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

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

coveralls 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.

src/rules/no-namespace.js Outdated Show resolved Hide resolved
@ljharb ljharb merged commit d030d8e into import-js:master Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants