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

fix: do not consider consts as unused variables #85

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/plugins/trackCodeFlow/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ describe('trackCodeFlow', () => {
expect(actual).deep.equal(expected);
});

it('does not mark consts as uninitialised vars', async () => {
const diagnostics = await linter.run({
...project1,
files: ['source/const.bs'],
rules: {
'unused-variable': 'error'
},
diagnosticFilters: [1001]
} as any);
const actual = fmtDiagnostics(diagnostics);
const expected = [];
expect(actual).deep.equal(expected);
});

describe('does not mark enums as uninitialised vars', () => {
it('in a regular file', async () => {
const diagnostics = await linter.run({
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/trackCodeFlow/varTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ function deferredVarLinter(
scope.getEnumMap().forEach(enm => {
toplevel.add(enm.item.name.toLowerCase());
});
scope.getConstMap().forEach(cnt => {
toplevel.add(cnt.item.name.toLowerCase());
});
if (isBrsFile(file)) {
file.parser.references.classStatements.forEach(cls => {
toplevel.add(cls.name.text.toLowerCase());
Expand Down
4 changes: 4 additions & 0 deletions test/project1/source/const.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const a = "noop"
sub test()
print a ' not an error
end sub