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

Check if in TypeExpression before doing VariableExpression checks #122

Merged
merged 2 commits into from
Jul 26, 2024
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
28 changes: 28 additions & 0 deletions src/plugins/trackCodeFlow/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,34 @@ describe('trackCodeFlow', () => {
expect(actual).deep.equal(expected);
});

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

it('does not mark typecasts as uninitialised vars', async () => {
const diagnostics = await linter.run({
...project1,
files: ['source/typecast-expressions.bs'],
rules: {
'unused-variable': 'error'
},
diagnosticFilters: []
} 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
2 changes: 1 addition & 1 deletion src/plugins/trackCodeFlow/varTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export function createVarLinter(
}

function visitExpression(expr: Expression, parent: Expression, curr: StatementInfo) {
if (isVariableExpression(expr)) {
if (isVariableExpression(expr) && !util.isInTypeExpression(expr)) {
const name = expr.tokens.name.text;
if (name === 'm') {
return;
Expand Down
10 changes: 10 additions & 0 deletions test/project1/source/inline-functions.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sub main()
takesFunction(function(input as object) as string
return "Hello, " + input.name + "!"
end function)
end sub


sub takesFunction(anonFunc as function)
print anonFunc({name: "Hello, World!"})
end sub
14 changes: 14 additions & 0 deletions test/project1/source/typecast-expression.bs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
typecast m as MyTypeCast



sub main(input)
print m.name
print (input as myTypeCast).name
print (input as dynamic).name
end sub


interface MyTypeCast
name as string
end interface