Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";',
],
});