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

[WIP] feat(linter): add eslint/no-unused-vars #642

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,33 @@ impl<'a> BindingPatternKind<'a> {
pub fn is_binding_identifier(&self) -> bool {
matches!(self, Self::BindingIdentifier(_))
}

/// Get the [`BindingIdentifier`] for this pattern if it is not a destructuring pattern.
pub fn identifier(&self) -> Option<&Box<'_, BindingIdentifier>> {
match self {
BindingPatternKind::BindingIdentifier(id) => Some(id),
BindingPatternKind::AssignmentPattern(pat) => pat.left.kind.identifier(),
_ => None,
}
}

pub fn has_binding_for(&self, name: &Atom) -> bool {
match self {
Self::BindingIdentifier(id) => id.name == name,
Self::AssignmentPattern(id) => id.left.kind.has_binding_for(name),
Self::ObjectPattern(pat) => {
pat.rest.as_ref().is_some_and(|rest| rest.argument.kind.has_binding_for(name))
|| pat.properties.iter().any(|p| p.value.kind.has_binding_for(name))
}
Self::ArrayPattern(pat) => {
pat.rest.as_ref().is_some_and(|rest| rest.argument.kind.has_binding_for(name))
|| pat
.elements
.iter()
.any(|el| el.as_ref().is_some_and(|el| el.kind.has_binding_for(name)))
}
}
}
}

#[derive(Debug, Hash)]
Expand Down Expand Up @@ -1750,6 +1777,17 @@ pub enum ImportDeclarationSpecifier {
/// import * as local from "source"
ImportNamespaceSpecifier(ImportNamespaceSpecifier),
}
impl ImportDeclarationSpecifier {
/// Get the identifier for this import that is referrable by other nodes
/// within the scope the import occurred
pub fn local(&self) -> &BindingIdentifier {
match self {
Self::ImportSpecifier(import) => &import.local,
Self::ImportDefaultSpecifier(import) => &import.local,
Self::ImportNamespaceSpecifier(import) => &import.local,
}
}
}

// import {imported} from "source"
// import {imported as local} from "source"
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ oxc_semantic = { workspace = true }
oxc_syntax = { workspace = true }
oxc_formatter = { workspace = true }

bitflags = { workspace = true }
lazy_static = { workspace = true } # used in oxc_macros
serde_json = { workspace = true }
regex = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ oxc_macros::declare_all_lint_rules! {
eslint::no_unsafe_negation,
eslint::no_unsafe_optional_chaining,
eslint::no_unused_labels,
eslint::no_unused_vars,
eslint::no_useless_catch,
eslint::no_useless_escape,
eslint::require_yield,
Expand Down
Loading