Skip to content

Commit

Permalink
feat(cli): use ruleset-migrator#isBasicRuleset
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Oct 24, 2022
1 parent ab184f4 commit 748643e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 32 deletions.
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@stoplight/spectral-parsers": "^1.0.1",
"@stoplight/spectral-ref-resolver": "1.0.2",
"@stoplight/spectral-ruleset-bundler": "^1.0.0",
"@stoplight/spectral-ruleset-migrator": "^1.5.0",
"@stoplight/spectral-ruleset-migrator": "^1.9.0",
"@stoplight/spectral-rulesets": ">=1",
"@stoplight/spectral-runtime": "^1.1.0",
"@stoplight/types": "12.3.0",
Expand Down
30 changes: 1 addition & 29 deletions packages/cli/src/services/linter/utils/getRuleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as path from '@stoplight/path';
import * as process from 'process';
import { createRequire } from 'module';
import { fetch } from '@stoplight/spectral-runtime';
import { migrateRuleset } from '@stoplight/spectral-ruleset-migrator';
import { migrateRuleset, isBasicRuleset } from '@stoplight/spectral-ruleset-migrator';
import { bundleRuleset } from '@stoplight/spectral-ruleset-bundler';
import { node } from '@stoplight/spectral-ruleset-bundler/presets/node';
import { stdin } from '@stoplight/spectral-ruleset-bundler/plugins/stdin';
Expand Down Expand Up @@ -100,31 +100,3 @@ function load(source: string, uri: string): RulesetDefinition {

return m.exports;
}

function stripSearchFromUrl(url: string): string {
try {
const { href, search } = new URL(url);
return href.slice(0, href.length - search.length);
} catch {
return url;
}
}

async function isBasicRuleset(uri: string): Promise<boolean> {
if (path.isURL(uri)) {
uri = stripSearchFromUrl(uri);
}

if (/\.(json|ya?ml)$/.test(path.extname(uri))) {
return true;
}

try {
const contentType = (await fetch(uri)).headers.get('Content-Type');
return (
contentType !== null && ['application/yaml', 'text/yaml', 'application/json', 'text/json'].includes(contentType)
);
} catch {
return false;
}
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ __metadata:
"@stoplight/spectral-parsers": ^1.0.1
"@stoplight/spectral-ref-resolver": 1.0.2
"@stoplight/spectral-ruleset-bundler": ^1.0.0
"@stoplight/spectral-ruleset-migrator": ^1.5.0
"@stoplight/spectral-ruleset-migrator": ^1.9.0
"@stoplight/spectral-rulesets": ">=1"
"@stoplight/spectral-runtime": ^1.1.0
"@stoplight/types": 12.3.0
Expand Down Expand Up @@ -2660,7 +2660,7 @@ __metadata:
languageName: unknown
linkType: soft

"@stoplight/spectral-ruleset-migrator@^1.5.0, @stoplight/spectral-ruleset-migrator@^1.7.4, @stoplight/spectral-ruleset-migrator@workspace:packages/ruleset-migrator":
"@stoplight/spectral-ruleset-migrator@^1.7.4, @stoplight/spectral-ruleset-migrator@^1.9.0, @stoplight/spectral-ruleset-migrator@workspace:packages/ruleset-migrator":
version: 0.0.0-use.local
resolution: "@stoplight/spectral-ruleset-migrator@workspace:packages/ruleset-migrator"
dependencies:
Expand Down

0 comments on commit 748643e

Please sign in to comment.