Skip to content

Commit

Permalink
es6 import
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed Jul 24, 2024
1 parent c1cd04f commit fe101e6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/insomnia-inso/src/commands/lint-specification.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { RulesetDefinition, Spectral } from '@stoplight/spectral-core';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { bundleAndLoadRuleset } = require('@stoplight/spectral-ruleset-bundler/with-loader');
import { Spectral } from '@stoplight/spectral-core';
import { bundleAndLoadRuleset } from '@stoplight/spectral-ruleset-bundler/with-loader';
import { oas } from '@stoplight/spectral-rulesets';
import { DiagnosticSeverity } from '@stoplight/types';
import fs from 'fs';
Expand All @@ -24,17 +23,15 @@ export const getRuleSetFileFromFolderByFilename = async (filePath: string) => {
export async function lintSpecification({ specContent, rulesetFileName }: { specContent: string; rulesetFileName?: string },) {
const spectral = new Spectral();
// Use custom ruleset if present
let ruleset = oas;
try {
if (rulesetFileName) {
ruleset = await bundleAndLoadRuleset(rulesetFileName, { fs });
spectral.setRuleset(await bundleAndLoadRuleset(rulesetFileName, { fs, fetch }));
}
} catch (error) {
logger.fatal(error.message);
return { isValid: false };
}

spectral.setRuleset(ruleset as RulesetDefinition);
const results = await spectral.run(specContent);
if (!results.length) {
logger.log('No linting errors or warnings.');
Expand Down

0 comments on commit fe101e6

Please sign in to comment.