diff --git a/cli/schemas/config-file.v1.json b/cli/schemas/config-file.v1.json index a64cb2ff655d42..1e3abb2c0d00ad 100644 --- a/cli/schemas/config-file.v1.json +++ b/cli/schemas/config-file.v1.json @@ -291,7 +291,7 @@ "type": "array", "description": "List of tag names that will be run. Empty list disables all tags and will only use rules from `include`.", "items": { - "$ref": "https://raw.githubusercontent.com/denoland/deno_lint/main/schemas/tags.v1.json" + "$ref": "lint-tags.v1.json" }, "minItems": 0, "uniqueItems": true @@ -300,7 +300,7 @@ "type": "array", "description": "List of rule names that will be excluded from configured tag sets. If the same rule is in `include` it will be run.", "items": { - "$ref": "https://raw.githubusercontent.com/denoland/deno_lint/main/schemas/rules.v1.json" + "$ref": "lint-rules.v1.json" }, "minItems": 0, "uniqueItems": true @@ -309,7 +309,7 @@ "type": "array", "description": "List of rule names that will be run. Even if the same rule is in `exclude` it will be run.", "items": { - "$ref": "https://raw.githubusercontent.com/denoland/deno_lint/main/schemas/rules.v1.json" + "$ref": "lint-rules.v1.json" }, "minItems": 0, "uniqueItems": true diff --git a/cli/schemas/lint-rules.v1.json b/cli/schemas/lint-rules.v1.json new file mode 100644 index 00000000000000..71d17849588c8e --- /dev/null +++ b/cli/schemas/lint-rules.v1.json @@ -0,0 +1,112 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "enum": [ + "adjacent-overload-signatures", + "ban-ts-comment", + "ban-types", + "ban-unknown-rule-code", + "ban-untagged-ignore", + "ban-untagged-todo", + "ban-unused-ignore", + "camelcase", + "constructor-super", + "default-param-last", + "eqeqeq", + "explicit-function-return-type", + "explicit-module-boundary-types", + "for-direction", + "fresh-handler-export", + "fresh-server-event-handlers", + "getter-return", + "guard-for-in", + "no-array-constructor", + "no-async-promise-executor", + "no-await-in-loop", + "no-await-in-sync-fn", + "no-boolean-literal-for-arguments", + "no-case-declarations", + "no-class-assign", + "no-compare-neg-zero", + "no-cond-assign", + "no-console", + "no-const-assign", + "no-constant-condition", + "no-control-regex", + "no-debugger", + "no-delete-var", + "no-deprecated-deno-api", + "no-dupe-args", + "no-dupe-class-members", + "no-dupe-else-if", + "no-dupe-keys", + "no-duplicate-case", + "no-empty", + "no-empty-character-class", + "no-empty-enum", + "no-empty-interface", + "no-empty-pattern", + "no-eval", + "no-ex-assign", + "no-explicit-any", + "no-external-import", + "no-extra-boolean-cast", + "no-extra-non-null-assertion", + "no-fallthrough", + "no-func-assign", + "no-global-assign", + "no-implicit-declare-namespace-export", + "no-import-assertions", + "no-import-assign", + "no-inferrable-types", + "no-inner-declarations", + "no-invalid-regexp", + "no-invalid-triple-slash-reference", + "no-irregular-whitespace", + "no-misused-new", + "no-namespace", + "no-new-symbol", + "no-node-globals", + "no-non-null-asserted-optional-chain", + "no-non-null-assertion", + "no-obj-calls", + "no-octal", + "no-process-globals", + "no-prototype-builtins", + "no-redeclare", + "no-regex-spaces", + "no-self-assign", + "no-self-compare", + "no-setter-return", + "no-shadow-restricted-names", + "no-sloppy-imports", + "no-slow-types", + "no-sparse-arrays", + "no-sync-fn-in-async-fn", + "no-this-alias", + "no-this-before-super", + "no-throw-literal", + "no-top-level-await", + "no-undef", + "no-unreachable", + "no-unsafe-finally", + "no-unsafe-negation", + "no-unused-labels", + "no-unused-vars", + "no-var", + "no-window", + "no-window-prefix", + "no-with", + "prefer-as-const", + "prefer-ascii", + "prefer-const", + "prefer-namespace-keyword", + "prefer-primordials", + "require-await", + "require-yield", + "single-var-declarator", + "triple-slash-reference", + "use-isnan", + "valid-typeof", + "verbatim-module-syntax" + ] +} diff --git a/cli/schemas/lint-tags.v1.json b/cli/schemas/lint-tags.v1.json new file mode 100644 index 00000000000000..4b4f0e48db400a --- /dev/null +++ b/cli/schemas/lint-tags.v1.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "enum": ["fresh", "jsr", "jsx", "react", "recommended"] +} diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index fcefb458746f03..596359bdc0b469 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -556,3 +556,68 @@ struct LintError { file_path: String, message: String, } + +#[cfg(test)] +mod tests { + use super::*; + use pretty_assertions::assert_eq; + use serde::Deserialize; + use test_util as util; + + #[derive(Serialize, Deserialize)] + struct RulesSchema { + #[serde(rename = "$schema")] + schema: String, + + #[serde(rename = "enum")] + rules: Vec, + } + + fn get_all_rules() -> Vec { + let rule_provider = LintRuleProvider::new(None, None); + let configured_rules = + rule_provider.resolve_lint_rules(Default::default(), None); + let mut all_rules = configured_rules + .all_rule_codes + .into_iter() + .map(|s| s.to_string()) + .collect::>(); + all_rules.sort(); + + all_rules + } + + // TODO(bartlomieju): do the same for tags, once https://github.com/denoland/deno/pull/27162 lands + #[test] + fn all_lint_rules_are_listed_in_schema_file() { + let all_rules = get_all_rules(); + + let rules_schema_path = + util::root_path().join("cli/schemas/lint-rules.v1.json"); + let rules_schema_file = + std::fs::read_to_string(&rules_schema_path).unwrap(); + + let schema: RulesSchema = serde_json::from_str(&rules_schema_file).unwrap(); + + const UPDATE_ENV_VAR_NAME: &str = "UPDATE_EXPECTED"; + + if std::env::var(UPDATE_ENV_VAR_NAME).ok().is_none() { + assert_eq!( + schema.rules, all_rules, + "Lint rules schema file not up to date. Run again with {}=1 to update the expected output", + UPDATE_ENV_VAR_NAME + ); + return; + } + + std::fs::write( + &rules_schema_path, + serde_json::to_string_pretty(&RulesSchema { + schema: schema.schema, + rules: all_rules, + }) + .unwrap(), + ) + .unwrap(); + } +}