Skip to content

Commit d8002be

Browse files
benasher44ljharb
authored andcommitted
[Fix] extensions: handle . and .. properly
1 parent f302f7d commit d8002be

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1212
- [Perf] `ExportMap`: Improve `ExportMap.for` performance on larger codebases ([#2756], thanks [@leipert])
1313
- [`no-extraneous-dependencies`]/TypeScript: do not error when importing inline type from dev dependencies ([#1820], thanks [@andyogo])
1414
- [`newline-after-import`]/TypeScript: do not error when re-exporting a namespaced import ([#2832], thanks [@laurens-dg])
15-
* [`order`]: partial fix for [#2687] (thanks [@ljharb])
15+
- [`order`]: partial fix for [#2687] (thanks [@ljharb])
1616
- [`no-duplicates`]: Detect across type and regular imports ([#2835], thanks [@benkrejci])
17+
- [`extensions`]: handle `.` and `..` properly ([#2778], thanks [@benasher44])
1718

1819
### Changed
1920
- [Docs] [`no-duplicates`]: fix example schema ([#2684], thanks [@simmo])
@@ -1076,6 +1077,7 @@ for info on changes for earlier releases.
10761077

10771078
[#2835]: https://github.com/import-js/eslint-plugin-import/pull/2835
10781079
[#2832]: https://github.com/import-js/eslint-plugin-import/pull/2832
1080+
[#2778]: https://github.com/import-js/eslint-plugin-import/pull/2778
10791081
[#2756]: https://github.com/import-js/eslint-plugin-import/pull/2756
10801082
[#2754]: https://github.com/import-js/eslint-plugin-import/pull/2754
10811083
[#2748]: https://github.com/import-js/eslint-plugin-import/pull/2748
@@ -1649,6 +1651,7 @@ for info on changes for earlier releases.
16491651
[@BarryThePenguin]: https://github.com/BarryThePenguin
16501652
[@be5invis]: https://github.com/be5invis
16511653
[@beatrizrezener]: https://github.com/beatrizrezener
1654+
[@benasher44]: https://github.com/benasher44
16521655
[@benkrejci]: https://github.com/benkrejci
16531656
[@benmosher]: https://github.com/benmosher
16541657
[@benmunro]: https://github.com/benmunro

src/rules/extensions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ module.exports = {
130130
}
131131

132132
function isExternalRootModule(file) {
133+
if (file === '.' || file === '..') { return false; }
133134
const slashCount = file.split('/').length - 1;
134135

135136
if (slashCount === 0) { return true; }

tests/files/internal-modules/test.js

Whitespace-only changes.

tests/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './files';

tests/src/rules/extensions.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,26 @@ ruleTester.run('extensions', rule, {
266266
],
267267
}),
268268

269+
test({
270+
code: [
271+
'import barjs from "."',
272+
'import barjs2 from ".."',
273+
].join('\n'),
274+
options: [ 'always' ],
275+
errors: [
276+
{
277+
message: 'Missing file extension "js" for "."',
278+
line: 1,
279+
column: 19,
280+
},
281+
{
282+
message: 'Missing file extension "js" for ".."',
283+
line: 2,
284+
column: 20,
285+
},
286+
],
287+
}),
288+
269289
test({
270290
code: [
271291
'import barjs from "./bar.js"',
@@ -594,6 +614,35 @@ ruleTester.run('extensions', rule, {
594614
},
595615
],
596616
}),
617+
618+
// TODO: properly ignore packages resolved via relative imports
619+
test({
620+
code: [
621+
'import * as test from "."',
622+
].join('\n'),
623+
filename: testFilePath('./internal-modules/test.js'),
624+
options: [ 'ignorePackages' ],
625+
errors: [
626+
{
627+
message: 'Missing file extension for "."',
628+
line: 1,
629+
},
630+
],
631+
}),
632+
// TODO: properly ignore packages resolved via relative imports
633+
test({
634+
code: [
635+
'import * as test from ".."',
636+
].join('\n'),
637+
filename: testFilePath('./internal-modules/plugins/plugin.js'),
638+
options: [ 'ignorePackages' ],
639+
errors: [
640+
{
641+
message: 'Missing file extension for ".."',
642+
line: 1,
643+
},
644+
],
645+
}),
597646
],
598647
});
599648

0 commit comments

Comments
 (0)