-
Notifications
You must be signed in to change notification settings - Fork 889
Add match-default-export-name
rule
#2117
Add match-default-export-name
rule
#2117
Conversation
very cool! this programming error was one of my main motivations for the no-default-export rule. |
…h_default_export_name
@@ -0,0 +1,3 @@ | |||
import b from "./named"; | |||
~ [Default export 'a' is imported as 'b'.] | |||
import anyName from "./anonymous"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test for import a as b
. Users look at tests to understand how the rule works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not legal syntax anyway.
/* tslint:enable:object-literal-sort-keys */ | ||
|
||
public static FAILURE_STRING(importName: string, exportName: string): string { | ||
return `Default export '${exportName}' is imported as '${importName}'.`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer something that indicates how to resolve the issue like Expected import '${importName}' to match the default export '${exportName}'
|
||
import * as Lint from "../index"; | ||
|
||
export class Rule extends Lint.Rules.AbstractRule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use TypedRule
and applyWithProgram
@andy-hanson thanks! |
PR checklist
What changes did you make?
Added the
match-default-export-name
rule, which requires that default imports have the same name as the default exports they reference.This doesn't check named exports, since they require explicit
import { foo as bar }
and are unlikely to be name-changed by mistake.This also doesn't check
import =
andexport =
, sinceexport =
comes from declaration files which probably don't use the name you want, and if it's an@types
module you can't simply change it.