Skip to content

Commit 3711e35

Browse files
fix-eslint-plugin (#2994)
* fix issues with string template scenarios. ensure plugin works with modern versions of eslint. add missing test scenarios. * run lint:fix Co-authored-by: Stephen James <sjames@salesforce.com>
1 parent 11c29ab commit 3711e35

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

eslint-plugin/lib/rules/no-double-dash-modifier.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
const getFixer = (node, getValue, getFixRange) => (fixer) => {
4040
const nodeText = getValue(node);
4141
const fixedText = nodeText.replace(SLDS_DEPRECATED_CSS_SYNTAX, '$1_$2');
42-
const range = getFixRange(node);
42+
const range = getFixRange(node.range);
4343
return fixer.replaceTextRange(range, fixedText);
4444
};
4545

@@ -74,14 +74,15 @@ module.exports = {
7474
checkNode(
7575
node,
7676
(stringNode) => stringNode.value,
77-
({ start, end }) => [start + 1, end - 1]
77+
([start, end]) => [start + 1, end - 1]
7878
);
7979
},
8080
TemplateElement(node) {
8181
checkNode(
8282
node,
8383
(quasi) => quasi.value.raw,
84-
({ start, end }) => [start, end]
84+
([start, end]) =>
85+
node.tail ? [start + 1, end - 1] : [start + 1, end - 2]
8586
);
8687
},
8788
};

eslint-plugin/tests/lib/rules/no-double-dash-modifier.js

+26
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,32 @@ ruleTester.run('no-double-dash-modifier', rule, {
132132
],
133133
parserOptions,
134134
},
135+
{
136+
code: '<div className={`${otherclasses}slds-dropdown--${position}`}/>',
137+
output: '<div className={`${otherclasses}slds-dropdown_${position}`}/>',
138+
errors: [
139+
{
140+
message:
141+
'SLDS modifier CSS classes should use a single ' +
142+
'underscore instead of double-hyphen: ' +
143+
'"slds-dropdown--".',
144+
},
145+
],
146+
parserOptions,
147+
},
148+
{
149+
code: '{[`${otherClases}slds-button__icon--large`]}',
150+
output: '{[`${otherClases}slds-button__icon_large`]}',
151+
errors: [
152+
{
153+
message:
154+
'SLDS modifier CSS classes should use a single ' +
155+
'underscore instead of double-hyphen: ' +
156+
'"slds-button__icon--large".',
157+
},
158+
],
159+
parserOptions,
160+
},
135161
],
136162
/* eslint-enable no-template-curly-in-string */
137163
});

0 commit comments

Comments
 (0)