diff --git a/src/plugins/trackCodeFlow/index.spec.ts b/src/plugins/trackCodeFlow/index.spec.ts index ec4a7be..1da9474 100644 --- a/src/plugins/trackCodeFlow/index.spec.ts +++ b/src/plugins/trackCodeFlow/index.spec.ts @@ -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({ diff --git a/src/plugins/trackCodeFlow/varTracking.ts b/src/plugins/trackCodeFlow/varTracking.ts index 007bea2..6c5cd03 100644 --- a/src/plugins/trackCodeFlow/varTracking.ts +++ b/src/plugins/trackCodeFlow/varTracking.ts @@ -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()); diff --git a/test/project1/source/const.bs b/test/project1/source/const.bs new file mode 100644 index 0000000..27f2d1d --- /dev/null +++ b/test/project1/source/const.bs @@ -0,0 +1,4 @@ +const a = "noop" +sub test() + print a ' not an error +end sub