Skip to content

Commit 2057c05

Browse files
KristjanTammekiviljharb
authored andcommitted
[Tests] add passing no-unused-modules tests
1 parent 5898e28 commit 2057c05

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

docs/rules/no-extraneous-dependencies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# import/no-extraneous-dependencies: Forbid the use of extraneous packages
22

33
Forbid the import of external modules that are not declared in the `package.json`'s `dependencies`, `devDependencies`, `optionalDependencies`, `peerDependencies`, or `bundledDependencies`.
4-
The closest parent `package.json` will be used. If no `package.json` is found, the rule will not lint anything. This behaviour can be changed with the rule option `packageDir`.
4+
The closest parent `package.json` will be used. If no `package.json` is found, the rule will not lint anything. This behavior can be changed with the rule option `packageDir`.
55

66
Modules have to be installed for this rule to work.
77

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const { destructured } = {};
2+
export const { destructured2 } = {};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { destructured } from './file-destructured-1';

tests/src/rules/no-unused-modules.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ describe('renameDefault', () => {
500500
});
501501
});
502502

503-
describe('test behaviour for new file', () => {
503+
describe('test behavior for new file', () => {
504504
before(() => {
505505
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-0.js'), '', { encoding: 'utf8' });
506506
});
@@ -588,7 +588,7 @@ describe('test behaviour for new file', () => {
588588
});
589589

590590

591-
describe('test behaviour for new file', () => {
591+
describe('test behavior for new file', () => {
592592
before(() => {
593593
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-1.js'), '', { encoding: 'utf8' });
594594
});
@@ -619,7 +619,7 @@ describe('test behaviour for new file', () => {
619619
});
620620
});
621621

622-
describe('test behaviour for new file', () => {
622+
describe('test behavior for new file', () => {
623623
before(() => {
624624
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-2.js'), '', { encoding: 'utf8' });
625625
});
@@ -641,7 +641,7 @@ describe('test behaviour for new file', () => {
641641
});
642642
});
643643

644-
describe('test behaviour for new file', () => {
644+
describe('test behavior for new file', () => {
645645
before(() => {
646646
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-3.js'), '', { encoding: 'utf8' });
647647
});
@@ -663,7 +663,26 @@ describe('test behaviour for new file', () => {
663663
});
664664
});
665665

666-
describe('test behaviour for new file', () => {
666+
describe('test behavior for destructured exports', () => {
667+
ruleTester.run('no-unused-modules', rule, {
668+
valid: [
669+
test({ options: unusedExportsOptions,
670+
code: `import { destructured } from '${testFilePath('./no-unused-modules/file-destructured-1.js')}'`,
671+
filename: testFilePath('./no-unused-modules/file-destructured-2.js') }),
672+
test({ options: unusedExportsOptions,
673+
code: `export const { destructured } = {};`,
674+
filename: testFilePath('./no-unused-modules/file-destructured-1.js') }),
675+
],
676+
invalid: [
677+
test({ options: unusedExportsOptions,
678+
code: `export const { destructured2 } = {};`,
679+
filename: testFilePath('./no-unused-modules/file-destructured-1.js'),
680+
errors: [`exported declaration 'destructured2' not used within other modules`] }),
681+
],
682+
});
683+
});
684+
685+
describe('test behavior for new file', () => {
667686
before(() => {
668687
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-4.js.js'), '', { encoding: 'utf8' });
669688
});

0 commit comments

Comments
 (0)