|
1 |
| -import { MutRef, O, P } from "@eslint-react/tools"; |
2 |
| -import type { TSESTree } from "@typescript-eslint/types"; |
| 1 | +import { MutRef, P } from "@eslint-react/tools"; |
3 | 2 | import type { ESLintUtils } from "@typescript-eslint/utils";
|
4 | 3 | import type { JSONSchema4 } from "@typescript-eslint/utils/json-schema";
|
5 | 4 |
|
@@ -66,30 +65,34 @@ export default createRule<Options, MessageID>({
|
66 | 65 | const cond = P.isString(options) ? options : options.rule ?? "as-needed";
|
67 | 66 |
|
68 | 67 | const filename = context.getFilename();
|
69 |
| - const jsxNodeRef = MutRef.make<O.Option<TSESTree.JSXElement | TSESTree.JSXFragment>>(O.none()); |
| 68 | + const hasJSXNodeRef = MutRef.make<boolean>(false); |
70 | 69 |
|
71 | 70 | return {
|
72 |
| - JSXElement(node) { |
73 |
| - MutRef.set(jsxNodeRef, O.some(node)); |
| 71 | + JSXElement() { |
| 72 | + MutRef.set(hasJSXNodeRef, true); |
74 | 73 | },
|
75 |
| - JSXFragment(node) { |
76 |
| - MutRef.set(jsxNodeRef, O.some(node)); |
| 74 | + JSXFragment() { |
| 75 | + MutRef.set(hasJSXNodeRef, true); |
77 | 76 | },
|
78 | 77 | "Program:exit"(node) {
|
79 | 78 | const fileNameExt = filename.slice(filename.lastIndexOf("."));
|
| 79 | + const isJSX = isJSXFile(fileNameExt); |
| 80 | + const hasJSXCode = MutRef.get(hasJSXNodeRef); |
80 | 81 |
|
81 |
| - if (O.isSome(MutRef.get(jsxNodeRef))) { |
82 |
| - if (!isJSXFile(fileNameExt)) { |
83 |
| - context.report({ |
84 |
| - messageId: "FILE_NAME_EXTENSION_INVALID", |
85 |
| - node, |
86 |
| - }); |
87 |
| - } |
| 82 | + if (!isJSX && hasJSXCode) { |
| 83 | + context.report({ |
| 84 | + messageId: "FILE_NAME_EXTENSION_INVALID", |
| 85 | + node, |
| 86 | + }); |
88 | 87 |
|
89 | 88 | return;
|
90 | 89 | }
|
91 | 90 |
|
92 |
| - if (cond === "as-needed" && isJSXFile(fileNameExt)) { |
| 91 | + if ( |
| 92 | + isJSX |
| 93 | + && !hasJSXCode |
| 94 | + && cond === "as-needed" |
| 95 | + ) { |
93 | 96 | context.report({
|
94 | 97 | messageId: "FILE_NAME_EXTENSION_UNEXPECTED",
|
95 | 98 | node,
|
|
0 commit comments