Skip to content

Commit

Permalink
feat(eslint-plugin): [member-ordering] add callback as an ordering ty…
Browse files Browse the repository at this point in the history
…pe of node (#3354)

* feat(eslint-plugin): add callback as a filtering type of node

* fix(eslint-plugin): change callback type to call-signature
  • Loading branch information
tanohzana committed May 28, 2021
1 parent 9524424 commit d134b1f
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 31 deletions.
16 changes: 12 additions & 4 deletions packages/eslint-plugin/src/rules/member-ordering.ts
Expand Up @@ -55,6 +55,7 @@ const objectConfig = (memberTypes: string[]): JSONSchema.JSONSchema4 => ({
export const defaultOrder = [
// Index signature
'signature',
'call-signature',

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

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

['public', 'protected', 'private'].forEach(accessibility => {
Expand Down Expand Up @@ -170,13 +175,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 'call-signature';
case AST_NODE_TYPES.TSConstructSignatureDeclaration:
return 'constructor';
case AST_NODE_TYPES.TSAbstractClassProperty:
Expand Down Expand Up @@ -216,6 +222,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

0 comments on commit d134b1f

Please sign in to comment.