From 5c4a5d5e56c5792c8517f1a3d9376566869a36e9 Mon Sep 17 00:00:00 2001 From: maddhruv Date: Tue, 18 Feb 2020 09:28:40 +0530 Subject: [PATCH 1/3] fix/require-data-selectors-support-TemplateLiteral --- lib/rules/require-data-selectors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/require-data-selectors.js b/lib/rules/require-data-selectors.js index b8d5203e..1257c296 100644 --- a/lib/rules/require-data-selectors.js +++ b/lib/rules/require-data-selectors.js @@ -39,7 +39,7 @@ function isCallingCyGet (node) { function isDataArgument (node) { return node.arguments.length > 0 && - node.arguments[0].type === 'Literal' && + (node.arguments[0].type === 'Literal' || node.arguments[0].type === 'TemplateLiteral') && String(node.arguments[0].value).startsWith('[data-') } From 09aa5418f59c3674d431f739bde8142ba2dcdfc5 Mon Sep 17 00:00:00 2001 From: maddhruv Date: Tue, 18 Feb 2020 09:47:24 +0530 Subject: [PATCH 2/3] test: add test and fix the rule --- lib/rules/require-data-selectors.js | 6 +++--- tests/lib/rules/require-data-selectors.js | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rules/require-data-selectors.js b/lib/rules/require-data-selectors.js index 1257c296..462dde47 100644 --- a/lib/rules/require-data-selectors.js +++ b/lib/rules/require-data-selectors.js @@ -39,7 +39,7 @@ function isCallingCyGet (node) { function isDataArgument (node) { return node.arguments.length > 0 && - (node.arguments[0].type === 'Literal' || node.arguments[0].type === 'TemplateLiteral') && - String(node.arguments[0].value).startsWith('[data-') - + ((node.arguments[0].type === 'Literal' && String(node.arguments[0].value).startsWith('[data-')) || + (node.arguments[0].type === 'TemplateLiteral' && String(node.arguments[0].quasis[0].value.cooked).startsWith('[data-')) + ) } diff --git a/tests/lib/rules/require-data-selectors.js b/tests/lib/rules/require-data-selectors.js index af123dc9..92036bb0 100644 --- a/tests/lib/rules/require-data-selectors.js +++ b/tests/lib/rules/require-data-selectors.js @@ -15,6 +15,7 @@ ruleTester.run('require-data-selectors', rule, { { code: 'cy.clock(5000)', parserOptions }, { code: 'cy.scrollTo(0, 10)', parserOptions }, { code: 'cy.tick(500)', parserOptions }, + { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions }, ], invalid: [ @@ -23,5 +24,6 @@ ruleTester.run('require-data-selectors', rule, { { code: 'cy.get(".btn-large").click()', parserOptions, errors }, { code: 'cy.get(".btn-.large").click()', parserOptions, errors }, { code: 'cy.get(".a")', parserOptions, errors }, + { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors }, ], }) From 550f377c91eb728b755b0277b1d8c1662476efd6 Mon Sep 17 00:00:00 2001 From: maddhruv Date: Tue, 18 Feb 2020 09:52:06 +0530 Subject: [PATCH 3/3] chore: prettify --- lib/rules/require-data-selectors.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rules/require-data-selectors.js b/lib/rules/require-data-selectors.js index 462dde47..f3f76afb 100644 --- a/lib/rules/require-data-selectors.js +++ b/lib/rules/require-data-selectors.js @@ -39,7 +39,8 @@ function isCallingCyGet (node) { function isDataArgument (node) { return node.arguments.length > 0 && - ((node.arguments[0].type === 'Literal' && String(node.arguments[0].value).startsWith('[data-')) || - (node.arguments[0].type === 'TemplateLiteral' && String(node.arguments[0].quasis[0].value.cooked).startsWith('[data-')) + ( + (node.arguments[0].type === 'Literal' && String(node.arguments[0].value).startsWith('[data-')) || + (node.arguments[0].type === 'TemplateLiteral' && String(node.arguments[0].quasis[0].value.cooked).startsWith('[data-')) ) }