Skip to content

Commit

Permalink
[Fix] extensions/importType: fix isScoped treating @/abc as scope…
Browse files Browse the repository at this point in the history
…d module

Fixes #2145
  • Loading branch information
Rafael Perello authored and ljharb committed Jul 6, 2021
1 parent b236748 commit 00d7bc8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`no-duplicates`]: ensure autofix avoids excessive newlines ([#2028], thanks [@ertrzyiks])
- [`extensions`]: avoid crashing on partially typed import/export statements ([#2118], thanks [@ljharb])
- [`no-extraneous-dependencies`]: add ESM intermediate package.json support] ([#2121], thanks [@paztis])
- Use `context.getPhysicalFilename()` when available (ESLint 7.28+) ([#2160], thanks [@pmcelhaney])
- Use `context.getPhysicalFilename()` when available (ESLint 7.28+) ([#2160], thanks [@pmcelhaney])
- [`extensions`]/`importType`: fix isScoped treating @/abc as scoped module ([#2146], thanks [@rperello])

### Changed
- [Docs] `extensions`: removed incorrect cases ([#2138], thanks [@wenfangdu])
Expand Down Expand Up @@ -814,6 +815,7 @@ for info on changes for earlier releases.
[#2160]: https://github.com/benmosher/eslint-plugin-import/pull/2160
[#2158]: https://github.com/benmosher/eslint-plugin-import/pull/2158
[#2156]: https://github.com/benmosher/eslint-plugin-import/pull/2156
[#2146]: https://github.com/benmosher/eslint-plugin-import/pull/2146
[#2138]: https://github.com/benmosher/eslint-plugin-import/pull/2138
[#2121]: https://github.com/benmosher/eslint-plugin-import/pull/2121
[#2099]: https://github.com/benmosher/eslint-plugin-import/pull/2099
Expand Down Expand Up @@ -1391,6 +1393,7 @@ for info on changes for earlier releases.
[@richardxia]: https://github.com/richardxia
[@robertrossmann]: https://github.com/robertrossmann
[@rosswarren]: https://github.com/rosswarren
[@rperello]: https://github.com/rperello
[@rsolomon]: https://github.com/rsolomon
[@s-h-a-d-o-w]: https://github.com/s-h-a-d-o-w
[@saschanaz]: https://github.com/saschanaz
Expand Down
2 changes: 1 addition & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function isModuleMain(name) {
return name && moduleMainRegExp.test(name);
}

const scopedRegExp = /^@[^/]*\/?[^/]+/;
const scopedRegExp = /^@[^/]+\/?[^/]+/;
export function isScoped(name) {
return name && scopedRegExp.test(name);
}
Expand Down
11 changes: 10 additions & 1 deletion tests/src/core/importType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as path from 'path';

import importType, { isExternalModule, isScopedModule } from 'core/importType';
import importType, { isExternalModule, isScopedModule, isScoped } from 'core/importType';

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

Expand Down Expand Up @@ -241,6 +241,15 @@ describe('importType(name)', function () {

it('correctly identifies scoped modules with `isScopedModule`', () => {
expect(isScopedModule('@/abc')).to.equal(false);
expect(isScopedModule('@/abc/def')).to.equal(false);
expect(isScopedModule('@a/abc')).to.equal(true);
expect(isScopedModule('@a/abc/def')).to.equal(true);
});

it('correctly identifies scoped modules with `isScoped`', () => {
expect(isScoped('@/abc')).to.equal(false);
expect(isScoped('@/abc/def')).to.equal(false);
expect(isScoped('@a/abc')).to.equal(true);
expect(isScoped('@a/abc/def')).to.equal(true);
});
});
10 changes: 10 additions & 0 deletions tests/src/rules/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ ruleTester.run('extensions', rule, {
line: 4,
column: 31,
},
{
message: 'Missing file extension for "@/configs/chart"',
line: 7,
column: 27,
},
],
}),

Expand All @@ -369,6 +374,11 @@ ruleTester.run('extensions', rule, {
line: 4,
column: 31,
},
{
message: 'Missing file extension for "@/configs/chart"',
line: 7,
column: 27,
},
],
}),

Expand Down

0 comments on commit 00d7bc8

Please sign in to comment.