Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): handle optional chaining in scope analysis (#1169)
Co-authored-by: nizarius <petrpotapov@Petrs-MacBook-Pro.local> Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
- Loading branch information
1 parent
96d1cc3
commit 026ceb9
Showing
5 changed files
with
384 additions
and
978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/eslint-plugin/tests/eslint-rules/no-use-before-define.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import rule from 'eslint/lib/rules/no-use-before-define'; | ||
import { RuleTester } from '../RuleTester'; | ||
|
||
const ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 6, | ||
sourceType: 'module', | ||
ecmaFeatures: {}, | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
}); | ||
|
||
ruleTester.run('no-use-before-define', rule, { | ||
valid: [ | ||
` | ||
const updatedAt = data?.updatedAt; | ||
`, | ||
` | ||
function f() { | ||
return function t() {}; | ||
} | ||
f()?.(); | ||
`, | ||
` | ||
var a = { b: 5 }; | ||
alert(a?.b); | ||
`, | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
f(); | ||
function f() {} | ||
`, | ||
errors: [ | ||
{ | ||
message: "'f' was used before it was defined.", | ||
// the base rule doesn't use messageId | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
alert(a); | ||
var a = 10; | ||
`, | ||
errors: [ | ||
{ | ||
message: "'a' was used before it was defined.", | ||
// the base rule doesn't use messageId | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
f()?.(); | ||
function f() { | ||
return function t() {}; | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
message: "'f' was used before it was defined.", | ||
// the base rule doesn't use messageId | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
alert(a?.b); | ||
var a = { b: 5 }; | ||
`, | ||
errors: [ | ||
{ | ||
message: "'a' was used before it was defined.", | ||
// the base rule doesn't use messageId | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any, | ||
], | ||
}, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.