Skip to content

Commit

Permalink
[Fix] no-unused-modules: improve schema
Browse files Browse the repository at this point in the history
 - allow empty arrays in `src` and `ignoreExports`
 - enforce uniqueness in `src` and `ignoreExport` lists
 - allow false/true combo on missingExports/unusedExports
  • Loading branch information
ljharb committed Jul 27, 2023
1 parent a6de522 commit 3e1dd0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
- [`order`]: partial fix for [#2687] (thanks [@ljharb])
- [`no-duplicates`]: Detect across type and regular imports ([#2835], thanks [@benkrejci])
- [`extensions`]: handle `.` and `..` properly ([#2778], thanks [@benasher44])
- [`no-unused-modules`]: improve schema (thanks [@ljharb])

### Changed
- [Docs] [`no-duplicates`]: fix example schema ([#2684], thanks [@simmo])
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unused-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Reports:

### Usage

In order for this plugin to work, one of the options `missingExports` or `unusedExports` must be enabled (see "Options" section below). In the future, these options will be enabled by default (see https://github.com/import-js/eslint-plugin-import/issues/1324)
In order for this plugin to work, at least one of the options `missingExports` or `unusedExports` must be enabled (see "Options" section below). In the future, these options will be enabled by default (see https://github.com/import-js/eslint-plugin-import/issues/1324)

Example:
```
Expand Down
39 changes: 12 additions & 27 deletions src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,16 @@ module.exports = {
src: {
description: 'files/paths to be analyzed (only for unused exports)',
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
minLength: 1,
},
},
ignoreExports: {
description:
'files/paths for which unused exports will not be reported (e.g module entry points)',
description: 'files/paths for which unused exports will not be reported (e.g module entry points)',
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
minLength: 1,
Expand All @@ -441,37 +440,23 @@ module.exports = {
type: 'boolean',
},
},
not: {
properties: {
unusedExports: { enum: [false] },
missingExports: { enum: [false] },
},
},
anyOf: [{
not: {
anyOf: [
{
properties: {
unusedExports: { enum: [true] },
src: {
minItems: 1,
},
},
required: ['unusedExports'],
},
required: ['missingExports'],
}, {
not: {
{
properties: {
missingExports: { enum: [true] },
},
required: ['missingExports'],
},
required: ['unusedExports'],
}, {
properties: {
unusedExports: { enum: [true] },
},
required: ['unusedExports'],
}, {
properties: {
missingExports: { enum: [true] },
},
required: ['missingExports'],
}],
],
}],
},

Expand Down

0 comments on commit 3e1dd0b

Please sign in to comment.