Skip to content
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

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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_config.workspace = true
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = { version = "=0.161.2", features = ["rust", "comrak"] }
deno_graph = { version = "=0.86.3" }
deno_lint = { version = "=0.68.2", features = ["docs"] }
deno_lint = { version = "0.69.0", features = ["docs"] }
deno_lockfile.workspace = true
deno_npm.workspace = true
deno_npm_cache.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: 22 additions & 8 deletions cli/tools/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,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 lint_rules = rule_provider
let mut lint_rules = rule_provider
.resolve_lint_rules(
LintRulesConfig {
tags: maybe_rules_tags.clone(),
Expand All @@ -454,6 +454,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
None,
)
.rules;
lint_rules.sort_by_cached_key(|rule| rule.code().to_string());

if json {
let json_output = serde_json::json!({
Expand All @@ -463,7 +464,7 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
.map(|rule| {
serde_json::json!({
"code": rule.code(),
"tags": rule.tags(),
"tags": rule.tags().iter().map(|t| t.display()).collect::<Vec<_>>(),
"docs": rule.docs(),
})
})
Expand All @@ -479,7 +480,17 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
if rule.tags().is_empty() {
println!();
} else {
println!(" [{}]", colors::gray(rule.tags().join(", ")))
println!(
" [{}]",
colors::gray(
rule
.tags()
.iter()
.map(|t| t.display())
.collect::<Vec<_>>()
.join(", ")
)
)
}
println!(
"{}",
Expand Down Expand Up @@ -612,11 +623,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
7 changes: 4 additions & 3 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 @@ -74,7 +75,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 Down Expand Up @@ -286,7 +287,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]
}

fn docs(&self) -> &'static str {
Expand Down
1 change: 1 addition & 0 deletions hashes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1ee13a3544 07737b03bc 796749c807 9fe52b1e8d 56035f34a2 d7dfd4b540 883abfa1bf 44d76975d5 da3a676d1c 1c0f236923 d99b2d6f7d 94c7653d0e c3af09821a 59dd5d21d4 21a9e2d42b 7bab83d6c0 4ab668ed06 fe1be715d8 7c8b55b584 dd42a64c43 6f506208f6
21 changes: 21 additions & 0 deletions log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
6f506208f6 feat(unstable): support caching npm dependencies only as they're needed (#27300)
dd42a64c43 refactor(lint): manage schema files for linter in Deno repo (#27324)
7c8b55b584 fix(outdated): error when there are no config files (#27306)
fe1be715d8 chore(tests): Deprecate remaining usages of itest in check tests (#26962)
4ab668ed06 fix(lint): do not error providing --allow-import (#27321)
7bab83d6c0 fix(outdated): respect --quiet flag for hints (#27317)
21a9e2d42b perf(compile): improve FileBackedVfsFile (#27299)
59dd5d21d4 fix: replace the @deno-types with @ts-types (#27310)
c3af09821a fix(outdated): show a suggestion for updating (#27304)
94c7653d0e fix(compile): correct read length for transpiled typescript files (#27301)
d99b2d6f7d chore: reduce allocations in a few places (#27288)
1c0f236923 fix(unstable): don't unwrap optional state in otel (#27292)
da3a676d1c fix: do not error when subpath has an @ symbol (#27290)
44d76975d5 fix(node): update list of builtin node modules, add missing export to _http_common (#27294)
883abfa1bf fix(ext/node): handle Float16Array in node:v8 module (#27285)
d7dfd4b540 refactor: Make `deno_runtime::shared` module public (#27242)
56035f34a2 fix(task): do not always kill child on ctrl+c on windows (#27269)
9fe52b1e8d fix: do not panic when fetching invalid file url on Windows (#27259)
796749c807 test(ext/node): remove flaky node:dgram compat test case (#27249)
07737b03bc fix(ext/node): accept file descriptor in fs.readFile(Sync) (#27252)
1ee13a3544 chore: add script to check remaining node compat cases (#27122)
Loading