mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-09 20:57:44 +00:00
chore: rename exceptions file
This commit is contained in:
10
README.md
10
README.md
@@ -204,10 +204,12 @@ Possible values are:
|
||||
* warning
|
||||
* error
|
||||
|
||||
#### Exceptions file
|
||||
#### Ignore file
|
||||
|
||||
You can exclude some known errors to not show up/break you validation using exceptions file.
|
||||
Exceptions file should be named `.openapi-cli.exceptions.yaml` and should be placed next to `.redocly.yaml`.
|
||||
This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.
|
||||
|
||||
You can exclude some known errors to not show up/break you validation using ignore file.
|
||||
Ignore file should be named `.redocly.lint-ignore.yaml` and should be placed next to `.redocly.yaml`.
|
||||
|
||||
```yaml
|
||||
"filename.yaml":
|
||||
@@ -219,7 +221,7 @@ Exceptions file should be named `.openapi-cli.exceptions.yaml` and should be pla
|
||||
- "#/excluded/json/pointer"
|
||||
```
|
||||
|
||||
Exceptions file can be autogenerated to add all messages as exceptions by running `openapi lint --generate-exceptions`
|
||||
Ignore file can be autogenerated to add all messages to it by running `openapi lint --generate-ignore-file`
|
||||
|
||||
#### Built-in Rules
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ export async function bundleDocument(opts: {
|
||||
|
||||
return {
|
||||
bundle: document.parsed,
|
||||
messages: ctx.messages.map((message) => config.addMessageToExceptions(message)),
|
||||
messages: ctx.messages.map((message) => config.addMessageToIgnore(message)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
28
src/cli.ts
28
src/cli.ts
@@ -39,8 +39,8 @@ yargs // eslint-disable-line
|
||||
type: 'number',
|
||||
default: 100,
|
||||
})
|
||||
.option('generate-exceptions', {
|
||||
description: 'Generate exceptions file',
|
||||
.option('generate-ignore-file', {
|
||||
description: 'Generate ignore file',
|
||||
type: 'boolean',
|
||||
})
|
||||
.option('skip-rule', {
|
||||
@@ -65,12 +65,12 @@ yargs // eslint-disable-line
|
||||
|
||||
const entrypoints = getFallbackEntryPointsOrExit(argv.entrypoints, config);
|
||||
|
||||
if (argv['generate-exceptions']) {
|
||||
config.lint.exceptions = {}; // clear ignore
|
||||
if (argv['generate-ignore-file']) {
|
||||
config.lint.ignore = {}; // clear ignore
|
||||
}
|
||||
|
||||
const totals: Totals = { errors: 0, warnings: 0, ignored: 0 };
|
||||
let totalExceptions = 0;
|
||||
let totalIgnored = 0;
|
||||
|
||||
// TODO: use shared externalRef resolver, blocked by transformers now as they mutate documents
|
||||
for (const entryPoint of entrypoints) {
|
||||
@@ -86,10 +86,10 @@ yargs // eslint-disable-line
|
||||
totals.warnings += fileTotals.warnings;
|
||||
totals.ignored += fileTotals.ignored;
|
||||
|
||||
if (argv['generate-exceptions']) {
|
||||
if (argv['generate-ignore-file']) {
|
||||
for (let m of results) {
|
||||
config.lint.addException(m);
|
||||
totalExceptions++;
|
||||
totalIgnored++;
|
||||
}
|
||||
} else {
|
||||
formatMessages(results, {
|
||||
@@ -108,20 +108,20 @@ yargs // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
if (argv['generate-exceptions']) {
|
||||
config.lint.saveExceptions();
|
||||
if (argv['generate-ignore-file']) {
|
||||
config.lint.saveIgnore();
|
||||
process.stderr.write(
|
||||
`Added ${totalExceptions} ${pluralize(
|
||||
`Added ${totalIgnored} ${pluralize(
|
||||
'message',
|
||||
totalExceptions,
|
||||
)} to exceptions file\n\n`,
|
||||
totalIgnored,
|
||||
)} to ignore file\n\n`,
|
||||
);
|
||||
} else {
|
||||
printLintTotals(totals, entrypoints.length);
|
||||
}
|
||||
|
||||
printUnusedWarnings(config.lint);
|
||||
process.exit(totals.errors === 0 || argv['generate-exceptions'] ? 0 : 1);
|
||||
process.exit(totals.errors === 0 || argv['generate-ignore-file'] ? 0 : 1);
|
||||
},
|
||||
)
|
||||
.command(
|
||||
@@ -326,7 +326,7 @@ function printLintTotals(totals: Totals, definitionsCount: number) {
|
||||
|
||||
if (totals.errors > 0) {
|
||||
process.stderr.write(
|
||||
gray(`\nrun with \`--generate-exceptions\` to add all messages to exceptions file\n`),
|
||||
gray(`\nrun with \`--generate-ignore-file\` to add all messages to ignore file\n`),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import { red, blue } from 'colorette';
|
||||
import { NodeType } from '../types';
|
||||
import { dirname } from 'path';
|
||||
|
||||
const EXCEPTIONS_FILE = '.openapi-cli.exceptions.yaml';
|
||||
const IGNORE_FILE = '.redocly.lint-ignore.yaml';
|
||||
|
||||
export type RuleConfig =
|
||||
| MessageSeverity
|
||||
@@ -75,7 +75,7 @@ export class LintConfig {
|
||||
plugins: Plugin[];
|
||||
rules: Record<string, RuleConfig>;
|
||||
transformers: Record<string, TransformerConfig>;
|
||||
exceptions: Record<string, Record<string, Set<string>>> = {};
|
||||
ignore: Record<string, Record<string, Set<string>>> = {};
|
||||
|
||||
private _usedRules: Set<string> = new Set();
|
||||
|
||||
@@ -105,37 +105,37 @@ export class LintConfig {
|
||||
this.transformers = merged.transformers;
|
||||
|
||||
const dir = this.configFile ? path.dirname(this.configFile) : process.cwd();
|
||||
const exceptionsFile = path.join(dir, EXCEPTIONS_FILE);
|
||||
const ignoreFile = path.join(dir, IGNORE_FILE);
|
||||
|
||||
if (fs.existsSync(exceptionsFile)) {
|
||||
this.exceptions = yaml.safeLoad(fs.readFileSync(exceptionsFile, 'utf-8')); // TODO: parse errors
|
||||
if (fs.existsSync(ignoreFile)) {
|
||||
this.ignore = yaml.safeLoad(fs.readFileSync(ignoreFile, 'utf-8')); // TODO: parse errors
|
||||
|
||||
// resolve ignore paths
|
||||
for (const fileName of Object.keys(this.exceptions)) {
|
||||
this.exceptions[path.resolve(dirname(exceptionsFile), fileName)] = this.exceptions[fileName];
|
||||
for (const ruleId of Object.keys(this.exceptions[fileName])) {
|
||||
this.exceptions[fileName][ruleId] = new Set(this.exceptions[fileName][ruleId]);
|
||||
for (const fileName of Object.keys(this.ignore)) {
|
||||
this.ignore[path.resolve(dirname(ignoreFile), fileName)] = this.ignore[fileName];
|
||||
for (const ruleId of Object.keys(this.ignore[fileName])) {
|
||||
this.ignore[fileName][ruleId] = new Set(this.ignore[fileName][ruleId]);
|
||||
}
|
||||
delete this.exceptions[fileName];
|
||||
delete this.ignore[fileName];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveExceptions() {
|
||||
saveIgnore() {
|
||||
const dir = this.configFile ? path.dirname(this.configFile) : process.cwd();
|
||||
const ignoreFile = path.join(dir, EXCEPTIONS_FILE);
|
||||
const ignoreFile = path.join(dir, IGNORE_FILE);
|
||||
const mapped: Record<string, any> = {};
|
||||
for (const absFileName of Object.keys(this.exceptions)) {
|
||||
const ruleExceptions = mapped[path.relative(dir, absFileName)] = this.exceptions[absFileName];
|
||||
for (const ruleId of Object.keys(ruleExceptions)) {
|
||||
ruleExceptions[ruleId] = Array.from(ruleExceptions[ruleId]) as any;
|
||||
for (const absFileName of Object.keys(this.ignore)) {
|
||||
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));
|
||||
}
|
||||
|
||||
addException(message: NormalizedReportMessage) {
|
||||
const ignore = this.exceptions;
|
||||
const ignore = this.ignore;
|
||||
const loc = message.location[0];
|
||||
if (loc.pointer === undefined) return;
|
||||
|
||||
@@ -145,11 +145,11 @@ export class LintConfig {
|
||||
ruleIgnore.add(loc.pointer);
|
||||
}
|
||||
|
||||
addMessageToExceptions(message: NormalizedReportMessage) {
|
||||
addMessageToIgnore(message: NormalizedReportMessage) {
|
||||
const loc = message.location[0];
|
||||
if (loc.pointer === undefined) return message;
|
||||
|
||||
const fileIgnore = this.exceptions[loc.source.absoluteRef] || {};
|
||||
const fileIgnore = this.ignore[loc.source.absoluteRef] || {};
|
||||
const ruleIgnore = fileIgnore[message.ruleId];
|
||||
const ignored = ruleIgnore && ruleIgnore.has(loc.pointer);
|
||||
return ignored
|
||||
|
||||
@@ -76,7 +76,7 @@ export async function validateDocument(opts: {
|
||||
ctx,
|
||||
});
|
||||
|
||||
return ctx.messages.map((message) => config.addMessageToExceptions(message));
|
||||
return ctx.messages.map((message) => config.addMessageToIgnore(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user