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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make no-namespace rule fixable #1401

Merged
merged 1 commit into from Oct 9, 2019

Conversation

@TrevorBurnham
Copy link
Contributor

commented Jun 29, 2019

This PR adds support for --fix to the no-namespace rule, in the case where all references to the namespace can be statically resolved:

Input

import * as foo from 'foo';
florp(foo.bar);
florp(foo.baz);

Output

import { bar, baz } from 'foo';
florp(bar);
florp(baz);

The motivation for this is to make it easier to opt in to no-namespace in codebases that are already using this pattern. It sure beats having to do it all by hand! 馃槃

Note that this will only work under ESLint 5+, as older versions don't allow for traversing upward from variable references. That is, in this code identifier.parent is undefined. I haven't been able to figure out a good way to support this under ESLint 4 (let me know if you have any ideas!), so I've added a note for this in the rule's documentation.

 - Add guards to avoid crashing older versions of ESLint
 - Note that no-namespace's --fix requires ESLint 5+
 - Prevent no-namespace --fix tests from running under ESLint < 5
@coveralls

This comment has been minimized.

Copy link

commented Jun 29, 2019

Coverage Status

Coverage decreased (-0.1%) to 96.319% when pulling d030d8e on TrevorBurnham:no-namespace-autofix into 3704801 on benmosher:master.

@ljharb ljharb force-pushed the TrevorBurnham:no-namespace-autofix branch from 5743a13 to 15675e7 Aug 19, 2019
src/rules/no-namespace.js Outdated Show resolved Hide resolved
@ljharb ljharb added the semver-minor label Aug 19, 2019
@ljharb
ljharb approved these changes Oct 8, 2019
@ljharb ljharb force-pushed the TrevorBurnham:no-namespace-autofix branch from cdff101 to d030d8e Oct 8, 2019
@ljharb ljharb merged commit d030d8e into benmosher:master Oct 9, 2019
2 of 3 checks passed
2 of 3 checks passed
coverage/coveralls Coverage decreased (-0.2%) to 96.205%
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can鈥檛 perform that action at this time.