Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add match-default-export-name rule #2117

Merged
merged 4 commits into from
Jan 29, 2017

Conversation

andy-hanson
Copy link
Contributor

PR checklist

  • Addresses an existing issue: #0000
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update

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 = and export =, since export = 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.

@adidahiya
Copy link
Contributor

very cool! this programming error was one of my main motivations for the no-default-export rule.

@@ -0,0 +1,3 @@
import b from "./named";
~ [Default export 'a' is imported as 'b'.]
import anyName from "./anonymous";
Copy link
Contributor

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

Copy link
Contributor Author

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}'.`;
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

use TypedRule and applyWithProgram

@nchen63 nchen63 merged commit 22e0fd3 into palantir:master Jan 29, 2017
@nchen63
Copy link
Contributor

nchen63 commented Jan 29, 2017

@andy-hanson thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants