Skip to content

Commit

Permalink
[eslint] Include field decorators in scope analysis (#16240)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 26, 2024
1 parent a262001 commit 0e5ae8d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion eslint/babel-eslint-parser/src/analyze-scope.cts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ class Referencer extends OriginalReferencer {
}

_visitClassProperty(node: any) {
const { computed, key, typeAnnotation, value } = node;
const { computed, key, typeAnnotation, decorators, value } = node;

this._visitArray(decorators);
if (computed) this.visit(key);
this._visitTypeAnnotation(typeAnnotation);

Expand Down
31 changes: 31 additions & 0 deletions eslint/babel-eslint-tests/test/integration/eslint/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,37 @@ describe("verify", () => {
});
});

describe("decorators #16239", () => {
it("field decorators count as usage for no-unused-vars", () => {
verifyAndAssertMessages(
`
import { tracked } from '@glimmer/tracking';
class State {
@tracked depth = 0;
}
new State();
`,
{ "no-unused-vars": 1 },
);
});
it("method decorators count as usage for no-unused-vars", () => {
verifyAndAssertMessages(
`
import { tracked } from '@glimmer/tracking';
class State {
@tracked depth() { return 0; }
}
new State();
`,
{ "no-unused-vars": 1 },
);
});
});

it("detects minimal no-unused-vars case #120", () => {
verifyAndAssertMessages("var unused;", { "no-unused-vars": 1 }, [
"1:5 'unused' is defined but never used. no-unused-vars",
Expand Down

0 comments on commit 0e5ae8d

Please sign in to comment.