diff --git a/resources/.openapi-cli.exceptions.yaml b/resources/.openapi-cli.exceptions.yaml deleted file mode 100644 index d2a47f55..00000000 --- a/resources/.openapi-cli.exceptions.yaml +++ /dev/null @@ -1,3 +0,0 @@ -petstore-with-errors.yaml: - no-unused-components: - - '#/components/schemas/Some' diff --git a/resources/.redocly.lint-ignore.yaml b/resources/.redocly.lint-ignore.yaml new file mode 100644 index 00000000..6fbdfe95 --- /dev/null +++ b/resources/.redocly.lint-ignore.yaml @@ -0,0 +1,6 @@ +# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API. +# See https://redoc.ly/docs/cli/ for more information. +petstore-with-errors.yaml: + no-unused-components: + - '#/components/parameters/anotherParam' + - '#/components/schemas/Some' diff --git a/src/config/config.ts b/src/config/config.ts index 48725265..021969db 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -18,13 +18,16 @@ import { NodeType } from '../types'; import { dirname } from 'path'; const IGNORE_FILE = '.redocly.lint-ignore.yaml'; +const IGNORE_BANNER = + `# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` + + `# See https://redoc.ly/docs/cli/ for more information.\n`; export type RuleConfig = | MessageSeverity | 'off' - | { + | ({ severity?: MessageSeverity; - } & Record; + } & Record); export type TransformerConfig = | MessageSeverity @@ -126,12 +129,12 @@ export class LintConfig { const ignoreFile = path.join(dir, IGNORE_FILE); const mapped: Record = {}; for (const absFileName of Object.keys(this.ignore)) { - const ignoredRules = mapped[path.relative(dir, absFileName)] = this.ignore[absFileName]; + const ignoredRules = (mapped[path.relative(dir, absFileName)] = this.ignore[absFileName]); for (const ruleId of Object.keys(ignoredRules)) { ignoredRules[ruleId] = Array.from(ignoredRules[ruleId]) as any; } } - fs.writeFileSync(ignoreFile, yaml.safeDump(mapped)); + fs.writeFileSync(ignoreFile, IGNORE_BANNER + yaml.safeDump(mapped)); } addException(message: NormalizedReportMessage) { @@ -140,7 +143,7 @@ export class LintConfig { if (loc.pointer === undefined) return; const fileIgnore = (ignore[loc.source.absoluteRef] = ignore[loc.source.absoluteRef] || {}); - const ruleIgnore = fileIgnore[message.ruleId] = fileIgnore[message.ruleId] || new Set(); + const ruleIgnore = (fileIgnore[message.ruleId] = fileIgnore[message.ruleId] || new Set()); ruleIgnore.add(loc.pointer); } @@ -154,9 +157,9 @@ export class LintConfig { const ignored = ruleIgnore && ruleIgnore.has(loc.pointer); return ignored ? { - ...message, - ignored, - } + ...message, + ignored, + } : message; } @@ -205,9 +208,9 @@ export class LintConfig { getUnusedRules() { return { - rules: Object.keys(this.rules).filter(name => !this._usedRules.has(name)), - transformers: Object.keys(this.transformers).filter(name => !this._usedRules.has(name)), - } + rules: Object.keys(this.rules).filter((name) => !this._usedRules.has(name)), + transformers: Object.keys(this.transformers).filter((name) => !this._usedRules.has(name)), + }; } getRulesForOasVersion(version: OasVersion) { @@ -223,7 +226,7 @@ export class LintConfig { } skipRules(rules?: string[]) { - for (const ruleId of (rules || [])) { + for (const ruleId of rules || []) { if (this.rules[ruleId]) { this.rules[ruleId] = 'off'; } @@ -231,7 +234,7 @@ export class LintConfig { } skipTransformers(transformers?: string[]) { - for (const transformerId of (transformers || [])) { + for (const transformerId of transformers || []) { if (this.transformers[transformerId]) { this.transformers[transformerId] = 'off'; }