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: upgrade to deno_ast 0.30 #1202

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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
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
2 changes: 1 addition & 1 deletion src/rules/no_dupe_class_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<'a, 'b, 'view> Visit for ClassVisitor<'a, 'b, 'view> {
self
.appeared_methods
.entry(m)
.or_insert_with(Vec::new)
.or_default()
.push((class_method.range(), name));
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no_dupe_else_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ impl<'c, 'view> VisitAll for NoDupeElseIfVisitor<'c, 'view> {

fn mk_condition_to_check(cond: Expr) -> Vec<Expr> {
match cond {
Expr::Bin(BinExpr { op, .. }) if op == BinaryOp::LogicalAnd => {
Expr::Bin(BinExpr {
op: BinaryOp::LogicalAnd,
..
}) => {
let mut c = vec![cond.clone()];
c.append(&mut split_by_and(cond));
c
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no_external_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl LintRule for NoExternalImport {
context: &mut Context,
program: Program,
) {
let mut handler = NoExternalImportHandler::default();
let mut handler = NoExternalImportHandler;
handler.traverse(program, context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no_invalid_triple_slash_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl ReportKind {
// These regexes should be consistent with how Deno resolves modules.
// https://github.com/denoland/deno/blob/76e2edc7e1868d7768e259aacbb9a991e1afc462/cli/module_graph.rs
static TRIPLE_SLASH_REFERENCE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"(?i)^/\s*<reference\s.*?/>"#).unwrap());
Lazy::new(|| Regex::new(r"(?i)^/\s*<reference\s.*?/>").unwrap());
static PATH_REFERENCE_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"(?i)\spath\s*=\s*["'](?P<value>[^"']*)["']"#).unwrap()
});
Expand Down
Loading