Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(parser): Draft of scope analysis with types#1533

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
armano2 wants to merge12 commits intotypescript-eslint:masterfromarmano2:typed-scopes-v3
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
c47f8d0
feat(parser): update scope-analysis part 1
armano2Feb 12, 2019
3067b9e
feat(parser): fix index signature and add invalid test
armano2Feb 12, 2019
c5c100c
feat(parser): remove redundant tests fixtures
armano2Feb 12, 2019
cf1f888
feat(parser): allow to setup env in RuleTester
armano2Feb 12, 2019
8271872
fix(parser): split variables from types
armano2Feb 13, 2019
fe2a7aa
fix(parser): make sure that overrides implements Scope
armano2Feb 13, 2019
0274924
fix(parser): restore some scope logic
armano2Feb 13, 2019
6ffd678
fix(parser): fix visiting classes and add setTypes
armano2Feb 13, 2019
67090da
fix(parser): fix scopes
armano2Feb 13, 2019
b19fd81
fix(parser): correct typeParameters in interfaces
armano2Feb 14, 2019
d4916ba
fix(parser): correct compile errors in tests
armano2Mar 2, 2019
f115957
fix: code cleanup
armano2Jan 22, 2020
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
31 changes: 7 additions & 24 deletionspackages/eslint-plugin/src/rules/no-unused-vars.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,41 +22,24 @@ export default util.createRule({
create(context) {
const rules = baseRule.create(context);

/**
* Mark heritage clause as used
* @param node The node currently being traversed
*/
function markHeritageAsUsed(node: TSESTree.Expression): void {
function markParameterAsUsed(node: TSESTree.Node): void {
switch (node.type) {
case AST_NODE_TYPES.Identifier:
context.markVariableAsUsed(node.name);
break;
case AST_NODE_TYPES.MemberExpression:
markHeritageAsUsed(node.object);
case AST_NODE_TYPES.AssignmentPattern:
markParameterAsUsed(node.left);
break;
case AST_NODE_TYPES.CallExpression:
markHeritageAsUsed(node.callee);
case AST_NODE_TYPES.RestElement:
markParameterAsUsed(node.argument);
break;
}
}

return Object.assign({}, rules, {
'TSTypeReference Identifier'(node: TSESTree.Identifier) {
context.markVariableAsUsed(node.name);
},
TSInterfaceHeritage(node: TSESTree.TSInterfaceHeritage) {
if (node.expression) {
markHeritageAsUsed(node.expression);
}
},
TSClassImplements(node: TSESTree.TSClassImplements) {
if (node.expression) {
markHeritageAsUsed(node.expression);
}
},
'TSParameterProperty Identifier'(node: TSESTree.Identifier) {
TSParameterProperty(node: TSESTree.TSParameterProperty) {
// just assume parameter properties are used
context.markVariableAsUsed(node.name);
markParameterAsUsed(node.parameter);
},
'TSEnumMember Identifier'(node: TSESTree.Identifier) {
context.markVariableAsUsed(node.name);
Expand Down
18 changes: 18 additions & 0 deletionspackages/eslint-plugin/src/rules/no-use-before-define.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -100,6 +100,21 @@ function isOuterVariable(
);
}

/**
* Checks whether or not a given variable is a type declaration.
*/
function isType(
variable: TSESLint.Scope.Variable,
reference: TSESLint.Scope.Reference,
): boolean {
const node = variable.defs[0].node as TSESTree.Node;

return (
node.type === AST_NODE_TYPES.TSTypeAliasDeclaration &&
isOuterScope(variable, reference)
);
}

/**
* Checks whether or not a given location is inside of the range of a given node.
*/
Expand DownExpand Up@@ -231,6 +246,9 @@ export default util.createRule<Options, MessageIds>({
if (isOuterClass(variable, reference)) {
return !!options.classes;
}
if (isType(variable, reference)) {
return !!options.typedefs;
}
if (isOuterVariable(variable, reference)) {
return !!options.variables;
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -83,6 +83,10 @@ interface B<T> {}
type C<T> = Array<T>
class D<T> {}
`,
`
interface foo<TMessageIds> {}
interface bar<TMessageIds> {}
`,
],
invalid: [
{
Expand Down
47 changes: 42 additions & 5 deletionspackages/eslint-plugin/tests/eslint-rules/no-undef.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,10 +3,10 @@ import { RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parserOptions: {
ecmaVersion:6,
ecmaVersion:10,
sourceType: 'module',
ecmaFeatures: {},
},
env: { es6: true },
parser: '@typescript-eslint/parser',
});

Expand DownExpand Up@@ -35,12 +35,16 @@ class X {
}
`,
// https://github.com/eslint/typescript-eslint-parser/issues/466
`
{
code: `
/*globals document, selector */
const links = document.querySelectorAll( selector ) as NodeListOf<HTMLElement>
`,
`,
env: { browser: true },
},
// https://github.com/eslint/typescript-eslint-parser/issues/437
`
type Result = string
interface Runnable {
run (): Result
toString (): string
Expand All@@ -60,7 +64,7 @@ export class FooBar extends Foo {}
// https://github.com/typescript-eslint/typescript-eslint/issues/18
`
function eachr<Key, Value>(subject: Map<Key, Value>): typeof subject;
function eachr(subject: Object | Array<Value>): typeof subject {
function eachr<Value = string>(subject: Object | Array<Value>): typeof subject {
return subject
}
`,
Expand All@@ -85,6 +89,18 @@ function eachr<Key, Value>(subject: Map<Key, Value>): typeof subject;
var a = { b: () => {} };
a?.b();
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/262
`
export default class Foo {
[key: string]: any;
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/262
`
export default interface Foo {
[key: string]: any;
}
`,
],
invalid: [
{
Expand DownExpand Up@@ -120,5 +136,26 @@ function eachr<Key, Value>(subject: Map<Key, Value>): typeof subject;
},
],
},
{
code: 'function foo(subject: Object<Key> | Array<Value>)',
errors: [
{
messageId: 'undef',
data: {
name: 'Key',
},
line: 1,
column: 30,
},
{
messageId: 'undef',
data: {
name: 'Value',
},
line: 1,
column: 43,
},
],
},
],
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp