addons/eslint-rules/stylex-import.jsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318module.exports = {
b69ab319 meta: {
b69ab3110 type: 'problem',
b69ab3111 docs: {
b69ab3112 description: 'disallow default import of stylex',
b69ab3113 },
b69ab3114 fixable: 'code', // This indicates that the rule is fixable
b69ab3115 messages: {
b69ab3116 noDefaultStylexImport:
b69ab3117 "Use `import * as stylex from '@stylexjs/stylex'` instead of default import to avoid test breakages.",
b69ab3118 },
b69ab3119 schema: [], // no options
b69ab3120 },
b69ab3121 create(context) {
b69ab3122 return {
b69ab3123 ImportDeclaration(node) {
b69ab3124 if (
b69ab3125 node.source.value === '@stylexjs/stylex' &&
b69ab3126 node.specifiers.some(specifier => specifier.type === 'ImportDefaultSpecifier')
b69ab3127 ) {
b69ab3128 context.report({
b69ab3129 node,
b69ab3130 messageId: 'noDefaultStylexImport',
b69ab3131 fix(fixer) {
b69ab3132 // Construct the correct import statement
b69ab3133 const importStatement = `import * as stylex from '@stylexjs/stylex';`;
b69ab3134 return fixer.replaceText(node, importStatement);
b69ab3135 },
b69ab3136 });
b69ab3137 }
b69ab3138 },
b69ab3139 };
b69ab3140 },
b69ab3141};