| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | module.exports = { |
| 9 | meta: { |
| 10 | type: 'problem', |
| 11 | docs: { |
| 12 | description: 'disallow default import of stylex', |
| 13 | }, |
| 14 | fixable: 'code', // This indicates that the rule is fixable |
| 15 | messages: { |
| 16 | noDefaultStylexImport: |
| 17 | "Use `import * as stylex from '@stylexjs/stylex'` instead of default import to avoid test breakages.", |
| 18 | }, |
| 19 | schema: [], // no options |
| 20 | }, |
| 21 | create(context) { |
| 22 | return { |
| 23 | ImportDeclaration(node) { |
| 24 | if ( |
| 25 | node.source.value === '@stylexjs/stylex' && |
| 26 | node.specifiers.some(specifier => specifier.type === 'ImportDefaultSpecifier') |
| 27 | ) { |
| 28 | context.report({ |
| 29 | node, |
| 30 | messageId: 'noDefaultStylexImport', |
| 31 | fix(fixer) { |
| 32 | // Construct the correct import statement |
| 33 | const importStatement = `import * as stylex from '@stylexjs/stylex';`; |
| 34 | return fixer.replaceText(node, importStatement); |
| 35 | }, |
| 36 | }); |
| 37 | } |
| 38 | }, |
| 39 | }; |
| 40 | }, |
| 41 | }; |
| 42 | |