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