Appearance
Plugins and rule set
Decides which rules the run has, and the severity each one runs at. It works from the built-in plugins and the plugins the config lists, and it runs before any form is read.
A plugin is an object with a name, a version and its rules. It can also declare the runtime versions it checks against (compat), and a hostVariables hook that supplies names to Name analysis, such as the Smart Forms sourceQueries names. The name is the namespace of its rules' IDs: the smart-forms plugin's rule unsupported-query-embedding is smart-forms/unsupported-query-embedding. Core has two built-in plugins: sdc, with the core rules, and lint, which holds only lint/stale-suppression. Both names are reserved. Installing a plugin's package does not enable it; listing it in plugins in an .mjs config does.
resolveRuleSet builds the rule set in four steps:
- It checks each listed plugin against the plugin contract, and rejects a reserved namespace or one already registered. A rule's
docsUrlmust be an absolute URL; it is copied into each of the rule's findings. - It picks the runtime versions for each plugin that declares
compat: the newest verified ones by default (latest), or the exact verified versions the config names. - It gives each rule its setting: the one in the config's
rules, or else the rule's default severity.offkeeps the rule from running. - It checks every rule ID that
rulesandsuppressname, and suggests a similar ID when one is unknown.lint/stale-suppressioncan only bewarningoroff, andlint/findings cannot be suppressed.
A problem at any step stops the run with CONFIG_INVALID. lint and explain build the same rule set, so they fail the same way.
Plugins shows how to list one, Adding a rule how to write one, and What a plugin can import the API core gives plugins.
Schema
The RuleSet holds every rule sorted by ID, including those set to off, each with its setting and its compat versions. It also holds the plugin versions and the selected compat for the report, and the plugins' hostVariables hooks, in config order, for Name analysis.
Code
In packages/core/src/plugins/:
rule-set.ts:resolveRuleSetbuilds the rule set as above.unknownRuleHelpsuggests a similar rule ID, for the config and forexplain.contract.ts: the plugin contract, public API:LintPlugin,LintRule,RuleContext,RuleFinding,RuleDocs,PluginCompatandHostVariablesInput.builtin.ts: thesdcandlintplugins. It also says where each built-in rule completes its check, which Suppressions uses to find stale entries and the summary uses to count unchecked expressions.core-rule.ts:CoreRule, ansdcrule that also receives core's analysis of the form. Plugin rules get only the publicRuleContext.