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] no-unused-modules: checkPkgFieldObject filters boolean fields #2598

Merged
merged 2 commits into from Nov 17, 2022
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 @@ -28,7 +28,8 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- [`dynamic-import-chunkname`]: prevent false report on a valid webpack magic comment ([#2330], thanks [@mhmadhamster])
- [`export`]: do not error on TS export overloads ([#1590], thanks [@ljharb])
- [`no-unresolved`], [`extensions`]: ignore type only exports ([#2436], thanks [@Lukas-Kullmann])
- [Fix] `ExportMap`: add missing param to function ([#2589], thanks [@Fdawgs])
- `ExportMap`: add missing param to function ([#2589], thanks [@Fdawgs])
- [`no-unused-modules`]: `checkPkgFieldObject` filters boolean fields from checks ([#2598], thanks [@mpint])

### Changed
- [Tests] [`named`]: Run all TypeScript test ([#2427], thanks [@ProdigySim])
Expand Down Expand Up @@ -1022,6 +1023,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#2598]: https://github.com/import-js/eslint-plugin-import/pull/2598
[#2589]: https://github.com/import-js/eslint-plugin-import/pull/2589
[#2588]: https://github.com/import-js/eslint-plugin-import/pull/2588
[#2582]: https://github.com/import-js/eslint-plugin-import/pull/2582
Expand Down Expand Up @@ -1697,6 +1699,7 @@ for info on changes for earlier releases.
[@mgwalker]: https://github.com/mgwalker
[@mhmadhamster]: https://github.com/MhMadHamster
[@MikeyBeLike]: https://github.com/MikeyBeLike
[@mpint]: https://github.com/mpint
[@mplewis]: https://github.com/mplewis
[@mrmckeb]: https://github.com/mrmckeb
[@msvab]: https://github.com/msvab
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-unused-modules.js
Expand Up @@ -364,7 +364,10 @@ const fileIsInPkg = file => {
};

const checkPkgFieldObject = pkgField => {
const pkgFieldFiles = values(pkgField).map(value => join(basePath, value));
const pkgFieldFiles = values(pkgField)
.filter((value) => typeof value !== 'boolean')
.map(value => join(basePath, value));

if (includes(pkgFieldFiles, file)) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/files/no-unused-modules/browserObject/package.json
@@ -1,5 +1,6 @@
{
"browser": {
"browserObject": "./index.js"
"browserObject": "./index.js",
"an-ignored-module": false
}
}
10 changes: 5 additions & 5 deletions tests/src/core/getExports.js
Expand Up @@ -367,7 +367,7 @@ describe('ExportMap', function () {

let imports;
before('load imports', function () {
this.timeout(20000); // takes a long time :shrug:
this.timeout(20e3); // takes a long time :shrug:
sinon.spy(tsConfigLoader, 'tsConfigLoader');
imports = ExportMap.get('./typescript.ts', context);
});
Expand Down Expand Up @@ -436,13 +436,13 @@ describe('ExportMap', function () {
it('should cache after parsing for an ambiguous module', function () {
const source = './typescript-declare-module.ts';
const parseSpy = sinon.spy(ExportMap, 'parse');

expect(ExportMap.get(source, context)).to.be.null;

ExportMap.get(source, context);

expect(parseSpy.callCount).to.equal(1);

parseSpy.restore();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/resolve.js
Expand Up @@ -401,7 +401,7 @@ describe('resolve', function () {

// special behavior for infinity
describe('infinite cache', function () {
this.timeout(1500);
this.timeout(1.5e3);

before((done) => setTimeout(done, 1100));

Expand All @@ -414,7 +414,7 @@ describe('resolve', function () {
});

describe('finite cache', function () {
this.timeout(1200);
this.timeout(1.2e3);
before((done) => setTimeout(done, 1000));
it('gets correct values after cache lifetime', function () {
expect(resolve(original, context)).not.to.exist;
Expand Down
4 changes: 3 additions & 1 deletion tests/src/rules/no-unused-modules.js
Expand Up @@ -243,14 +243,16 @@ ruleTester.run('no-unused-modules', rule, {
});


describe('dynamic imports', () => {
describe('dynamic imports', function () {
if (semver.satisfies(eslintPkg.version, '< 6')) {
beforeEach(function () {
this.skip();
});
return;
}

this.timeout(10e3);

// test for unused exports with `import()`
ruleTester.run('no-unused-modules', rule, {
valid: [
Expand Down