Skip to content

Commit

Permalink
prevent-abbreviations: Skip fix when variable is JSX component (#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 20, 2022
1 parent 690ed8c commit 9ed08ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rules/prevent-abbreviations.js
Expand Up @@ -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
// `<foo></foo>` -> `<bar></foo>` will cause parse error
&& identifier.type !== 'JSXIdentifier',
);

const isDefaultOrNamespaceImportName = identifier => {
if (
Expand Down
24 changes: 24 additions & 0 deletions test/prevent-abbreviations.mjs
Expand Up @@ -1858,6 +1858,30 @@ test.typescript({
],
});

// JSX
test.typescript({
testerOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
valid: [],
invalid: [
// https://github.com/microsoft/fluentui/blob/ead191a8368bf64ecabffce5ea0e02565f449a95/packages/fluentui/docs/src/views/FocusTrapZoneDoc.tsx#L10
{
code: outdent`
import DocPage from '../components/DocPage';
export default () => (
<DocPage title="Focus Trap Zone"></DocPage>
);
`,
errors: 1,
},
],
});

// Filename
test({
valid: [
Expand Down

0 comments on commit 9ed08ab

Please sign in to comment.