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

Destructured exports no unused modules #2038

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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