From f75a2a2ec91c3896c88e7bb3baae0799bb49b5f2 Mon Sep 17 00:00:00 2001 From: Bryce Osterhaus Date: Mon, 1 Nov 2021 14:43:01 -0700 Subject: [PATCH 1/4] fix(eslint-plugin): fix bug in no-get-data-attribute rule --- .../lib/rules/no-get-data-attribute.js | 21 +++++++++++++++++-- .../tests/lib/rules/no-get-data-attribute.js | 12 +++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/projects/eslint-plugin/rules/general/lib/rules/no-get-data-attribute.js b/projects/eslint-plugin/rules/general/lib/rules/no-get-data-attribute.js index 38d9cd5c01..699ab7070a 100644 --- a/projects/eslint-plugin/rules/general/lib/rules/no-get-data-attribute.js +++ b/projects/eslint-plugin/rules/general/lib/rules/no-get-data-attribute.js @@ -5,6 +5,8 @@ module.exports = { create(context) { + const sourceCode = context.getSourceCode(); + return { CallExpression(node) { if ( @@ -21,16 +23,31 @@ module.exports = { const argumentName = argumentValue.replace('data-', ''); + const replacementString = argumentName.includes('-') + ? `['${argumentName}']` + : '.' + argumentName; context.report({ fix: (fixer) => { if (node.callee.object.type === 'Identifier') { return fixer.replaceText( node, - `${node.callee.object.name}.dataset.${argumentName}` + `${node.callee.object.name}.dataset${replacementString}` + ); + } + else if ( + node.callee.object.type === 'MemberExpression' + ) { + const memberExpressionString = sourceCode.getText( + node.callee.object + ); + + return fixer.replaceText( + node, + `${memberExpressionString}.dataset${replacementString}` ); } }, - message: `Use "dataset.${argumentName}" instead of "getAttribute('${argumentValue}')"`, + message: `Use "dataset${replacementString}" instead of "getAttribute('${argumentValue}')"`, node: node.callee.property, }); } diff --git a/projects/eslint-plugin/rules/general/tests/lib/rules/no-get-data-attribute.js b/projects/eslint-plugin/rules/general/tests/lib/rules/no-get-data-attribute.js index 12fb7b7997..d3094ed54a 100644 --- a/projects/eslint-plugin/rules/general/tests/lib/rules/no-get-data-attribute.js +++ b/projects/eslint-plugin/rules/general/tests/lib/rules/no-get-data-attribute.js @@ -21,6 +21,8 @@ ruleTester.run('no-get-data-attribute', rule, { code: ` el.querySelector('test').getAttribute('data-foo'); el.getAttribute('data-test'); + el.getAttribute('data-some-other-key'); + one.el.getAttribute('data-some-other-key'); `, errors: [ { @@ -32,10 +34,20 @@ ruleTester.run('no-get-data-attribute', rule, { message: `Use "dataset.test" instead of "getAttribute('data-test')"`, type: 'Identifier', }, + { + message: `Use "dataset['some-other-key']" instead of "getAttribute('data-some-other-key')"`, + type: 'Identifier', + }, + { + message: `Use "dataset['some-other-key']" instead of "getAttribute('data-some-other-key')"`, + type: 'Identifier', + }, ], output: ` el.querySelector('test').getAttribute('data-foo'); el.dataset.test; + el.dataset['some-other-key']; + one.el.dataset['some-other-key']; `, }, ], From 30e6c3660516755a52e40206d2dc63e9b5352304 Mon Sep 17 00:00:00 2001 From: Bryce Osterhaus Date: Tue, 2 Nov 2021 10:08:02 -0700 Subject: [PATCH 2/4] fix(eslint-plugin): fix bug in no-localhost-reference rule --- .../rules/portal/lib/rules/no-localhost-reference.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js b/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js index 6065b1f6a1..561f62cabd 100644 --- a/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js +++ b/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js @@ -25,8 +25,8 @@ module.exports = { if ( node && node.value && - typeof node.value.includes === 'function' && - node.value.includes('localhost') + typeof node.value === 'string' && + node.value.indexOf('localhost') !== -1 ) { context.report({ message: DESCRIPTION, From 17db227d9d6da7a96a724322e7bb3610192ebec8 Mon Sep 17 00:00:00 2001 From: Bryce Osterhaus Date: Thu, 4 Nov 2021 12:05:17 -0700 Subject: [PATCH 3/4] fix(eslint-plugin): don't test against dev directories for localhost rule --- .../rules/portal/lib/rules/no-localhost-reference.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js b/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js index 561f62cabd..9783819879 100644 --- a/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js +++ b/projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js @@ -13,9 +13,10 @@ module.exports = { const filename = path.basename(filePath); if ( - filename.includes('webpack') || filename.includes('jest') || - filePath.includes('test') + filePath.includes('dev') || + filePath.includes('test') || + filePath.includes('webpack') ) { return {}; } From 4e26e9e6c125d0ae40a98fd41899c5761ca14811 Mon Sep 17 00:00:00 2001 From: Bryce Osterhaus Date: Thu, 4 Nov 2021 12:05:37 -0700 Subject: [PATCH 4/4] feat(npm-scripts): lint against dev directories --- .../packages/npm-scripts/src/config/npmscripts.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/npm-tools/packages/npm-scripts/src/config/npmscripts.config.js b/projects/npm-tools/packages/npm-scripts/src/config/npmscripts.config.js index be29e4c62c..071c22675f 100644 --- a/projects/npm-tools/packages/npm-scripts/src/config/npmscripts.config.js +++ b/projects/npm-tools/packages/npm-scripts/src/config/npmscripts.config.js @@ -7,7 +7,7 @@ const path = require('path'); const CHECK_AND_FIX_GLOBS = [ '/*.{js,ts}', - '/{src,test}/**/*.{js,scss,ts,tsx}', + '/{dev,src,test}/**/*.{js,scss,ts,tsx}', '/src/**/*.{jsp,jspf}', ];