Skip to content

Commit 9ed08ab

Browse files
authored
prevent-abbreviations: Skip fix when variable is JSX component (#1907)
1 parent 690ed8c commit 9ed08ab

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

rules/prevent-abbreviations.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ const isExportedIdentifier = identifier => {
215215
return false;
216216
};
217217

218-
const shouldFix = variable => !getVariableIdentifiers(variable).some(identifier => isExportedIdentifier(identifier));
218+
const shouldFix = variable => getVariableIdentifiers(variable)
219+
.every(identifier =>
220+
!isExportedIdentifier(identifier)
221+
// In typescript parser, only `JSXOpeningElement` is added to variable
222+
// `<foo></foo>` -> `<bar></foo>` will cause parse error
223+
&& identifier.type !== 'JSXIdentifier',
224+
);
219225

220226
const isDefaultOrNamespaceImportName = identifier => {
221227
if (

test/prevent-abbreviations.mjs

+24
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,30 @@ test.typescript({
18581858
],
18591859
});
18601860

1861+
// JSX
1862+
test.typescript({
1863+
testerOptions: {
1864+
parserOptions: {
1865+
ecmaFeatures: {
1866+
jsx: true,
1867+
},
1868+
},
1869+
},
1870+
valid: [],
1871+
invalid: [
1872+
// https://github.com/microsoft/fluentui/blob/ead191a8368bf64ecabffce5ea0e02565f449a95/packages/fluentui/docs/src/views/FocusTrapZoneDoc.tsx#L10
1873+
{
1874+
code: outdent`
1875+
import DocPage from '../components/DocPage';
1876+
export default () => (
1877+
<DocPage title="Focus Trap Zone"></DocPage>
1878+
);
1879+
`,
1880+
errors: 1,
1881+
},
1882+
],
1883+
});
1884+
18611885
// Filename
18621886
test({
18631887
valid: [

0 commit comments

Comments
 (0)