Skip to content

Commit

Permalink
refactor(eslint-plugin): better namings in explicit-function-return-type
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Feb 23, 2019
1 parent 28d6df6 commit b9e3c06
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/eslint-plugin/src/rules/explicit-function-return-type.ts
Expand Up @@ -45,34 +45,36 @@ export default util.createRule<Options, MessageIds>({
],
create(context, [options]) {
/**
* Checks if the parent of a function expression is a constructor.
* @param parent The parent of a function expression node
* Checks if a node is a constructor.
* @param node The node to check
*/
function isConstructor(parent: TSESTree.Node): boolean {
function isConstructor(node: TSESTree.Node): boolean {
return (
parent.type === AST_NODE_TYPES.MethodDefinition &&
parent.kind === 'constructor'
node.type === AST_NODE_TYPES.MethodDefinition &&
node.kind === 'constructor'
);
}

/**
* Checks if the parent of a function expression is a setter.
* @param parent The parent of a function expression node
* Checks if a node is a setter.
* @param parent The node to check
*/
function isSetter(parent: TSESTree.Node): boolean {
function isSetter(node: TSESTree.Node): boolean {
return (
parent.type === AST_NODE_TYPES.MethodDefinition && parent.kind === 'set'
node.type === AST_NODE_TYPES.MethodDefinition && node.kind === 'set'
);
}

/**
* Checks if the parent of a function expression has a type annotation.
* @param parent The parent of a function expression node
* Checks if a node is a variable declarator with a type annotation.
* @param node The node to check
*/
function hasTypeAnnotation(parent: TSESTree.Node): boolean {
function isVariableDeclaratorWithTypeAnnotation(
node: TSESTree.Node,
): boolean {
return (
parent.type === AST_NODE_TYPES.VariableDeclarator &&
!!parent.id.typeAnnotation
node.type === AST_NODE_TYPES.VariableDeclarator &&
!!node.id.typeAnnotation
);
}

Expand Down Expand Up @@ -122,7 +124,7 @@ export default util.createRule<Options, MessageIds>({
if (
options.allowTypedFunctionExpressions &&
node.parent &&
hasTypeAnnotation(node.parent)
isVariableDeclaratorWithTypeAnnotation(node.parent)
) {
return;
}
Expand Down

0 comments on commit b9e3c06

Please sign in to comment.