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

fix(eslint-plugin): improve detection of used vars in heritage#102

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

Merged
JamesHenry merged 2 commits intotypescript-eslint:masterfromarmano2:no-unused-vars
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes fromall 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
30 changes: 28 additions & 2 deletionspackages/eslint-plugin/lib/rules/no-unused-vars.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,6 +45,25 @@ module.exports = Object.assign({}, baseRule, {
}
}

/**
* Mark heritage clause as used
* @param node The node currently being traversed
* @returns {void}
*/
function markHeritageAsUsed(node) {
switch (node.type) {
case 'Identifier':
context.markVariableAsUsed(node.name);
break;
case 'MemberExpression':
markHeritageAsUsed(node.object);
break;
case 'CallExpression':
markHeritageAsUsed(node.callee);
break;
}
}

//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
Expand All@@ -54,8 +73,15 @@ module.exports = Object.assign({}, baseRule, {
'TSTypeReference Identifier'(node) {
context.markVariableAsUsed(node.name);
},
'TSClassImplements Identifier'(node) {
context.markVariableAsUsed(node.name);
TSInterfaceHeritage(node) {
if (node.expression) {
markHeritageAsUsed(node.expression);
}
},
TSClassImplements(node) {
if (node.expression) {
markHeritageAsUsed(node.expression);
}
},
'TSParameterProperty Identifier'(node) {
// just assume parameter properties are used
Expand Down
65 changes: 65 additions & 0 deletionspackages/eslint-plugin/tests/lib/rules/no-unused-vars.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -541,6 +541,15 @@ declare var Foo: {
new (value?: any): Object,
foo(): string
}
`,
`
import foo from 'foo';
export interface Bar extends foo.i18n {}
`,
`
import foo from 'foo';
import bar from 'foo';
export interface Bar extends foo.i18n<bar> {}
`
],

Expand DownExpand Up@@ -763,6 +772,62 @@ enum FormFieldIds {
column: 6
}
]
},
{
code: `
import test from 'test';
import baz from 'baz';
export interface Bar extends baz.test {}
`,
errors: [
{
message: "'test' is defined but never used.",
line: 2,
column: 8
}
]
},
{
code: `
import test from 'test';
import baz from 'baz';
export interface Bar extends baz().test {}
`,
errors: [
{
message: "'test' is defined but never used.",
line: 2,
column: 8
}
]
},
{
code: `
import test from 'test';
import baz from 'baz';
export class Bar implements baz.test {}
`,
errors: [
{
message: "'test' is defined but never used.",
line: 2,
column: 8
}
]
},
{
code: `
import test from 'test';
import baz from 'baz';
export class Bar implements baz().test {}
`,
errors: [
{
message: "'test' is defined but never used.",
line: 2,
column: 8
}
]
}
]
});

[8]ページ先頭

©2009-2025 Movatter.jp