Skip to content

Commit

Permalink
[eslint-plugin] fix(classes-constants): ignore imports/exports (#5076)
Browse files Browse the repository at this point in the history
  • Loading branch information
styu committed Jan 4, 2022
1 parent e0dd35e commit 8403bf2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/eslint-plugin/src/rules/classes-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export const classesConstantsRule = createRule<[], MessageIds>({
});

function create(context: RuleContext<MessageIds, []>, 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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/test/classes-constants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,9 @@ ruleTester.run("classes-constants", classesConstantsRule, {

// it should not touch icons as theyre handled by a different rule
'<div className="pt-icon-folder-open" />',

// don't flag strings in export/import statements
'import { test } from "packagewithpt-thatshouldnterror";',
'export { test } from "packagewithpt-thatshouldnterror";',
],
});

1 comment on commit 8403bf2

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[eslint-plugin] fix(classes-constants): ignore imports/exports (#5076)

Previews: documentation | landing | table | modern colors demo

Please sign in to comment.