Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5da0c85
chore(linter): no-unused-vars boilerplate
DonIsaac Jul 23, 2023
c7a1958
feat(linter): add no-unused-vars options parsing
DonIsaac Jul 23, 2023
bfa819a
refactor(linter): regex option parsing, clippy fixes
DonIsaac Jul 23, 2023
03d3358
feat: start reference resolution steps
DonIsaac Jul 23, 2023
fef74ce
fix(linter): start var impl
DonIsaac Jul 24, 2023
56b4c41
Merge branch 'main' of https://github.com/Boshen/oxc into don/feat/no…
DonIsaac Jul 25, 2023
3603c40
test(linter): more no-unused-vars test cases
DonIsaac Jul 25, 2023
a974932
test(linter): start enabling eslint test cases
DonIsaac Jul 26, 2023
d196582
feat(linter/no-unused-vars): support exports
DonIsaac Jul 27, 2023
f2b8019
test(linter/no-unused-vars): add more fail cases
DonIsaac Jul 27, 2023
6e413b5
feat(linter/no-unused-vars): support class decls
DonIsaac Jul 27, 2023
7a3d490
feat(linter/no-unused-vars): start supporting args
DonIsaac Jul 27, 2023
b3177d7
Merge branch 'main' of https://github.com/Boshen/oxc into don/feat/no…
DonIsaac Jul 27, 2023
23562d0
refactor(linter/no-unused-vars): remove reliance on experimental feat…
DonIsaac Jul 27, 2023
e6a6bf6
feat(linter/no-unused-args): support after-used
DonIsaac Jul 28, 2023
a473a28
refactor(linter/no-unused-vars): cleanup
DonIsaac Jul 28, 2023
5084705
feat(linter/no-unused-vars): support caught errors
DonIsaac Jul 28, 2023
477c61e
test(linter/no-unused-vars): enable more passing tests
DonIsaac Jul 28, 2023
36c9dd5
fix(linter/no-unused-vars): support var: local option
DonIsaac Jul 28, 2023
f34e746
fix(linter/no-unused-vars): support exported variables
DonIsaac Jul 28, 2023
ed59097
feat(linter/no-unused-vars): start recursive binding check
DonIsaac Jul 28, 2023
f284f56
Merge branch 'main' of https://github.com/Boshen/oxc into don/feat/no…
DonIsaac Jul 28, 2023
410d739
feat(linter/no-unused-vars): arr/obj unpacking
DonIsaac Jul 29, 2023
3730312
fix(linter/no-unused-vars): arr unpacking in function args
DonIsaac Jul 29, 2023
e5a9007
style(linter): fix clippy lints
DonIsaac Jul 29, 2023
8966874
style(linter/no-unused-vars): fix clippy lints
DonIsaac Jul 29, 2023
a886407
test(linter/no-unused-vars): report unused imports, add a lot of fail…
DonIsaac Jul 29, 2023
dcf2e40
test(linter/no-unused-vars): more testing
DonIsaac Jul 29, 2023
def7d6b
feat(linter/no-unused-vars): support ignore rest siblings
DonIsaac Jul 29, 2023
0267425
Merge branch 'main' of https://github.com/Boshen/oxc into don/feat/no…
DonIsaac Jul 29, 2023
8c6d70f
fix(linter/no-unused-vars): more progress
DonIsaac Jul 31, 2023
dd16c82
Merge branch 'main' of https://github.com/Boshen/oxc into don/feat/no…
DonIsaac Jul 31, 2023
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
Prev Previous commit
Next Next commit
fix(linter/no-unused-vars): support var: local option
  • Loading branch information
DonIsaac committed Jul 28, 2023
commit 36c9dd52e469dd35532fa0f43870c737291c921d
60 changes: 28 additions & 32 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl NoUnusedVarsDiagnostic {
}
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq)]
pub enum VarsOption {
/// All variables are checked for usage, including those in the global scope.
#[default]
Expand Down Expand Up @@ -391,6 +391,11 @@ impl NoUnusedVars {
return;
}

// Allow `var x` for "vars": "local" b/c var keyword has side effects
if self.vars == VarsOption::Local && decl.kind.is_var() {
return;
}

ctx.diagnostic(NoUnusedVarsDiagnostic::decl(name.clone(), decl.span))
// if let Some(pat) = &self.vars_ignore_pattern && pat.is_match(identifier.name.as_str()) {
// return
Expand Down Expand Up @@ -738,15 +743,6 @@ mod tests {
use crate::tester::Tester;

// test-only trait implementations to make testing easier
impl PartialEq for VarsOption {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::All, Self::All) => true,
(Self::Local, Self::Local) => true,
_ => false,
}
}
}

