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): [no-misused-promises] improve report loc for methods#10216

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
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
22 commits
Select commitHold shift + click to select a range
359e052
fix(eslint-plugin): correctly report errors for async methods returni…
gyumongOct 27, 2024
d8c6635
test add coverage
gyumongOct 27, 2024
3d26e12
fix: remove unreachable code
gyumongOct 27, 2024
a5dbd87
fix: simplify redundant if checks in context.report logic
gyumongOct 27, 2024
a762f40
test: specify error location in voidReturnProperty test cases
gyumongOct 27, 2024
8b1393c
Merge branch 'main' into fix-no-misused-promises
gyumongOct 27, 2024
432b792
fix lint
gyumongOct 27, 2024
2207c17
Merge branch 'main' into fix-no-misused-promises
gyumongOct 28, 2024
aa8f8c6
Merge branch 'main' into fix-no-misused-promises
gyumongOct 29, 2024
4c7d787
test: add full loc (line, endLine, column, endColumn) to existing tes…
gyumongOct 31, 2024
65ae628
test: add new invalid test cases for promise-returning methods withou…
gyumongOct 31, 2024
801bf4c
fix : test col
gyumongOct 31, 2024
f367c20
fix: log
gyumongOct 31, 2024
09be707
Merge branch 'main' into fix-no-misused-promises
gyumongOct 31, 2024
e79283c
Update packages/eslint-plugin/src/rules/no-misused-promises.ts
gyumongNov 1, 2024
1278e3d
Merge branch 'main' into fix-no-misused-promises
gyumongNov 4, 2024
2bc7666
refactor(no-misused-promises): improve function type checking in void…
gyumongNov 4, 2024
2da0b5c
test(no-misused-promises): add test cases for isFunction utility usage
gyumongNov 4, 2024
ac34e36
Merge branch 'main' into fix-no-misused-promises
gyumongNov 5, 2024
c7ac4e6
test(no-misused-promises): add test cases
gyumongNov 5, 2024
50a6252
Merge branch 'main' into fix-no-misused-promises
gyumongNov 6, 2024
eb66dbd
Merge branch 'main' into fix-no-misused-promises
gyumongNov 8, 2024
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
42 changes: 34 additions & 8 deletionspackages/eslint-plugin/src/rules/no-misused-promises.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import * as ts from 'typescript';

import {
createRule,
getFunctionHeadLoc,
getParserServices,
isArrayMethodCallWithPredicate,
isFunction,
Expand DownExpand Up@@ -436,10 +437,25 @@ export default createRule<Options, MessageId>({
) &&
returnsThenable(checker, tsNode.initializer)
) {
context.report({
node: node.value,
messageId: 'voidReturnProperty',
});
if (isFunction(node.value)) {
const functionNode = node.value;
if (functionNode.returnType) {
context.report({
node: functionNode.returnType.typeAnnotation,
messageId: 'voidReturnProperty',
});
} else {
context.report({
loc: getFunctionHeadLoc(functionNode, context.sourceCode),
messageId: 'voidReturnProperty',
});
}
} else {
context.report({
node: node.value,
messageId: 'voidReturnProperty',
});
}
}
} else if (ts.isShorthandPropertyAssignment(tsNode)) {
const contextualType = checker.getContextualType(tsNode.name);
Expand DownExpand Up@@ -490,10 +506,19 @@ export default createRule<Options, MessageId>({
);

if (isVoidReturningFunctionType(checker, tsNode.name, contextualType)) {
context.report({
node: node.value,
messageId: 'voidReturnProperty',
});
const functionNode = node.value as TSESTree.FunctionExpression;

if (functionNode.returnType) {
context.report({
node: functionNode.returnType.typeAnnotation,
messageId: 'voidReturnProperty',
});
} else {
context.report({
loc: getFunctionHeadLoc(functionNode, context.sourceCode),
messageId: 'voidReturnProperty',
});
}
}
return;
}
Expand All@@ -513,6 +538,7 @@ export default createRule<Options, MessageId>({
}
return nullThrows(current, NullThrowsReasons.MissingParent);
})();

