Skip to content

Commit

Permalink
fix: add chamges requested in review
Browse files Browse the repository at this point in the history
  • Loading branch information
viestat committed May 4, 2020
1 parent d96ae67 commit b6c50ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
26 changes: 26 additions & 0 deletions src/rules/__tests__/no-interpolation-inline-snapshot.test.ts
Expand Up @@ -14,6 +14,11 @@ ruleTester.run('no-interpolation-inline-snapshot', rule, {
'expect(something).toMatchInlineSnapshot();',
'expect(something).toMatchInlineSnapshot(`No interpolation`);',
'expect(something).toMatchInlineSnapshot({}, `No interpolation`);',
'expect(something);',
'expect(something).not;',
'expect.toHaveAssertions();',
'myObjectWants.toMatchInlineSnapshot({}, `${interpolated}`);',
'toMatchInlineSnapshot({}, `${interpolated}`);',
],
invalid: [
{
Expand All @@ -26,6 +31,16 @@ ruleTester.run('no-interpolation-inline-snapshot', rule, {
},
],
},
{
code: 'expect(something).not.toMatchInlineSnapshot(`${interpolated}`);',
errors: [
{
endColumn: 62,
column: 45,
messageId: 'noInterpolation',
},
],
},
{
code: 'expect(something).toMatchInlineSnapshot({}, `${interpolated}`);',
errors: [
Expand All @@ -36,5 +51,16 @@ ruleTester.run('no-interpolation-inline-snapshot', rule, {
},
],
},
{
code:
'expect(something).not.toMatchInlineSnapshot({}, `${interpolated}`);',
errors: [
{
endColumn: 66,
column: 49,
messageId: 'noInterpolation',
},
],
},
],
});
15 changes: 9 additions & 6 deletions src/rules/no-interpolation-inline-snapshot.ts
@@ -1,5 +1,5 @@
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
import { createRule } from './utils';
import { createRule, isExpectCall, parseExpectCall } from './utils';

export default createRule({
name: __filename,
Expand All @@ -20,18 +20,21 @@ export default createRule({
create(context) {
return {
CallExpression(node) {
const { callee, arguments: nodeArguments } = node;
if (!isExpectCall(node)) {
return;
}

const { matcher } = parseExpectCall(node);

if (
callee.type !== AST_NODE_TYPES.MemberExpression ||
callee.property.type !== AST_NODE_TYPES.Identifier ||
callee.property.name !== 'toMatchInlineSnapshot'
matcher?.name !== 'toMatchInlineSnapshot' ||
matcher?.arguments === null
) {
return;
}

// Check all since the optional 'propertyMatchers' argument might be present
nodeArguments.forEach(argument => {
matcher.arguments.forEach(argument => {
if (
argument.type === AST_NODE_TYPES.TemplateLiteral &&
argument.expressions.length > 0
Expand Down

0 comments on commit b6c50ec

Please sign in to comment.