From a8cb7889bc75c3bbdb33cac173202f5980f379bd Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 20 Sep 2022 15:35:32 +0800 Subject: [PATCH 1/3] Skip fixing when variable is JSX component --- rules/prevent-abbreviations.js | 8 +++++++- test/prevent-abbreviations.mjs | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js index e4bf84315d..a133dc5a22 100644 --- a/rules/prevent-abbreviations.js +++ b/rules/prevent-abbreviations.js @@ -215,7 +215,13 @@ const isExportedIdentifier = identifier => { return false; }; -const shouldFix = variable => !getVariableIdentifiers(variable).some(identifier => isExportedIdentifier(identifier)); +const shouldFix = variable => getVariableIdentifiers(variable) + .every(identifier => + !isExportedIdentifier(identifier) + // In typescript parser, only `JSXOpeningElement` is added to variable + // `` -> `` will cause parse error + && identifier.type !== 'JSXIdentifier' + ); const isDefaultOrNamespaceImportName = identifier => { if ( diff --git a/test/prevent-abbreviations.mjs b/test/prevent-abbreviations.mjs index 20d7c8df30..43ae09596f 100644 --- a/test/prevent-abbreviations.mjs +++ b/test/prevent-abbreviations.mjs @@ -1858,6 +1858,30 @@ test.typescript({ ], }); +// JSX +test.typescript({ + testerOptions: { + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + }, + valid: [], + invalid: [ + // `jsx` https://github.com/microsoft/fluentui/blob/ead191a8368bf64ecabffce5ea0e02565f449a95/packages/fluentui/docs/src/views/FocusTrapZoneDoc.tsx#L10 + { + code: outdent` + import DocPage from '../components/DocPage'; + export default () => ( + + ); + `, + errors: 1, + }, + ], +}); + // Filename test({ valid: [ From 36ef2c909323d369fb65ce4fa32cad79161c4245 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 20 Sep 2022 15:41:12 +0800 Subject: [PATCH 2/3] Fix comment --- test/prevent-abbreviations.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/prevent-abbreviations.mjs b/test/prevent-abbreviations.mjs index 43ae09596f..87ff815ad5 100644 --- a/test/prevent-abbreviations.mjs +++ b/test/prevent-abbreviations.mjs @@ -1869,7 +1869,7 @@ test.typescript({ }, valid: [], invalid: [ - // `jsx` https://github.com/microsoft/fluentui/blob/ead191a8368bf64ecabffce5ea0e02565f449a95/packages/fluentui/docs/src/views/FocusTrapZoneDoc.tsx#L10 + // https://github.com/microsoft/fluentui/blob/ead191a8368bf64ecabffce5ea0e02565f449a95/packages/fluentui/docs/src/views/FocusTrapZoneDoc.tsx#L10 { code: outdent` import DocPage from '../components/DocPage'; From d8db6d8574c9743af4d49579356c0880627f85f8 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 20 Sep 2022 15:45:07 +0800 Subject: [PATCH 3/3] Linting --- rules/prevent-abbreviations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/prevent-abbreviations.js b/rules/prevent-abbreviations.js index a133dc5a22..8328724c3f 100644 --- a/rules/prevent-abbreviations.js +++ b/rules/prevent-abbreviations.js @@ -220,7 +220,7 @@ const shouldFix = variable => getVariableIdentifiers(variable) !isExportedIdentifier(identifier) // In typescript parser, only `JSXOpeningElement` is added to variable // `` -> `` will cause parse error - && identifier.type !== 'JSXIdentifier' + && identifier.type !== 'JSXIdentifier', ); const isDefaultOrNamespaceImportName = identifier => {