Skip to content

Commit 0697578

Browse files
authored
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.
1 parent ad50c0d commit 0697578

File tree

7 files changed

+51
-21
lines changed

7 files changed

+51
-21
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ deno_doc = { version = "=0.164.0", features = ["rust", "comrak"] }
7474
deno_error.workspace = true
7575
deno_graph = { version = "=0.87.0" }
7676
deno_lib.workspace = true
77-
deno_lint = { version = "=0.68.2" }
77+
deno_lint = { version = "0.69.0" }
7878
deno_lockfile.workspace = true
7979
deno_media_type = { workspace = true, features = ["data_url", "decoding", "module_specifier"] }
8080
deno_npm.workspace = true

cli/schemas/lint-rules.v1.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ban-untagged-ignore",
99
"ban-untagged-todo",
1010
"ban-unused-ignore",
11+
"button-has-type",
1112
"camelcase",
1213
"constructor-super",
1314
"default-param-last",
@@ -19,6 +20,17 @@
1920
"fresh-server-event-handlers",
2021
"getter-return",
2122
"guard-for-in",
23+
"jsx-boolean-value",
24+
"jsx-curly-braces",
25+
"jsx-key",
26+
"jsx-no-children-prop",
27+
"jsx-no-comment-text-nodes",
28+
"jsx-no-danger-with-children",
29+
"jsx-no-duplicate-props",
30+
"jsx-no-unescaped-entities",
31+
"jsx-no-useless-fragment",
32+
"jsx-props-no-spread-multi",
33+
"jsx-void-dom-elements-no-children",
2234
"no-array-constructor",
2335
"no-async-promise-executor",
2436
"no-await-in-loop",
@@ -32,6 +44,7 @@
3244
"no-const-assign",
3345
"no-constant-condition",
3446
"no-control-regex",
47+
"no-danger",
3548
"no-debugger",
3649
"no-delete-var",
3750
"no-deprecated-deno-api",
@@ -70,7 +83,7 @@
7083
"no-non-null-assertion",
7184
"no-obj-calls",
7285
"no-octal",
73-
"no-process-globals",
86+
"no-process-global",
7487
"no-prototype-builtins",
7588
"no-redeclare",
7689
"no-regex-spaces",
@@ -92,6 +105,7 @@
92105
"no-unsafe-negation",
93106
"no-unused-labels",
94107
"no-unused-vars",
108+
"no-useless-rename",
95109
"no-var",
96110
"no-window",
97111
"no-window-prefix",
@@ -103,6 +117,7 @@
103117
"prefer-primordials",
104118
"require-await",
105119
"require-yield",
120+
"rules-of-hooks",
106121
"single-var-declarator",
107122
"triple-slash-reference",
108123
"use-isnan",

