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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
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
31 changes: 7 additions & 24 deletions 31 packages/eslint-plugin/src/rules/no-unused-vars.ts
Original file line number Diff line number Diff 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 deletions 10 packages/eslint-plugin/tests/RuleTester.ts
Original file line number Diff line number Diff 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 Down Expand 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
Original file line number Diff line number Diff 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 deletions 52 packages/eslint-plugin/tests/eslint-rules/no-undef.test.ts
Original file line number Diff line number Diff 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 Down Expand 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.