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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] extensions/importType: fix isScoped treating @/abc as scoped module #2146

Merged
merged 1 commit into from Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
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
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
@@ -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
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