Skip to content

Commit

Permalink
feat: upgrade to deno_ast 0.30 (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Oct 20, 2023
1 parent c83f725 commit f210fc6
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 120 deletions.
44 changes: 22 additions & 22 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ default = []
docs = []

[dependencies]
deno_ast = { version = "0.29.0", features = ["scopes", "transforms", "utils", "visit", "view", "module_specifier"] }
deno_ast = { version = "0.30.0", features = ["scopes", "transforms", "utils", "visit", "view", "module_specifier"] }
log = "0.4.14"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
Expand Down
10 changes: 10 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tasks": {
"update-docs": "cargo run --features=docs --example dlint rules --json > www/static/docs.json"
},
"exclude": [
"target",
"examples",
"benchmarks/oak"
]
}
2 changes: 2 additions & 0 deletions docs/rules/no_unsafe_negation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ it will be less confusing.

### Invalid:

<!-- deno-fmt-ignore -->

```typescript
if (!key in object) {}
if (!foo instanceof Foo) {}
Expand Down
18 changes: 7 additions & 11 deletions examples/dlint/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,16 @@ fn colorize_code_block(lang: CodeBlockLang, src: &str) -> String {
decorate(&line[range], Attribute::Yellow)
}
Word::Keyword(_) => decorate(&line[range], Attribute::Cyan),
Word::Ident(ident) => {
if ident == *"undefined" {
decorate(&line[range], Attribute::Gray)
} else if ident == *"Infinity" || ident == *"NaN" {
Word::Ident(ident) => match ident.as_ref() {
"undefined" => decorate(&line[range], Attribute::Gray),
"Infinity" | "NaN" => {
decorate(&line[range], Attribute::Yellow)
} else if matches!(
ident.as_ref(),
"async" | "of" | "enum" | "type" | "interface"
) {
}
"async" | "of" | "enum" | "type" | "interface" => {
decorate(&line[range], Attribute::Cyan)
} else {
line[range].to_string()
}
}
_ => line[range].to_string(),
},
},
_ => line[range].to_string(),
},
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.70.0"
channel = "1.73.0"
components = ["clippy", "rustfmt"]
12 changes: 3 additions & 9 deletions src/control_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,19 +471,13 @@ impl Visit for Analyzer<'_> {
.cases
.iter()
.filter_map(|case| self.get_end_reason(case.start()))
.fold(
Some(End::Forced {
.try_fold(
End::Forced {
ret: false,
throw: false,
infinite_loop: false,
}),
|acc, cur| {
if let Some(acc) = acc {
acc.merge_forced(cur)
} else {
None
}
},
|acc, cur| acc.merge_forced(cur),
);

match forced_end {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/ban_ts_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ fn check_comment(comment: &Comment) -> Option<DirectiveKind> {
}

static EXPECT_ERROR_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"^/*\s*@ts-expect-error\s*$"#).unwrap());
Lazy::new(|| Regex::new(r"^/*\s*@ts-expect-error\s*$").unwrap());
static IGNORE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"^/*\s*@ts-ignore\s*$"#).unwrap());
Lazy::new(|| Regex::new(r"^/*\s*@ts-ignore\s*$").unwrap());
static NOCHECK_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"^/*\s*@ts-nocheck\s*$"#).unwrap());
Lazy::new(|| Regex::new(r"^/*\s*@ts-nocheck\s*$").unwrap());

if EXPECT_ERROR_REGEX.is_match(&comment.text) {
return Some(DirectiveKind::ExpectError);
Expand Down
6 changes: 4 additions & 2 deletions src/rules/ban_untagged_ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ impl LintRule for BanUntaggedIgnore {
let mut violated_ranges: Vec<SourceRange> = context
.file_ignore_directive()
.iter()
.filter_map(|d| d.ignore_all().then(|| d.range()))
.filter(|d| d.ignore_all())
.map(|d| d.range())
.collect();

violated_ranges.extend(
context
.line_ignore_directives()
.values()
.filter_map(|d| d.ignore_all().then(|| d.range())),
.filter(|d| d.ignore_all())
.map(|d| d.range()),
);

for range in violated_ranges {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/ban_untagged_todo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn check_comment(comment: &Comment) -> bool {
}

static TODO_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"todo\((#|@)?\S+\)"#).unwrap());
Lazy::new(|| Regex::new(r"todo\((#|@)?\S+\)").unwrap());

if TODO_RE.is_match(text) {
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/rules/fresh_handler_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ impl Handler for Visitor {
let id = match export_decl.decl {
Decl::Var(var_decl) => {
if let Some(first) = var_decl.decls.first() {
let Pat::Ident(name_ident) = first.name else {return};
let Pat::Ident(name_ident) = first.name else {
return;
};
name_ident.id
} else {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/rules/fresh_server_event_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ impl Handler for Visitor {
_ => return,
};

let JSXExpr::Expr(expr_value) = expr.expr else {return};
let JSXExpr::Expr(expr_value) = expr.expr else {
return;
};

// If we pass a function expression or an arrow function expression
// then we know for sure that we can't render that.
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no_console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ mod tests {
assert_lint_ok!(
NoConsole,
// ignored
r#"// deno-lint-ignore no-console\nconsole.error('Error message');"#,
r"// deno-lint-ignore no-console\nconsole.error('Error message');",
// not global
r#"const console = { log() {} } console.log('Error message');"#,
r"const console = { log() {} } console.log('Error message');",
);
}

Expand Down
Loading

0 comments on commit f210fc6

Please sign in to comment.