if (
functionNode.returnType &&
!isPossiblyFunctionType(functionNode.returnType)
Expand Down
149 changes: 148 additions & 1 deletionpackages/eslint-plugin/tests/rules/no-misused-promises.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1405,6 +1405,9 @@ const obj: O = {
`,
errors: [
{
column: 3,
endColumn: 12,
endLine: 4,
line: 4,
messageId: 'voidReturnProperty',
},
Expand All@@ -1419,6 +1422,9 @@ const obj: O = {
`,
errors: [
{
column: 3,
endColumn: 12,
endLine: 4,
line: 4,
messageId: 'voidReturnProperty',
},
Expand DownExpand Up@@ -1451,6 +1457,9 @@ const obj: O = {
`,
errors: [
{
column: 3,
endColumn: 10,
endLine: 4,
line: 4,
messageId: 'voidReturnProperty',
},
Expand All@@ -1472,14 +1481,23 @@ function f(): O {
`,
errors: [
{
column: 5,
endColumn: 12,
endLine: 6,
line: 6,
messageId: 'voidReturnProperty',
},
{
column: 5,
endColumn: 14,
endLine: 9,
line: 9,
messageId: 'voidReturnProperty',
},
{
column: 5,
endColumn: 6,
endLine: 10,
line: 10,
messageId: 'voidReturnProperty',
},
Expand DownExpand Up@@ -1783,7 +1801,15 @@ const test: ReturnsRecord = () => {
return { asynchronous: async () => {} };
};
`,
errors: [{ line: 5, messageId: 'voidReturnProperty' }],
errors: [
{
column: 12,
endColumn: 32,
endLine: 5,
line: 5,
messageId: 'voidReturnProperty',
},
],
},
{
code: `
Expand DownExpand Up@@ -2429,5 +2455,126 @@ arrayFn<() => void>(
},
],
},
{
code: `
type HasVoidMethod = {
f(): void;
};

const o: HasVoidMethod = {
async f() {
return 3;
},
};
`,
errors: [
{
column: 3,
endColumn: 10,
endLine: 7,
line: 7,
messageId: 'voidReturnProperty',
},
],
},
{
code: `
type HasVoidMethod = {
f(): void;
};

const o: HasVoidMethod = {
async f(): Promise<number> {
return 3;
},
};
`,
errors: [
{
column: 14,
endColumn: 29,
endLine: 7,
line: 7,
messageId: 'voidReturnProperty',
},
],
},
{
code: `
type HasVoidMethod = {
f(): void;
};
const obj: HasVoidMethod = {
f() {
return Promise.resolve('foo');
},
};
`,
errors: [
{
column: 3,
endColumn: 4,
endLine: 6,
line: 6,
messageId: 'voidReturnProperty',
},
],
},
{
code: `
type HasVoidMethod = {
f(): void;
};
const obj: HasVoidMethod = {
f(): Promise<void> {
throw new Error();
},
};
`,
errors: [
{
column: 8,
endColumn: 21,
endLine: 6,
line: 6,
messageId: 'voidReturnProperty',
},
],
},
{
code: `
type O = { f: () => void };
const asyncFunction = async () => 'foo';
const obj: O = {
f: asyncFunction,
};
`,
errors: [
{
column: 6,
endColumn: 19,
endLine: 5,
line: 5,
messageId: 'voidReturnProperty',
},
],
},
{
code: `
type O = { f: () => void };
const obj: O = {
f: async (): Promise<string> => 'foo',
};
`,
errors: [
{
column: 16,
endColumn: 31,
endLine: 4,
line: 4,
messageId: 'voidReturnProperty',
},
],
},
],
});
Loading

[8]ページ先頭

©2009-2025 Movatter.jp