diff --git a/packages/eslint-plugin/src/rules/classes-constants.ts b/packages/eslint-plugin/src/rules/classes-constants.ts index 6935882f45..0d3c66cfa1 100644 --- a/packages/eslint-plugin/src/rules/classes-constants.ts +++ b/packages/eslint-plugin/src/rules/classes-constants.ts @@ -52,6 +52,13 @@ export const classesConstantsRule = createRule<[], MessageIds>({ }); function create(context: RuleContext, node: TSESTree.Literal | TSESTree.TemplateElement): void { + // We shouldn't lint on strings from imports/exports + if ( + node.parent?.type === AST_NODE_TYPES.ImportDeclaration || + node.parent?.type === AST_NODE_TYPES.ExportNamedDeclaration + ) { + return; + } const nodeValue = node.type === AST_NODE_TYPES.Literal ? node.raw : node.value.raw; const prefixMatches = getAllMatches(nodeValue); if (prefixMatches.length > 0) { diff --git a/packages/eslint-plugin/test/classes-constants.test.ts b/packages/eslint-plugin/test/classes-constants.test.ts index 5200ec3444..fefce49035 100644 --- a/packages/eslint-plugin/test/classes-constants.test.ts +++ b/packages/eslint-plugin/test/classes-constants.test.ts @@ -162,5 +162,9 @@ ruleTester.run("classes-constants", classesConstantsRule, { // it should not touch icons as theyre handled by a different rule '
', + + // don't flag strings in export/import statements + 'import { test } from "packagewithpt-thatshouldnterror";', + 'export { test } from "packagewithpt-thatshouldnterror";', ], });