Skip to content

Commit

Permalink
fix: do not try to resolve valid uris
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Jun 4, 2019
1 parent e019e8f commit 2ae8d62
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/cli/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getLocationForJsonPath } from '@stoplight/yaml';
import { writeFile } from 'fs';
import { isNil, omitBy } from 'lodash';
import { resolve } from 'path';
import * as URI from 'urijs';
import { promisify } from 'util';

import { IRuleResult } from '../..';
Expand Down Expand Up @@ -127,7 +128,7 @@ async function lint(name: string, flags: any, command: Lint, rules?: RuleCollect
command.log(`Linting ${name}`);
}

const targetUri = resolve(name);
const targetUri = isValidURI(name) ? name : resolve(name);

const spec: IParserResult = await readParsable(targetUri, flags.encoding);
const spectral = new Spectral({ resolver: httpAndFileResolver });
Expand Down Expand Up @@ -167,6 +168,7 @@ async function lint(name: string, flags: any, command: Lint, rules?: RuleCollect

let results = [];
try {
console.log(targetUri);
const parsedResult: IParsedResult = {
source: targetUri,
parsed: spec,
Expand Down Expand Up @@ -254,3 +256,13 @@ function mergeConfig(config: IConfig, flags: any): ILintConfig {
),
};
}

const isValidURI = (maybeUri: string) => {
try {
// tslint:disable-next-line:no-unused-expression
new URI(maybeUri);
return true;
} catch {
return false;
}
};

0 comments on commit 2ae8d62

Please sign in to comment.