Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ deno_doc = { version = "=0.164.0", features = ["rust", "comrak"] }
deno_error.workspace = true
deno_graph = { version = "=0.87.0" }
deno_lib.workspace = true
deno_lint = { version = "=0.68.2" }
deno_lint = { version = "0.69.0" }
deno_lockfile.workspace = true
deno_media_type = { workspace = true, features = ["data_url", "decoding", "module_specifier"] }
deno_npm.workspace = true
Expand Down
17 changes: 16 additions & 1 deletion cli/schemas/lint-rules.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ban-untagged-ignore",
"ban-untagged-todo",
"ban-unused-ignore",
"button-has-type",
"camelcase",
"constructor-super",
"default-param-last",
Expand All @@ -19,6 +20,17 @@
"fresh-server-event-handlers",
"getter-return",
"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-async-promise-executor",
"no-await-in-loop",
Expand All @@ -32,6 +44,7 @@
"no-const-assign",
"no-constant-condition",
"no-control-regex",
"no-danger",
"no-debugger",
"no-delete-var",
"no-deprecated-deno-api",
Expand Down Expand Up @@ -70,7 +83,7 @@
"no-non-null-assertion",
"no-obj-calls",
"no-octal",
"no-process-globals",
"no-process-global",
"no-prototype-builtins",
"no-redeclare",
"no-regex-spaces",
Expand All @@ -92,6 +105,7 @@
"no-unsafe-negation",
"no-unused-labels",
"no-unused-vars",
"no-useless-rename",
"no-var",
"no-window",
"no-window-prefix",
Expand All @@ -103,6 +117,7 @@
"prefer-primordials",
"require-await",
"require-yield",
"rules-of-hooks",
"single-var-declarator",
"triple-slash-reference",
"use-isnan",
Expand Down
30 changes: 21 additions & 9 deletions cli/tools/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ fn collect_lint_files(
#[allow(clippy::print_stdout)]
pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
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(
LintRulesConfig {
tags: maybe_rules_tags.clone(),
Expand All @@ -467,6 +467,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
},
None,
);
all_rules.sort_by_cached_key(|rule| rule.code().to_string());

if json {
let json_output = serde_json::json!({
Expand All @@ -477,7 +478,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
// TODO(bartlomieju): print if rule enabled
serde_json::json!({
"code": rule.code(),
"tags": rule.tags(),
"tags": rule.tags().iter().map(|t| t.display()).collect::<Vec<_>>(),
"docs": rule.help_docs_url(),
})
})
Expand All @@ -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) {
"✓"
} else {
" "
""
};
println!("- {} {}", rule.code(), colors::green(enabled),);
println!(
Expand All @@ -505,7 +506,15 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
} else {
println!(
" {}",
colors::gray(format!("tags: {}", rule.tags().join(", ")))
colors::gray(format!(
"tags: {}",
rule
.tags()
.iter()
.map(|t| t.display())
.collect::<Vec<_>>()
.join(", ")
))
);
}
println!();
Expand Down Expand Up @@ -658,11 +667,14 @@ mod tests {

std::fs::write(
&rules_schema_path,
serde_json::to_string_pretty(&RulesSchema {
schema: schema.schema,
rules: all_rules,
})
.unwrap(),
format!(
"{}\n",
serde_json::to_string_pretty(&RulesSchema {
schema: schema.schema,
rules: all_rules,
})
.unwrap(),
),
)
.unwrap();
}
Expand Down
9 changes: 5 additions & 4 deletions cli/tools/lint/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use deno_core::error::AnyError;
use deno_graph::ModuleGraph;
use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::rules::LintRule;
use deno_lint::tags;

use crate::resolver::CliSloppyImportsResolver;

Expand All @@ -25,7 +26,7 @@ pub use no_slow_types::collect_no_slow_type_diagnostics;
pub trait PackageLintRule: std::fmt::Debug + Send + Sync {
fn code(&self) -> &'static str;

fn tags(&self) -> &'static [&'static str] {
fn tags(&self) -> tags::Tags {
&[]
}

Expand Down Expand Up @@ -78,7 +79,7 @@ impl CliLintRule {
}
}

pub fn tags(&self) -> &'static [&'static str] {
pub fn tags(&self) -> tags::Tags {
use CliLintRuleKind::*;
match &self.0 {
DenoLint(rule) => rule.tags(),
Expand All @@ -91,7 +92,7 @@ impl CliLintRule {
use CliLintRuleKind::*;
match &self.0 {
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(),
Package(rule) => rule.help_docs_url(),
Expand Down Expand Up @@ -284,7 +285,7 @@ mod test {
.resolve_lint_rules(Default::default(), None)
.rules
.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())
.filter(|n| n != "no-debugger")
.collect::<Vec<_>>();
Expand Down
5 changes: 3 additions & 2 deletions cli/tools/lint/rules/no_sloppy_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use deno_lint::diagnostic::LintDiagnosticRange;
use deno_lint::diagnostic::LintFix;
use deno_lint::diagnostic::LintFixChange;
use deno_lint::rules::LintRule;
use deno_lint::tags;
use deno_resolver::sloppy_imports::SloppyImportsResolution;
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
use text_lines::LineAndColumnIndex;
Expand Down Expand Up @@ -166,8 +167,8 @@ impl LintRule for NoSloppyImportsRule {
// include_str!("no_sloppy_imports.md")
// }

fn tags(&self) -> &'static [&'static str] {
&["recommended"]
fn tags(&self) -> tags::Tags {
&[tags::RECOMMENDED]
}
}

Expand Down
5 changes: 3 additions & 2 deletions cli/tools/lint/rules/no_slow_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use deno_graph::ModuleGraph;
use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::diagnostic::LintDiagnosticDetails;
use deno_lint::diagnostic::LintDiagnosticRange;
use deno_lint::tags;

use super::PackageLintRule;

Expand All @@ -22,8 +23,8 @@ impl PackageLintRule for NoSlowTypesRule {
CODE
}

fn tags(&self) -> &'static [&'static str] {
&["jsr"]
fn tags(&self) -> tags::Tags {
&[tags::JSR]
}

// TODO(bartlomieju): these docs need to be hosted somewhere.
Expand Down
Loading