Skip to content

Commit 30b8e1b

Browse files
kinlaneclaude
andcommitted
Level all rules to warn severity
Every rule now reports at a single severity — `warn`: - All inline rules in src/all-rules.json set to severity: warn (were info). - Active (recommended) built-in spectral:oas / spectral:asyncapi rules are re-leveled to warn in activeRulesetDef via the new builtinRecommendedByFormat export; dormant non-recommended built-ins stay off, oas2 stays off. User per-rule overrides still win (applied after). Verified: all emitted diagnostics across OpenAPI/AsyncAPI/Arazzo/JSON Schema are severity=warn. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e6491ce commit 30b8e1b

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/all-rules.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as monaco from 'monaco-editor';
22
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
33
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
44
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
5-
import { lint, builtinDescriptions, builtinRulesByFormat } from './spectral';
5+
import { lint, builtinDescriptions, builtinRulesByFormat, builtinRecommendedByFormat } from './spectral';
66
import { ARTIFACTS, SAMPLES, artifactById, type ArtifactType } from './artifacts';
77
import allRulesRaw from './all-rules.json';
88
import { searchSource, loadHit, enabledSources, type Hit, type SourceId, type Tokens } from './sources';
@@ -254,9 +254,14 @@ function activeRulesetDef(): any {
254254
if (t.includes('duplicate:true')) continue;
255255
rules[name] = engineRule(rule);
256256
}
257-
// we don't support Swagger / OpenAPI 2.0 — turn off any built-in oas2 rules
257+
// Built-in (extended) rules: we don't support Swagger / OpenAPI 2.0, so turn off
258+
// any oas2 rules; every other active (recommended) built-in is re-leveled to
259+
// `warn` so the whole ruleset reports at a single severity. Non-recommended
260+
// built-ins are left dormant (not enabled just to re-level them).
261+
const recommended = new Set(builtinRecommendedByFormat[current.format] ?? []);
258262
for (const name of builtinRulesByFormat[current.format] ?? []) {
259263
if (/^oas2[-_]/i.test(name)) rules[name] = 'off';
264+
else if (recommended.has(name)) rules[name] = 'warn';
260265
}
261266
// saved rule overrides for this format take priority over the originals
262267
const isInline = (name: string) => !!ALL_RULES[current.format]?.[name] && ALL_RULES[current.format][name].source !== 'builtin';

src/spectral.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ export const builtinRulesByFormat: Record<string, string[]> = {
3939
asyncapi: Object.keys((asyncapi as any)?.rules ?? {}),
4040
};
4141

42+
// The subset the engine actually runs when we extend the bare ruleset — Spectral
43+
// enables rules whose `recommended` is not false. These are the built-in rules we
44+
// re-level to `warn` (without enabling the dormant, non-recommended ones).
45+
const recommendedNames = (rs: any): string[] =>
46+
Object.entries<any>(rs?.rules ?? {}).filter(([, r]) => r?.recommended !== false).map(([n]) => n);
47+
export const builtinRecommendedByFormat: Record<string, string[]> = {
48+
openapi: recommendedNames(oas),
49+
asyncapi: recommendedNames(asyncapi),
50+
};
51+
4252
// Normalize ruleset format strings to the format-function export names.
4353
const FORMAT_ALIASES: Record<string, string> = {
4454
'oas3.0': 'oas3_0', 'oas3.1': 'oas3_1', oas31: 'oas3_1', oas30: 'oas3_0',

0 commit comments

Comments
 (0)