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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check node argument is defined before use #285

Merged
merged 4 commits into from Jun 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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