Skip to content

Commit ed2812f

Browse files
authored
typography-deprecation - JSX should use short version (no Typography prefix) - fix (#810)
1 parent 575ecd7 commit ed2812f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

eslint-rules/lib/rules/typography-deprecation.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
schema: [MAP_SCHEMA],
2121
},
2222
create(context) {
23-
function reportDeprecatedTypography(node, options) {
23+
function reportDeprecatedTypography(node, options, useShortVersion) {
2424
try {
2525
const {dueDate} = context.options[0];
2626
const dueDateNotice = dueDate ? ` Please fix this issue by ${dueDate}!` : '';
@@ -30,7 +30,8 @@ module.exports = {
3030
message: `${msg}`,
3131
fix(fixer) {
3232
if (options.fix) {
33-
return fixer.replaceText(node, options.fix);
33+
const fix = useShortVersion ? options.fix.substr(`${defaultImportName}.`.length) : options.fix;
34+
return fixer.replaceText(node, fix);
3435
}
3536
},
3637
});
@@ -47,23 +48,23 @@ module.exports = {
4748
localImportSpecifier = utils.getLocalImportSpecifier(node, source, defaultImportName);
4849
}
4950

50-
function findAndReportDeprecation(node, possibleDeprecation) {
51+
function findAndReportDeprecation(node, possibleDeprecation, useShortVersion) {
5152
const path = `${defaultImportName}.${possibleDeprecation}`;
5253
const foundDeprecation = _.find(deprecations, {path});
5354
if (foundDeprecation) {
54-
reportDeprecatedTypography(node, foundDeprecation);
55+
reportDeprecatedTypography(node, foundDeprecation, useShortVersion);
5556
}
5657
}
5758

5859
function testMemberDeprecation(node) {
5960
if (node && node.object && node.property && node.object.name === localImportSpecifier) {
60-
findAndReportDeprecation(node, node.property.name);
61+
findAndReportDeprecation(node, node.property.name, false);
6162
}
6263
}
6364

6465
function testJSXAttribute(node) {
6566
if (node && node.name) {
66-
findAndReportDeprecation(node, node.name.name);
67+
findAndReportDeprecation(node, node.name.name, true);
6768
}
6869
}
6970

0 commit comments

Comments
 (0)