Skip to content

Commit

Permalink
fix: add defined guards to util functions (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored and SimenB committed Jun 22, 2019
1 parent d7a9532 commit 9cba626
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/rules/__tests__/no-empty-title.js
Expand Up @@ -11,6 +11,7 @@ const ruleTester = new RuleTester({

ruleTester.run('no-empty-title', rule, {
valid: [
'describe()',
'someFn("", function () {})',
'describe(1, function () {})',
'describe("foo", function () {})',
Expand Down
18 changes: 12 additions & 6 deletions src/rules/util.js
Expand Up @@ -125,18 +125,24 @@ const isTestCase = node =>
testCaseNames[getNodeName(node.callee)];

const isDescribe = node =>
node.type === 'CallExpression' && describeAliases[getNodeName(node.callee)];
node &&
node.type === 'CallExpression' &&
describeAliases[getNodeName(node.callee)];

const isFunction = node =>
node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
node &&
(node.type === 'FunctionExpression' ||
node.type === 'ArrowFunctionExpression');

const isString = node =>
(node.type === 'Literal' && typeof node.value === 'string') ||
isTemplateLiteral(node);
node &&
((node.type === 'Literal' && typeof node.value === 'string') ||
isTemplateLiteral(node));

const isTemplateLiteral = node => node.type === 'TemplateLiteral';
const isTemplateLiteral = node => node && node.type === 'TemplateLiteral';

const hasExpressions = node => node.expressions && node.expressions.length > 0;
const hasExpressions = node =>
node && node.expressions && node.expressions.length > 0;

const getStringValue = arg =>
isTemplateLiteral(arg) ? arg.quasis[0].value.raw : arg.value;
Expand Down

0 comments on commit 9cba626

Please sign in to comment.