cli/tools/lint/mod.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ fn collect_lint_files(
458458
#[allow(clippy::print_stdout)]
459459
pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
460460
let rule_provider = LintRuleProvider::new(None, None);
461-
let all_rules = rule_provider.all_rules();
461+
let mut all_rules = rule_provider.all_rules();
462462
let configured_rules = rule_provider.resolve_lint_rules(
463463
LintRulesConfig {
464464
tags: maybe_rules_tags.clone(),
@@ -467,6 +467,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
467467
},
468468
None,
469469
);
470+
all_rules.sort_by_cached_key(|rule| rule.code().to_string());
470471

471472
if json {
472473
let json_output = serde_json::json!({
@@ -477,7 +478,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
477478
// TODO(bartlomieju): print if rule enabled
478479
serde_json::json!({
479480
"code": rule.code(),
480-
"tags": rule.tags(),
481+
"tags": rule.tags().iter().map(|t| t.display()).collect::<Vec<_>>(),
481482
"docs": rule.help_docs_url(),
482483
})
483484
})
@@ -493,7 +494,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
493494
let enabled = if configured_rules.rules.contains(rule) {
494495
"✓"
495496
} else {
496-
" "
497+
""
497498
};
498499
println!("- {} {}", rule.code(), colors::green(enabled),);
499500
println!(
@@ -505,7 +506,15 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
505506
} else {
506507
println!(
507508
" {}",
508-
colors::gray(format!("tags: {}", rule.tags().join(", ")))
509+
colors::gray(format!(
510+
"tags: {}",
511+
rule
512+
.tags()
513+
.iter()
514+
.map(|t| t.display())
515+
.collect::<Vec<_>>()
516+
.join(", ")
517+
))
509518
);
510519
}
511520
println!();
@@ -658,11 +667,14 @@ mod tests {
658667

659668
std::fs::write(
660669
&rules_schema_path,
661-
serde_json::to_string_pretty(&RulesSchema {
662-
schema: schema.schema,
663-
rules: all_rules,
664-
})
665-
.unwrap(),
670+
format!(
671+
"{}\n",
672+
serde_json::to_string_pretty(&RulesSchema {
673+
schema: schema.schema,
674+
rules: all_rules,
675+
})
676+
.unwrap(),
677+
),
666678
)
667679
.unwrap();
668680
}

cli/tools/lint/rules/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use deno_core::error::AnyError;
1313
use deno_graph::ModuleGraph;
1414
use deno_lint::diagnostic::LintDiagnostic;
1515
use deno_lint::rules::LintRule;
16+
use deno_lint::tags;
1617

1718
use crate::resolver::CliSloppyImportsResolver;
1819

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

28-
fn tags(&self) -> &'static [&'static str] {
29+
fn tags(&self) -> tags::Tags {
2930
&[]
3031
}
3132

@@ -78,7 +79,7 @@ impl CliLintRule {
7879
}
7980
}
8081

81-
pub fn tags(&self) -> &'static [&'static str] {
82+
pub fn tags(&self) -> tags::Tags {
8283
use CliLintRuleKind::*;
8384
match &self.0 {
8485
DenoLint(rule) => rule.tags(),
@@ -91,7 +92,7 @@ impl CliLintRule {
9192
use CliLintRuleKind::*;
9293
match &self.0 {
9394
DenoLint(rule) => {
94-
Cow::Owned(format!("https://lint.deno.land/rules/{}", rule.code()))
95+
Cow::Owned(format!("https://docs.deno.com/lint/rules/{}", rule.code()))
9596
}
9697
Extended(rule) => rule.help_docs_url(),
9798
Package(rule) => rule.help_docs_url(),
@@ -284,7 +285,7 @@ mod test {
284285
.resolve_lint_rules(Default::default(), None)
285286
.rules
286287
.into_iter()
287-
.filter(|r| r.tags().iter().any(|t| *t == "recommended"))
288+
.filter(|r| r.tags().iter().any(|t| *t == tags::RECOMMENDED))
288289
.map(|r| r.code().to_string())
289290
.filter(|n| n != "no-debugger")
290291
.collect::<Vec<_>>();

cli/tools/lint/rules/no_sloppy_imports.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use deno_lint::diagnostic::LintDiagnosticRange;
1616
use deno_lint::diagnostic::LintFix;
1717
use deno_lint::diagnostic::LintFixChange;
1818
use deno_lint::rules::LintRule;
19+
use deno_lint::tags;
1920
use deno_resolver::sloppy_imports::SloppyImportsResolution;
2021
use deno_resolver::sloppy_imports::SloppyImportsResolutionKind;
2122
use text_lines::LineAndColumnIndex;
@@ -166,8 +167,8 @@ impl LintRule for NoSloppyImportsRule {
166167
// include_str!("no_sloppy_imports.md")
167168
// }
168169

169-
fn tags(&self) -> &'static [&'static str] {
170-
&["recommended"]
170+
fn tags(&self) -> tags::Tags {
171+
&[tags::RECOMMENDED]
171172
}
172173
}
173174

cli/tools/lint/rules/no_slow_types.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use deno_graph::ModuleGraph;
99
use deno_lint::diagnostic::LintDiagnostic;
1010
use deno_lint::diagnostic::LintDiagnosticDetails;
1111
use deno_lint::diagnostic::LintDiagnosticRange;
12+
use deno_lint::tags;
1213

1314
use super::PackageLintRule;
1415

@@ -22,8 +23,8 @@ impl PackageLintRule for NoSlowTypesRule {
2223
CODE
2324
}
2425

25-
fn tags(&self) -> &'static [&'static str] {
26-
&["jsr"]
26+
fn tags(&self) -> tags::Tags {
27+
&[tags::JSR]
2728
}
2829

2930
// TODO(bartlomieju): these docs need to be hosted somewhere.

0 commit comments

Comments
 (0)