Skip to content

Commit 96ad1db

Browse files
committed
chore: extracted isMethodSymbol to ts-utils
1 parent d428bfd commit 96ad1db

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/eslint-plugin-svelte/src/rules/require-event-prefix.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createRule } from '../utils/index.js';
2-
import { type TSTools, getTypeScriptTools } from '../utils/ts-utils/index.js';
2+
import { type TSTools, getTypeScriptTools, isMethodSymbol } from '../utils/ts-utils/index.js';
33
import {
44
type MethodSignature,
55
type Symbol,
6-
SymbolFlags,
76
SyntaxKind,
87
type Type,
98
type TypeReferenceNode,
@@ -57,7 +56,7 @@ export default createRule('require-event-prefix', {
5756
}
5857
for (const property of propsType.getProperties()) {
5958
if (
60-
isFunctionLike(property) &&
59+
isFunctionLike(property, tsTools) &&
6160
!property.getName().startsWith('on') &&
6261
(checkAsyncFunctions || !isFunctionAsync(property))
6362
) {
@@ -94,9 +93,9 @@ function getPropsType(node: CallExpression, tsTools: TSTools): Type | undefined
9493
return tsTools.service.program.getTypeChecker().getTypeAtLocation(tsNode);
9594
}
9695

97-
function isFunctionLike(functionSymbol: Symbol): boolean {
96+
function isFunctionLike(functionSymbol: Symbol, tsTools: TSTools): boolean {
9897
return (
99-
(functionSymbol.getFlags() & SymbolFlags.Method) !== 0 ||
98+
isMethodSymbol(functionSymbol, tsTools.ts) ||
10099
(functionSymbol.valueDeclaration?.kind === SyntaxKind.PropertySignature &&
101100
(functionSymbol.valueDeclaration as PropertySignature).type?.kind === SyntaxKind.FunctionType)
102101
);

packages/eslint-plugin-svelte/src/utils/ts-utils/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,10 @@ export function getTypeOfPropertyOfType(
307307
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- getTypeOfPropertyOfType is an internal API of TS.
308308
return (checker as any).getTypeOfPropertyOfType(type, name);
309309
}
310+
311+
/**
312+
* Check whether the given symbol is a method type or not.
313+
*/
314+
export function isMethodSymbol(type: TS.Symbol, ts: TypeScript): boolean {
315+
return (type.getFlags() & ts.SymbolFlags.Method) !== 0;
316+
}

0 commit comments

Comments
 (0)