Skip to content

Commit 9929da0

Browse files
committed
Refactor createFix function to only create a fix if allowedImportStyles has 'namespace' and does not have 'named'.
1 parent 0898f85 commit 9929da0

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

rules/import-style.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,9 @@ const getNamespaceIdentifier = moduleName => {
175175
@param {import('estree').Node} options.node - The AST node representing the import/require statement.
176176
@param {import('eslint').SourceCode} options.sourceCode - The ESLint source code object.
177177
@param {string} options.moduleName - The name of the module being imported.
178-
@param {Set<string>} options.allowedImportStyles - Set of allowed import styles for the module.
179178
@returns {(fixer: import('eslint').Rule.RuleFixer) => Array<import('eslint').Rule.Fix>|void} A function that takes a fixer and returns an array of fixes or void.
180179
*/
181-
const createFix = ({node, sourceCode, moduleName, allowedImportStyles}) => fixer => {
182-
if (!allowedImportStyles.has('namespace') || allowedImportStyles.has('named')) {
183-
return;
184-
}
185-
180+
const createFix = ({node, sourceCode, moduleName}) => fixer => {
186181
const isImportDeclaration = node.type === 'ImportDeclaration';
187182
const isVariableDeclarator = node.type === 'VariableDeclarator';
188183
const isRequireCall = isCallExpression(node.init, {name: 'require'});
@@ -351,9 +346,11 @@ const create = context => {
351346
node,
352347
messageId: MESSAGE_ID,
353348
data,
354-
fix: createFix({
355-
node, sourceCode, moduleName, allowedImportStyles,
356-
}),
349+
fix: allowedImportStyles.has('namespace') && !allowedImportStyles.has('named')
350+
? createFix({
351+
node, sourceCode, moduleName, allowedImportStyles,
352+
})
353+
: undefined,
357354
});
358355
};
359356

0 commit comments

Comments
 (0)