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#233

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 merge13 commits intotypescript-eslint:masterfromarmano2:scope2
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
1fc7917
feat(parser): update scope-analysis part 1
armano2Feb 12, 2019
fe33679
feat(parser): fix index signature and add invalid test
armano2Feb 12, 2019
4309653
feat(parser): remove redundant tests fixtures
armano2Feb 12, 2019
f07ee4a
feat(parser): allow to setup env in RuleTester
armano2Feb 12, 2019
73813ed
fix(parser): split variables from types
armano2Feb 13, 2019
9a6d774
chore(parser): fix formatting
armano2Feb 13, 2019
7d9bf1a
fix(parser): make sure that overrides implements Scope
armano2Feb 13, 2019
7070e8a
fix(parser): restore some scope logic
armano2Feb 13, 2019
6d06f21
fix(parser): fix visiting classes and add setTypes
armano2Feb 13, 2019
84ba37a
Merge branch 'master' into scope2
armano2Feb 13, 2019
b542328
fix(parser): fix scopes
armano2Feb 13, 2019
1741942
chore(parser): fix code formatting
armano2Feb 13, 2019
252d004
fix(parser): correct typeParameters in interfaces
armano2Feb 14, 2019
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@@ -24,41 +24,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) {
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
10 changes: 7 additions & 3 deletionspackages/eslint-plugin/tests/RuleTester.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,11 @@ import { RuleTester as ESLintRuleTester } from 'eslint';
import * as path from 'path';
import RuleModule from 'ts-eslint';

interface EnvTestOptions {
browser?: boolean;
es6?: boolean;
}

interface ValidTestCase<TOptions extends Readonly<any[]>> {
code: string;
options?: TOptions;
Expand All@@ -12,9 +17,7 @@ interface ValidTestCase<TOptions extends Readonly<any[]>> {
settings?: Record<string, any>;
parser?: string;
globals?: Record<string, boolean>;
env?: {
browser?: boolean;
};
env?: EnvTestOptions;
}

interface InvalidTestCase<
Expand DownExpand Up@@ -53,6 +56,7 @@ declare class RuleTesterTyped {
const RuleTester = (ESLintRuleTester as any) as {
new (config?: {
parser: '@typescript-eslint/parser';
env?: EnvTestOptions;
parserOptions?: ParserOptions;
}): RuleTesterTyped;
};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -76,6 +76,10 @@ function A<T>() {}
interface B<T> {}
type C<T> = Array<T>
class D<T> {}
`,
`
interface foo<TMessageIds> {}
interface bar<TMessageIds> {}
`
],
invalid: [
Expand Down
52 changes: 45 additions & 7 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,
sourceType: 'module',
ecmaFeatures: {}
ecmaVersion: 10,
sourceType: 'module'
},
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,14 +64,48 @@ 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
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/18
`
function eachr<Key, Value>(subject: Map<Key, Value>): typeof subject;
`,
// 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: []
invalid: [
{
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