Skip to content

Commit 1a5b2df

Browse files
committed
chore: extracted isMethodType to ts-utils
1 parent d428bfd commit 1a5b2df

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

+7-5
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, isMethodType } 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,12 @@ 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+
isMethodType(
99+
tsTools.service.program.getTypeChecker().getTypeOfSymbol(functionSymbol),
100+
tsTools.ts
101+
) ||
100102
(functionSymbol.valueDeclaration?.kind === SyntaxKind.PropertySignature &&
101103
(functionSymbol.valueDeclaration as PropertySignature).type?.kind === SyntaxKind.FunctionType)
102104
);

Diff for: packages/eslint-plugin-svelte/src/utils/ts-utils/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ export function isVoidType(type: TS.Type, ts: TypeScript): boolean {
190190
export function isNullType(type: TS.Type, ts: TypeScript): boolean {
191191
return (type.flags & ts.TypeFlags.Null) !== 0;
192192
}
193+
/**
194+
* Check whether the given type is a method type or not.
195+
*/
196+
export function isMethodType(type: TS.Type, ts: TypeScript): boolean {
197+
return (type.flags & ts.SymbolFlags.Method) !== 0;
198+
}
193199
/**
194200
* Check whether the given type is a possibly falsy type or not.
195201
*/

0 commit comments

Comments
 (0)