diff --git a/CHANGELOG.md b/CHANGELOG.md index a6ddbb803..53cc78240 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 @@ -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 diff --git a/src/core/importType.js b/src/core/importType.js index ecea976f4..8457c7853 100644 --- a/src/core/importType.js +++ b/src/core/importType.js @@ -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); } diff --git a/tests/src/core/importType.js b/tests/src/core/importType.js index 371a3d739..3a5000212 100644 --- a/tests/src/core/importType.js +++ b/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'; @@ -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); }); }); diff --git a/tests/src/rules/extensions.js b/tests/src/rules/extensions.js index 4070c6a6b..013433455 100644 --- a/tests/src/rules/extensions.js +++ b/tests/src/rules/extensions.js @@ -349,6 +349,11 @@ ruleTester.run('extensions', rule, { line: 4, column: 31, }, + { + message: 'Missing file extension for "@/configs/chart"', + line: 7, + column: 27, + }, ], }), @@ -369,6 +374,11 @@ ruleTester.run('extensions', rule, { line: 4, column: 31, }, + { + message: 'Missing file extension for "@/configs/chart"', + line: 7, + column: 27, + }, ], }),