eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

Support CommonJS in Extensions

Open sedenardi opened this issue 5 years ago • 17 comments

This applies the same logic of the import/extensions rule to CommonJS-style require paths. Similar to the import/no-unresolved rule, it's enabled with a { commonjs: true } option so existing setups aren't disrupted.

I've added notes to the rule's docs, as well as 4 tests (in the style as similar tests for this rule). Please let me know if you have any questions/comments/concerns.

sedenardi avatar Apr 24 '19 03:04 sedenardi

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.902% when pulling e3752f53f5165ef05e01a2a9312f49cec359c753 on sedenardi:extensions-commonjs into f63dd261809de6883b13b6b5b960e6d7f42a7813 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

Coverage Status

Coverage increased (+2.5%) to 97.99% when pulling 771a85fc4dc03301fb85635c520a2fa3a1e0b10c on sedenardi:extensions-commonjs into 174afbbffa9127db1728dae544fc26afb94eaf28 on benmosher:master.

coveralls avatar Apr 24 '19 04:04 coveralls

haven't looked closely at code but I like the idea 👍

benmosher avatar Apr 24 '19 17:04 benmosher

Hey guys, no rush to get this reviewed and merged, just wanted to make sure you weren't waiting on anything on my end. Thanks again for all your help and feedback.

sedenardi avatar May 01 '19 20:05 sedenardi

Thanks for picking this up @sedenardi - this will be a big help within our team if this gets released 👍

alexnewmannn avatar May 08 '19 09:05 alexnewmannn

ideally everything that is acting on arbitrary imports/requires should go through moduleVisitor so we can centralize the detection. I'd also like to (if it doesn't already) allow setting es/common/amd settings globally for all rules which would make most sense to support from moduleVisitor vs. replicating everywhere.

sorry to hold this up! 😅

benmosher avatar May 23 '19 11:05 benmosher

@benmosher I've cutover rule to use moduleVisitor as you suggested. I've also remove all the Line/Column declarations from the error tests, as they've changed (due to the reported node when erroring). I feel this is safe because the test for the rule you gave as an example (no-unresolved) does not use Line/Column declarations for their error testing.

Thank you again for your time.

sedenardi avatar Jun 05 '19 16:06 sedenardi

Hi all, just bumping this PR to see if we can get someone to take a look at it again since I think I've satisfied all the requirements.

sedenardi avatar Aug 13 '19 22:08 sedenardi

@sedenardi it'd be great if you could rebase this on top of latest master

ljharb avatar May 14 '21 05:05 ljharb

@sedenardi it'd be great if you could rebase this on top of latest master

Apologies for the delayed reply. Feel free to close/reject this PR. To be honest, it's been too long since I've been familiar with the code to rebase 300+ commits over almost 2 years, and I no longer rely on this PR's feature in my projects.

sedenardi avatar Jun 28 '21 05:06 sedenardi