From 8403bf29bd137f4cb263443dfe0e94774bc5edeb Mon Sep 17 00:00:00 2001 From: styu Date: Tue, 4 Jan 2022 10:39:26 -0600 Subject: [PATCH] [eslint-plugin] fix(classes-constants): ignore imports/exports (#5076) --- packages/eslint-plugin/src/rules/classes-constants.ts | 7 +++++++ packages/eslint-plugin/test/classes-constants.test.ts | 4 ++++ 2 files changed, 11 insertions(+) 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";', ], });