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

New: Add no-restricted-exports rule (fixes #10428) #12546

Merged
merged 3 commits into from Dec 23, 2019

Conversation

mdjermanovic
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] New rule #10428

Examples of incorrect code for this rule:

/*eslint no-restricted-exports: ["error", ["foo", "bar", "Baz", "a", "b", "c", "d"]]*/

export const foo = 1;

export function bar() {}

export class Baz {}

const a = {};
export { a };

function someFunction() {}
export { someFunction as b };

export { c } from 'some_module';

export { something as d } from 'some_module';

What changes did you make? (Give an overview)

New rule no-restricted-exports

Is there anything you'd like reviewers to focus on?

  • configuration

Configuration is ["error", ["foo", "bar"]] instead of ["error", "foo", "bar"]

This might be a better choice as it's clear that "error" isn't a restricted name, but it's different from other similar rules. Is it okay? There was a discussion about this in #11331.

  • custom messages

This wasn't mentioned in the issue thread, should the rule support custom messages for configured restricted names?

  • reported nodes

The rule always reports Identifier nodes, rather than the declaration nodes (because a declaration can export more names, including the valid ones).

  • export default

Configured "default" doesn't disallow export default (although it does export "default" name). Is it okay? There is a section in the documentation about this.

  • export * from 'some_module'

This can export restricted names, but it's out of scope for this rule and noted in the Known Limitations section.

  • documentation

I'm not sure what to note as a typical use case in the very first section (maybe nothing?).

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Nov 8, 2019
@mdjermanovic mdjermanovic added accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Nov 8, 2019
@ilyavolodin
Copy link
Member

The code looks fine, and I think all of the assumptions are valid. However, I notice more and more people do not want to use default exports, because named exports are a lot more descriptive. It would be nice to add an option to this rule to disallow default exports. But that could be done in a separate PR, I guess.

@mdjermanovic
Copy link
Member Author

👍 to add the option in a separate PR.

Though, it might be good to already think about how the option fits the current design.

["error", ["default"]] disallows export { foo as default }, but allows export default foo. That's already implemented in this PR.

The new boolean option would disallow just export default syntax, but allow default exports via named export declarations?

For instance, ["error", [""], { disallowExportDefault: true }] disallows export default foo, but allows export { foo as default }.

["error", ["default"], { disallowExportDefault: true }] disallows any forms of default exports.

@kaicataldo
Copy link
Member

While ["error", ["default"], { disallowExportDefault: true }] makes sense given what the rule does, it certainly is verbose and I do worry that it would be confusing to a new user.

Alternatively, could we replace the first configuration option with an object and do something like the following?

["error", { 
  restrictedExports: ["default"],
  disallowExportDefault: true
}]

@mdjermanovic
Copy link
Member Author

Alternatively, could we replace the first configuration option with an object and do something like the following?

["error", { 
  restrictedExports: ["default"],
  disallowExportDefault: true
}]

This looks better to me!

Maybe restrictedNamedExports to make it more clear that it doesn't affect export default?

Given that is seems (based on votes) that the new option will be added at some point, I'm 👍 to change the initial configuration now.

@ilyavolodin would you agree with this change? (asking because you already approved the current version)

@kaicataldo
Copy link
Member

Maybe restrictedNamedExports to make it more clear that it doesn't affect export default?

Sounds good to me 👍

@mdjermanovic
Copy link
Member Author

Configuration is now changed from ["error", ["foo", "bar"]] to:

["error", { restrictedNamedExports: ["foo", "bar"] }]

(if that isn't okay, I'll revert the change)

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the comprehensive test suite.

@kaicataldo kaicataldo merged commit 985dac3 into master Dec 23, 2019
@kaicataldo kaicataldo deleted the no-restricted-exports branch December 23, 2019 20:53
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 22, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants