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): fix false positive from adjacent-overload-signatures#206

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
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,6 +73,17 @@ module.exports = {
}
}

/**
* Determine whether two methods are the same or not
* @param {{ name: string; static: boolean }} method1 a method to compare
* @param {{ name: string; static: boolean }} method2 another method to compare with
* @returns {boolean} true if two methods are the same
* @private
*/
function isSameMethod(method1, method2) {
return method1.name === method2.name && method1.static === method2.static;
}

/**
* Check the body for overload methods.
* @param {ASTNode} node the body to be inspected.
Expand All@@ -83,28 +94,32 @@ module.exports = {
const members = node.body || node.members;

if (members) {
let name;
let index;
let lastName;
const seen = [];
let lastMethod;
const seenMethods = [];

members.forEach(member => {
name = getMemberName(member);
const name = getMemberName(member);
const method = {
name,
static: member.static
};

index = seen.indexOf(name);
if (index > -1 && lastName !== name) {
const index = seenMethods.findIndex(seenMethod =>
isSameMethod(method, seenMethod)
);
if (index > -1 && !isSameMethod(method, lastMethod)) {
context.report({
node: member,
messageId: 'adjacentSignature',
data: {
name
name: (method.static ? 'static ' : '') + method.name
}
});
} else if (name && index === -1) {
seen.push(name);
seenMethods.push(method);
}

lastName =name;
lastMethod =method;
});
}
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -211,6 +211,23 @@ class Foo {
foo(sn: string | number): void {}
bar(): void {}
baz(): void {}
}
`,
`
class Foo {
name: string;
static foo(s: string): void;
static foo(n: number): void;
static foo(sn: string | number): void {}
bar(): void {}
baz(): void {}
}
`,
`
class Test {
static test() {}
untest() {}
test() {}
}
`,
// examples from https://github.com/nzakas/eslint-plugin-typescript/issues/138
Expand DownExpand Up@@ -789,6 +806,26 @@ class Foo {
column: 5
}
]
},
{
code: `
class Foo {
static foo(s: string): void;
name: string;
static foo(n: number): void;
static foo(sn: string | number): void {}
bar(): void {}
baz(): void {}
}
`,
errors: [
{
messageId: 'adjacentSignature',
data: { name: 'static foo' },
line: 5,
column: 5
}
]
}
]
});

[8]ページ先頭

©2009-2025 Movatter.jp