impl PartialEq for ArgsOption {
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -924,13 +920,13 @@ mod tests {
Some(serde_json::json!(["all"])),
),
// todo
// ("function a(x, y){ return y; }; a();", Some(serde_json::json!(["all"]))),
("function a(x, y){ return y; }; a();", Some(serde_json::json!(["all"]))),
(
"var arr1 = [1, 2]; var arr2 = [3, 4]; for (var i in arr1) { arr1[i] = 5; } for (var i in arr2) { arr2[i] = 10; }",
Some(serde_json::json!(["all"])),
),
// todo
// ("var a=10;", Some(serde_json::json!(["local"]))),
("var a=10;", Some(serde_json::json!(["local"]))),
("var min = \"min\"; Math[min];", Some(serde_json::json!(["all"]))),
("Foo.bar = function(baz) { return baz; };", Some(serde_json::json!(["all"]))),
("myFunc(function foo() {}.bind(this))", None),
Expand All @@ -946,14 +942,14 @@ mod tests {
"var a=10; (function() { alert(a); })();",
Some(serde_json::json!([{ "vars": "all" }])),
),
// (
// "function g(bar, baz) { return baz; }; g();",
// Some(serde_json::json!([{ "vars": "all" }])),
// ),
// (
// "function g(bar, baz) { return baz; }; g();",
// Some(serde_json::json!([{ "vars": "all", "args": "after-used" }])),
// ),
(
"function g(bar, baz) { return baz; }; g();",
Some(serde_json::json!([{ "vars": "all" }])),
),
(
"function g(bar, baz) { return baz; }; g();",
Some(serde_json::json!([{ "vars": "all", "args": "after-used" }])),
),
(
"function g(bar, baz) { return bar; }; g();",
Some(serde_json::json!([{ "vars": "all", "args": "none" }])),
Expand All @@ -971,18 +967,18 @@ mod tests {
Some(serde_json::json!([{ "vars": "all", "args": "none" }])),
),
("(function z() { z(); })();", None),
// (" ", None),
(" ", None),
("var who = \"Paul\";\nmodule.exports = `Hello ${who}!`;", None),
// ("export var foo = 123;", None),
("export function foo () {}", None),
// todo
// FIXME
// ("let toUpper = (partial) => partial.toUpperCase; export {toUpper}", None),
("export class foo {}", None),
// ("class Foo{}; var x = new Foo(); x.foo()", None),
// (
// "const foo = \"hello!\";function bar(foobar = foo) { foobar.replace(/!$/, \" world!\");}\nbar();",
// None,
// ),
("class Foo{}; var x = new Foo(); x.foo()", None),
(
"const foo = \"hello!\";function bar(foobar = foo) { foobar.replace(/!$/, \" world!\");}\nbar();",
None,
),
("function Foo(){}; var x = new Foo(); x.foo()", None),
("function foo() {var foo = 1; return foo}; foo();", None),
("function foo(foo) {return foo}; foo(1);", None),
Expand Down Expand Up @@ -1021,10 +1017,10 @@ mod tests {
// ("/*eslint use-every-a:1*/ !function() { var a; return 1 }", None),
("var _a;", Some(serde_json::json!([{ "vars": "all", "varsIgnorePattern": "^_" }]))),
// todo
// (
// "var a; function foo() { var _b; } foo();",
// Some(serde_json::json!([{ "vars": "local", "varsIgnorePattern": "^_" }])),
// ),
(
"var a; function foo() { var _b; } foo();",
Some(serde_json::json!([{ "vars": "local", "varsIgnorePattern": "^_" }])),
),
(
"function foo(_a) { } foo();",
Some(serde_json::json!([{ "args": "all", "argsIgnorePattern": "^_" }])),
Expand Down Expand Up @@ -1096,7 +1092,7 @@ mod tests {
serde_json::json!([{ "caughtErrors": "all", "caughtErrorsIgnorePattern": "^ignore" }]),
),
),
// ("try{}catch(err){}", Some(serde_json::json!([{ "vars": "all", "args": "all" }]))),
("try{}catch(err){}", Some(serde_json::json!([{ "vars": "all", "args": "all" }]))),
// (
// "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(coords);",
// Some(serde_json::json!([{ "ignoreRestSiblings": true }])),
Expand Down