0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-04 01:44:26 -05:00

feat(lint): add rules for react/preact (#27162)

This commit updated to deno_lint 0.69.0, which adds a bunch
or new lint rules dedicated for react/preact users.
This commit is contained in:
Bartek Iwańczuk 2025-01-24 13:08:36 +01:00 committed by GitHub
parent ad50c0df34
commit 0697578d3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 51 additions and 21 deletions

4
Cargo.lock generated
View file

@ -1937,9 +1937,9 @@ dependencies = [
[[package]] [[package]]
name = "deno_lint" name = "deno_lint"
version = "0.68.2" version = "0.69.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce713d564f76efd90535061113210bdc6b942ed6327b33eb1d5f76a5daf8e7a5" checksum = "802583d3ca6c7063e14cafa02ddc206fb34e804e095d52032baf375c56a99515"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"deno_ast", "deno_ast",

View file

@ -74,7 +74,7 @@ deno_doc = { version = "=0.164.0", features = ["rust", "comrak"] }
deno_error.workspace = true deno_error.workspace = true
deno_graph = { version = "=0.87.0" } deno_graph = { version = "=0.87.0" }
deno_lib.workspace = true deno_lib.workspace = true
deno_lint = { version = "=0.68.2" } deno_lint = { version = "0.69.0" }
deno_lockfile.workspace = true deno_lockfile.workspace = true
deno_media_type = { workspace = true, features = ["data_url", "decoding", "module_specifier"] } deno_media_type = { workspace = true, features = ["data_url", "decoding", "module_specifier"] }
deno_npm.workspace = true deno_npm.workspace = true

View file

@ -8,6 +8,7 @@
"ban-untagged-ignore", "ban-untagged-ignore",
"ban-untagged-todo", "ban-untagged-todo",
"ban-unused-ignore", "ban-unused-ignore",
"button-has-type",
"camelcase", "camelcase",
"constructor-super", "constructor-super",
"default-param-last", "default-param-last",
@ -19,6 +20,17 @@
"fresh-server-event-handlers", "fresh-server-event-handlers",
"getter-return", "getter-return",
"guard-for-in", "guard-for-in",
"jsx-boolean-value",
"jsx-curly-braces",
"jsx-key",
"jsx-no-children-prop",
"jsx-no-comment-text-nodes",
"jsx-no-danger-with-children",
"jsx-no-duplicate-props",
"jsx-no-unescaped-entities",
"jsx-no-useless-fragment",
"jsx-props-no-spread-multi",
"jsx-void-dom-elements-no-children",
"no-array-constructor", "no-array-constructor",
"no-async-promise-executor", "no-async-promise-executor",
"no-await-in-loop", "no-await-in-loop",
@ -32,6 +44,7 @@
"no-const-assign", "no-const-assign",
"no-constant-condition", "no-constant-condition",
"no-control-regex", "no-control-regex",
"no-danger",
"no-debugger", "no-debugger",
"no-delete-var", "no-delete-var",
"no-deprecated-deno-api", "no-deprecated-deno-api",
@ -70,7 +83,7 @@
"no-non-null-assertion", "no-non-null-assertion",
"no-obj-calls", "no-obj-calls",
"no-octal", "no-octal",
"no-process-globals", "no-process-global",
"no-prototype-builtins", "no-prototype-builtins",
"no-redeclare", "no-redeclare",
"no-regex-spaces", "no-regex-spaces",
@ -92,6 +105,7 @@
"no-unsafe-negation", "no-unsafe-negation",
"no-unused-labels", "no-unused-labels",
"no-unused-vars", "no-unused-vars",
"no-useless-rename",
"no-var", "no-var",
"no-window", "no-window",
"no-window-prefix", "no-window-prefix",
@ -103,6 +117,7 @@
"prefer-primordials", "prefer-primordials",
"require-await", "require-await",
"require-yield", "require-yield",
"rules-of-hooks",
"single-var-declarator", "single-var-declarator",
"triple-slash-reference", "triple-slash-reference",
"use-isnan", "use-isnan",

View file

@ -458,7 +458,7 @@ fn collect_lint_files(
#[allow(clippy::print_stdout)] #[allow(clippy::print_stdout)]
pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) { pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
let rule_provider = LintRuleProvider::new(None, None); let rule_provider = LintRuleProvider::new(None, None);
let all_rules = rule_provider.all_rules(); let mut all_rules = rule_provider.all_rules();
let configured_rules = rule_provider.resolve_lint_rules( let configured_rules = rule_provider.resolve_lint_rules(
LintRulesConfig { LintRulesConfig {
tags: maybe_rules_tags.clone(), tags: maybe_rules_tags.clone(),
@ -467,6 +467,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
}, },
None, None,
); );
all_rules.sort_by_cached_key(|rule| rule.code().to_string());
if json { if json {
let json_output = serde_json::json!({ let json_output = serde_json::json!({
@ -477,7 +478,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
// TODO(bartlomieju): print if rule enabled // TODO(bartlomieju): print if rule enabled
serde_json::json!({ serde_json::json!({
"code": rule.code(), "code": rule.code(),
"tags": rule.tags(), "tags": rule.tags().iter().map(|t| t.display()).collect::<Vec<_>>(),
"docs": rule.help_docs_url(), "docs": rule.help_docs_url(),
}) })
}) })
@ -493,7 +494,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
let enabled = if configured_rules.rules.contains(rule) { let enabled = if configured_rules.rules.contains(rule) {
"" ""
} else { } else {
" " ""
}; };
println!("- {} {}", rule.code(), colors::green(enabled),); println!("- {} {}", rule.code(), colors::green(enabled),);
println!( println!(
@ -505,7 +506,15 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
} else { } else {
println!( println!(
" {}", " {}",
colors::gray(format!("tags: {}", rule.tags().join(", "))) colors::gray(format!(
"tags: {}",
rule
.tags()
.iter()
.map(|t| t.display())
.collect::<Vec<_>>()
.join(", ")
))
); );
} }
println!(); println!();
@ -658,11 +667,14 @@ mod tests {
std::fs::write( std::fs::write(
&rules_schema_path, &rules_schema_path,
serde_json::to_string_pretty(&RulesSchema { format!(
schema: schema.schema, "{}\n",
rules: all_rules, serde_json::to_string_pretty(&RulesSchema {
}) schema: schema.schema,
.unwrap(), rules: all_rules,
})
.unwrap(),
),
) )
.unwrap(); .unwrap();
} }

View file

@ -13,6 +13,7 @@ use deno_core::error::AnyError;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_lint::diagnostic::LintDiagnostic; use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::rules::LintRule; use deno_lint::rules::LintRule;
use deno_lint::tags;
use crate::resolver::CliSloppyImportsResolver; use crate::resolver::CliSloppyImportsResolver;
@ -25,7 +26,7 @@ pub use no_slow_types::collect_no_slow_type_diagnostics;
pub trait PackageLintRule: std::fmt::Debug + Send + Sync { pub trait PackageLintRule: std::fmt::Debug + Send + Sync {
fn code(&self) -> &'static str; fn code(&self) -> &'static str;
fn tags(&self) -> &'static [&'static str] { fn tags(&self) -> tags::Tags {
&[] &[]
} }
@ -78,7 +79,7 @@ impl CliLintRule {
} }
} }
pub fn tags(&self) -> &'static [&'static str] { pub fn tags(&self) -> tags::Tags {
use CliLintRuleKind::*; use CliLintRuleKind::*;
match &self.0 { match &self.0 {
DenoLint(rule) => rule.tags(), DenoLint(rule) => rule.tags(),
@ -91,7 +92,7 @@ impl CliLintRule {
use CliLintRuleKind::*; use CliLintRuleKind::*;
match &self.0 { match &self.0 {
DenoLint(rule) => { DenoLint(rule) => {
Cow::Owned(format!("https://lint.deno.land/rules/{}", rule.code())) Cow::Owned(format!("https://docs.deno.com/lint/rules/{}", rule.code()))
} }
Extended(rule) => rule.help_docs_url(), Extended(rule) => rule.help_docs_url(),
Package(rule) => rule.help_docs_url(), Package(rule) => rule.help_docs_url(),
@ -284,7 +285,7 @@ mod test {
.resolve_lint_rules(Default::default(), None) .resolve_lint_rules(Default::default(), None)
.rules .rules
.into_iter() .into_iter()
.filter(|r| r.tags().iter().any(|t| *t == "recommended")) .filter(|r| r.tags().iter().any(|t| *t == tags::RECOMMENDED))
.map(|r| r.code().to_string()) .map(|r| r.code().to_string())
.filter(|n| n != "no-debugger") .filter(|n| n != "no-debugger")
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View file

@ -16,6 +16,7 @@ use deno_lint::diagnostic::LintDiagnosticRange;
use deno_lint::diagnostic::LintFix; use deno_lint::diagnostic::LintFix;
use deno_lint::diagnostic::LintFixChange; use deno_lint::diagnostic::LintFixChange;
use deno_lint::rules::LintRule; use deno_lint::rules::LintRule;
use deno_lint::tags;
use deno_resolver::sloppy_imports::SloppyImportsResolution; use deno_resolver::sloppy_imports::SloppyImportsResolution;
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind; use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
use text_lines::LineAndColumnIndex; use text_lines::LineAndColumnIndex;
@ -166,8 +167,8 @@ impl LintRule for NoSloppyImportsRule {
// include_str!("no_sloppy_imports.md") // include_str!("no_sloppy_imports.md")
// } // }
fn tags(&self) -> &'static [&'static str] { fn tags(&self) -> tags::Tags {
&["recommended"] &[tags::RECOMMENDED]
} }
} }

View file

@ -9,6 +9,7 @@ use deno_graph::ModuleGraph;
use deno_lint::diagnostic::LintDiagnostic; use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::diagnostic::LintDiagnosticDetails; use deno_lint::diagnostic::LintDiagnosticDetails;
use deno_lint::diagnostic::LintDiagnosticRange; use deno_lint::diagnostic::LintDiagnosticRange;
use deno_lint::tags;
use super::PackageLintRule; use super::PackageLintRule;
@ -22,8 +23,8 @@ impl PackageLintRule for NoSlowTypesRule {
CODE CODE
} }
fn tags(&self) -> &'static [&'static str] { fn tags(&self) -> tags::Tags {
&["jsr"] &[tags::JSR]
} }
// TODO(bartlomieju): these docs need to be hosted somewhere. // TODO(bartlomieju): these docs need to be hosted somewhere.