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:
parent
ad50c0df34
commit
0697578d3e
7 changed files with 51 additions and 21 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1937,9 +1937,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_lint"
|
||||
version = "0.68.2"
|
||||
version = "0.69.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce713d564f76efd90535061113210bdc6b942ed6327b33eb1d5f76a5daf8e7a5"
|
||||
checksum = "802583d3ca6c7063e14cafa02ddc206fb34e804e095d52032baf375c56a99515"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"deno_ast",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"ban-untagged-ignore",
|
||||
"ban-untagged-todo",
|
||||
"ban-unused-ignore",
|
||||
"button-has-type",
|
||||
"camelcase",
|
||||
"constructor-super",
|
||||
"default-param-last",
|
||||
|
@ -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",
|
||||
|
@ -32,6 +44,7 @@
|
|||
"no-const-assign",
|
||||
"no-constant-condition",
|
||||
"no-control-regex",
|
||||
"no-danger",
|
||||
"no-debugger",
|
||||
"no-delete-var",
|
||||
"no-deprecated-deno-api",
|
||||
|
@ -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",
|
||||
|
@ -92,6 +105,7 @@
|
|||
"no-unsafe-negation",
|
||||
"no-unused-labels",
|
||||
"no-unused-vars",
|
||||
"no-useless-rename",
|
||||
"no-var",
|
||||
"no-window",
|
||||
"no-window-prefix",
|
||||
|
@ -103,6 +117,7 @@
|
|||
"prefer-primordials",
|
||||
"require-await",
|
||||
"require-yield",
|
||||
"rules-of-hooks",
|
||||
"single-var-declarator",
|
||||
"triple-slash-reference",
|
||||
"use-isnan",
|
||||
|
|
|
@ -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(),
|
||||
|
@ -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!({
|
||||
|
@ -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(),
|
||||
})
|
||||
})
|
||||
|
@ -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!(
|
||||
|
@ -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!();
|
||||
|
@ -658,11 +667,14 @@ mod tests {
|
|||
|
||||
std::fs::write(
|
||||
&rules_schema_path,
|
||||
format!(
|
||||
"{}\n",
|
||||
serde_json::to_string_pretty(&RulesSchema {
|
||||
schema: schema.schema,
|
||||
rules: all_rules,
|
||||
})
|
||||
.unwrap(),
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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 {
|
||||
&[]
|
||||
}
|
||||
|
||||
|
@ -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(),
|
||||
|
@ -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(),
|
||||
|
@ -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<_>>();
|
||||
|
|
|
@ -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;
|
||||
|
@ -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]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue