Skip to content

Commit

Permalink
[Tests] add passing no-unused-modules tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KristjanTammekivi authored and ljharb committed Apr 27, 2021
1 parent 5898e28 commit 2057c05
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/rules/no-extraneous-dependencies.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# import/no-extraneous-dependencies: Forbid the use of extraneous packages

Forbid the import of external modules that are not declared in the `package.json`'s `dependencies`, `devDependencies`, `optionalDependencies`, `peerDependencies`, or `bundledDependencies`.
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`.
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`.

Modules have to be installed for this rule to work.

Expand Down
2 changes: 2 additions & 0 deletions tests/files/no-unused-modules/file-destructured-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const { destructured } = {};
export const { destructured2 } = {};
1 change: 1 addition & 0 deletions tests/files/no-unused-modules/file-destructured-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { destructured } from './file-destructured-1';
29 changes: 24 additions & 5 deletions tests/src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ describe('renameDefault', () => {
});
});

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


describe('test behaviour for new file', () => {
describe('test behavior for new file', () => {
before(() => {
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-1.js'), '', { encoding: 'utf8' });
});
Expand Down Expand Up @@ -619,7 +619,7 @@ describe('test behaviour for new file', () => {
});
});

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

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

describe('test behaviour for new file', () => {
describe('test behavior for destructured exports', () => {
ruleTester.run('no-unused-modules', rule, {
valid: [
test({ options: unusedExportsOptions,
code: `import { destructured } from '${testFilePath('./no-unused-modules/file-destructured-1.js')}'`,
filename: testFilePath('./no-unused-modules/file-destructured-2.js') }),
test({ options: unusedExportsOptions,
code: `export const { destructured } = {};`,
filename: testFilePath('./no-unused-modules/file-destructured-1.js') }),
],
invalid: [
test({ options: unusedExportsOptions,
code: `export const { destructured2 } = {};`,
filename: testFilePath('./no-unused-modules/file-destructured-1.js'),
errors: [`exported declaration 'destructured2' not used within other modules`] }),
],
});
});

describe('test behavior for new file', () => {
before(() => {
fs.writeFileSync(testFilePath('./no-unused-modules/file-added-4.js.js'), '', { encoding: 'utf8' });
});
Expand Down

0 comments on commit 2057c05

Please sign in to comment.