Skip to content

Commit e33b146

Browse files
Merge pull request #731 from bryceosterhaus/bugfixes
2 parents 47eaa75 + 4e26e9e commit e33b146

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

projects/eslint-plugin/rules/general/lib/rules/no-get-data-attribute.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
module.exports = {
77
create(context) {
8+
const sourceCode = context.getSourceCode();
9+
810
return {
911
CallExpression(node) {
1012
if (
@@ -21,16 +23,31 @@ module.exports = {
2123

2224
const argumentName = argumentValue.replace('data-', '');
2325

26+
const replacementString = argumentName.includes('-')
27+
? `['${argumentName}']`
28+
: '.' + argumentName;
2429
context.report({
2530
fix: (fixer) => {
2631
if (node.callee.object.type === 'Identifier') {
2732
return fixer.replaceText(
2833
node,
29-
`${node.callee.object.name}.dataset.${argumentName}`
34+
`${node.callee.object.name}.dataset${replacementString}`
35+
);
36+
}
37+
else if (
38+
node.callee.object.type === 'MemberExpression'
39+
) {
40+
const memberExpressionString = sourceCode.getText(
41+
node.callee.object
42+
);
43+
44+
return fixer.replaceText(
45+
node,
46+
`${memberExpressionString}.dataset${replacementString}`
3047
);
3148
}
3249
},
33-
message: `Use "dataset.${argumentName}" instead of "getAttribute('${argumentValue}')"`,
50+
message: `Use "dataset${replacementString}" instead of "getAttribute('${argumentValue}')"`,
3451
node: node.callee.property,
3552
});
3653
}

projects/eslint-plugin/rules/general/tests/lib/rules/no-get-data-attribute.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ ruleTester.run('no-get-data-attribute', rule, {
2121
code: `
2222
el.querySelector('test').getAttribute('data-foo');
2323
el.getAttribute('data-test');
24+
el.getAttribute('data-some-other-key');
25+
one.el.getAttribute('data-some-other-key');
2426
`,
2527
errors: [
2628
{
@@ -32,10 +34,20 @@ ruleTester.run('no-get-data-attribute', rule, {
3234
message: `Use "dataset.test" instead of "getAttribute('data-test')"`,
3335
type: 'Identifier',
3436
},
37+
{
38+
message: `Use "dataset['some-other-key']" instead of "getAttribute('data-some-other-key')"`,
39+
type: 'Identifier',
40+
},
41+
{
42+
message: `Use "dataset['some-other-key']" instead of "getAttribute('data-some-other-key')"`,
43+
type: 'Identifier',
44+
},
3545
],
3646
output: `
3747
el.querySelector('test').getAttribute('data-foo');
3848
el.dataset.test;
49+
el.dataset['some-other-key'];
50+
one.el.dataset['some-other-key'];
3951
`,
4052
},
4153
],

projects/eslint-plugin/rules/portal/lib/rules/no-localhost-reference.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ module.exports = {
1313
const filename = path.basename(filePath);
1414

1515
if (
16-
filename.includes('webpack') ||
1716
filename.includes('jest') ||
18-
filePath.includes('test')
17+
filePath.includes('dev') ||
18+
filePath.includes('test') ||
19+
filePath.includes('webpack')
1920
) {
2021
return {};
2122
}
@@ -25,8 +26,8 @@ module.exports = {
2526
if (
2627
node &&
2728
node.value &&
28-
typeof node.value.includes === 'function' &&
29-
node.value.includes('localhost')
29+
typeof node.value === 'string' &&
30+
node.value.indexOf('localhost') !== -1
3031
) {
3132
context.report({
3233
message: DESCRIPTION,

projects/npm-tools/packages/npm-scripts/src/config/npmscripts.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const path = require('path');
77

88
const CHECK_AND_FIX_GLOBS = [
99
'/*.{js,ts}',
10-
'/{src,test}/**/*.{js,scss,ts,tsx}',
10+
'/{dev,src,test}/**/*.{js,scss,ts,tsx}',
1111
'/src/**/*.{jsp,jspf}',
1212
];
1313

0 commit comments

Comments
 (0)