Skip to content

Commit 00d7bc8

Browse files
Rafael Perelloljharb
Rafael Perello
authored andcommittedJul 6, 2021
[Fix] extensions/importType: fix isScoped treating @/abc as scoped module
Fixes #2145
1 parent b236748 commit 00d7bc8

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed
 

‎CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1010
- [`no-duplicates`]: ensure autofix avoids excessive newlines ([#2028], thanks [@ertrzyiks])
1111
- [`extensions`]: avoid crashing on partially typed import/export statements ([#2118], thanks [@ljharb])
1212
- [`no-extraneous-dependencies`]: add ESM intermediate package.json support] ([#2121], thanks [@paztis])
13-
- Use `context.getPhysicalFilename()` when available (ESLint 7.28+) ([#2160], thanks [@pmcelhaney])
13+
- Use `context.getPhysicalFilename()` when available (ESLint 7.28+) ([#2160], thanks [@pmcelhaney])
14+
- [`extensions`]/`importType`: fix isScoped treating @/abc as scoped module ([#2146], thanks [@rperello])
1415

1516
### Changed
1617
- [Docs] `extensions`: removed incorrect cases ([#2138], thanks [@wenfangdu])
@@ -814,6 +815,7 @@ for info on changes for earlier releases.
814815
[#2160]: https://github.com/benmosher/eslint-plugin-import/pull/2160
815816
[#2158]: https://github.com/benmosher/eslint-plugin-import/pull/2158
816817
[#2156]: https://github.com/benmosher/eslint-plugin-import/pull/2156
818+
[#2146]: https://github.com/benmosher/eslint-plugin-import/pull/2146
817819
[#2138]: https://github.com/benmosher/eslint-plugin-import/pull/2138
818820
[#2121]: https://github.com/benmosher/eslint-plugin-import/pull/2121
819821
[#2099]: https://github.com/benmosher/eslint-plugin-import/pull/2099
@@ -1391,6 +1393,7 @@ for info on changes for earlier releases.
13911393
[@richardxia]: https://github.com/richardxia
13921394
[@robertrossmann]: https://github.com/robertrossmann
13931395
[@rosswarren]: https://github.com/rosswarren
1396+
[@rperello]: https://github.com/rperello
13941397
[@rsolomon]: https://github.com/rsolomon
13951398
[@s-h-a-d-o-w]: https://github.com/s-h-a-d-o-w
13961399
[@saschanaz]: https://github.com/saschanaz

‎src/core/importType.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function isModuleMain(name) {
6464
return name && moduleMainRegExp.test(name);
6565
}
6666

67-
const scopedRegExp = /^@[^/]*\/?[^/]+/;
67+
const scopedRegExp = /^@[^/]+\/?[^/]+/;
6868
export function isScoped(name) {
6969
return name && scopedRegExp.test(name);
7070
}

‎tests/src/core/importType.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import * as path from 'path';
33

4-
import importType, { isExternalModule, isScopedModule } from 'core/importType';
4+
import importType, { isExternalModule, isScopedModule, isScoped } from 'core/importType';
55

66
import { testContext, testFilePath } from '../utils';
77

@@ -241,6 +241,15 @@ describe('importType(name)', function () {
241241

242242
it('correctly identifies scoped modules with `isScopedModule`', () => {
243243
expect(isScopedModule('@/abc')).to.equal(false);
244+
expect(isScopedModule('@/abc/def')).to.equal(false);
244245
expect(isScopedModule('@a/abc')).to.equal(true);
246+
expect(isScopedModule('@a/abc/def')).to.equal(true);
247+
});
248+
249+
it('correctly identifies scoped modules with `isScoped`', () => {
250+
expect(isScoped('@/abc')).to.equal(false);
251+
expect(isScoped('@/abc/def')).to.equal(false);
252+
expect(isScoped('@a/abc')).to.equal(true);
253+
expect(isScoped('@a/abc/def')).to.equal(true);
245254
});
246255
});

‎tests/src/rules/extensions.js

+10
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ ruleTester.run('extensions', rule, {
349349
line: 4,
350350
column: 31,
351351
},
352+
{
353+
message: 'Missing file extension for "@/configs/chart"',
354+
line: 7,
355+
column: 27,
356+
},
352357
],
353358
}),
354359

@@ -369,6 +374,11 @@ ruleTester.run('extensions', rule, {
369374
line: 4,
370375
column: 31,
371376
},
377+
{
378+
message: 'Missing file extension for "@/configs/chart"',
379+
line: 7,
380+
column: 27,
381+
},
372382
],
373383
}),
374384

0 commit comments

Comments
 (0)
Please sign in to comment.