Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): [member-ordering] add callback as an ordering type of node #3354

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Expand Up @@ -56,6 +56,9 @@ export const defaultOrder = [
// Index signature
'signature',

// Callbacks
'callback',

// Fields
'public-static-field',
'protected-static-field',
Expand Down Expand Up @@ -122,9 +125,13 @@ export const defaultOrder = [
'method',
];

const allMemberTypes = ['signature', 'field', 'method', 'constructor'].reduce<
string[]
>((all, type) => {
const allMemberTypes = [
'signature',
'field',
'method',
'callback',
'constructor',
].reduce<string[]>((all, type) => {
all.push(type);

['public', 'protected', 'private'].forEach(accessibility => {
Expand Down Expand Up @@ -170,13 +177,14 @@ const functionExpressions = [
* @param node the node to be evaluated.
*/
function getNodeType(node: Member): string | null {
// TODO: add missing TSCallSignatureDeclaration
switch (node.type) {
case AST_NODE_TYPES.TSAbstractMethodDefinition:
case AST_NODE_TYPES.MethodDefinition:
return node.kind;
case AST_NODE_TYPES.TSMethodSignature:
return 'method';
case AST_NODE_TYPES.TSCallSignatureDeclaration:
return 'callback';
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'constructor';
case AST_NODE_TYPES.TSAbstractClassProperty:
Expand Down Expand Up @@ -216,6 +224,8 @@ function getMemberName(
: util.getNameFromMember(node, sourceCode);
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'new';
case AST_NODE_TYPES.TSCallSignatureDeclaration:
return 'call';
case AST_NODE_TYPES.TSIndexSignature:
return util.getNameFromIndexSignature(node);
default:
Expand Down