Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a42aa8

Browse files
committed
chore: add ignore file banner
1 parent c0c5d34 commit 1a42aa8

3 files changed

Lines changed: 22 additions & 16 deletions

File tree

resources/.openapi-cli.exceptions.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.
2+
# See https://redoc.ly/docs/cli/ for more information.
3+
petstore-with-errors.yaml:
4+
no-unused-components:
5+
- '#/components/parameters/anotherParam'
6+
- '#/components/schemas/Some'

src/config/config.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ import { NodeType } from '../types';
1818
import { dirname } from 'path';
1919

2020
const IGNORE_FILE = '.redocly.lint-ignore.yaml';
21+
const IGNORE_BANNER =
22+
`# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.\n` +
23+
`# See https://redoc.ly/docs/cli/ for more information.\n`;
2124

2225
export type RuleConfig =
2326
| MessageSeverity
2427
| 'off'
25-
| {
28+
| ({
2629
severity?: MessageSeverity;
27-
} & Record<string, any>;
30+
} & Record<string, any>);
2831

2932
export type TransformerConfig =
3033
| MessageSeverity
@@ -126,12 +129,12 @@ export class LintConfig {
126129
const ignoreFile = path.join(dir, IGNORE_FILE);
127130
const mapped: Record<string, any> = {};
128131
for (const absFileName of Object.keys(this.ignore)) {
129-
const ignoredRules = mapped[path.relative(dir, absFileName)] = this.ignore[absFileName];
132+
const ignoredRules = (mapped[path.relative(dir, absFileName)] = this.ignore[absFileName]);
130133
for (const ruleId of Object.keys(ignoredRules)) {
131134
ignoredRules[ruleId] = Array.from(ignoredRules[ruleId]) as any;
132135
}
133136
}
134-
fs.writeFileSync(ignoreFile, yaml.safeDump(mapped));
137+
fs.writeFileSync(ignoreFile, IGNORE_BANNER + yaml.safeDump(mapped));
135138
}
136139

137140
addException(message: NormalizedReportMessage) {
@@ -140,7 +143,7 @@ export class LintConfig {
140143
if (loc.pointer === undefined) return;
141144

142145
const fileIgnore = (ignore[loc.source.absoluteRef] = ignore[loc.source.absoluteRef] || {});
143-
const ruleIgnore = fileIgnore[message.ruleId] = fileIgnore[message.ruleId] || new Set();
146+
const ruleIgnore = (fileIgnore[message.ruleId] = fileIgnore[message.ruleId] || new Set());
144147

145148
ruleIgnore.add(loc.pointer);
146149
}
@@ -154,9 +157,9 @@ export class LintConfig {
154157
const ignored = ruleIgnore && ruleIgnore.has(loc.pointer);
155158
return ignored
156159
? {
157-
...message,
158-
ignored,
159-
}
160+
...message,
161+
ignored,
162+
}
160163
: message;
161164
}
162165

@@ -205,9 +208,9 @@ export class LintConfig {
205208

206209
getUnusedRules() {
207210
return {
208-
rules: Object.keys(this.rules).filter(name => !this._usedRules.has(name)),
209-
transformers: Object.keys(this.transformers).filter(name => !this._usedRules.has(name)),
210-
}
211+
rules: Object.keys(this.rules).filter((name) => !this._usedRules.has(name)),
212+
transformers: Object.keys(this.transformers).filter((name) => !this._usedRules.has(name)),
213+
};
211214
}
212215

213216
getRulesForOasVersion(version: OasVersion) {
@@ -223,15 +226,15 @@ export class LintConfig {
223226
}
224227

225228
skipRules(rules?: string[]) {
226-
for (const ruleId of (rules || [])) {
229+
for (const ruleId of rules || []) {
227230
if (this.rules[ruleId]) {
228231
this.rules[ruleId] = 'off';
229232
}
230233
}
231234
}
232235

233236
skipTransformers(transformers?: string[]) {
234-
for (const transformerId of (transformers || [])) {
237+
for (const transformerId of transformers || []) {
235238
if (this.transformers[transformerId]) {
236239
this.transformers[transformerId] = 'off';
237240
}

0 commit comments

Comments
 (0)