-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New: no-unused-modules
rule
#1142
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
75a9eab
New: `no-unused-modules` rule
rfermann 1d8ddf7
New: `no-unused-modules` rule - minor refactoring
rfermann 153599d
New: `no-unused-modules` rule - added tests
rfermann fd1ccc0
New: `no-unused-modules` rule - removed destructoring of context.getF…
rfermann a402023
New: `no-unused-modules` rule - minor refactoring
rfermann 230122b
New: `no-unused-modules` rule - added more tests
rfermann aa7253b
New: `no-unused-modules` rule - added default src, more comprehensive…
rfermann d47ccdf
New: `no-unused-modules` rule - add support for 'import *'
rfermann 06a0976
New: rule - added support for 'export * from' and 'export { stuff } …
rfermann c483514
New: `no-unused-modules` rule - renamed 'ignore' option to 'ignoreExp…
rfermann e04c87c
New: `no-unused-modules` rule - corrected typo in docs
rfermann 2922910
New: `no-unused-modules` rule - reworked schema, removed UNDEFINED va…
0f5c2a5
New: `no-unused-modules` rule - implemented latest feedback
rfermann 191c77b
New: `no-unused-modules` rule - added trailing newlines
rfermann ae9942f
New: `no-unused-modules` rule - added stricter check for node_modules
rfermann 32f4c23
New: `no-unused-modules` rule - revert changing eslint version
rfermann 90f7217
New: `no-unused-modules` rule - removed whitespace, replaced if-stmt
rfermann 0dd398c
ew: `no-unused-modules` rule - remove unnecessary exports
rfermann 1ac4bd7
ew: `no-unused-modules` rule - remove unnecessary exports
rfermann d35b7ff
Merge branches 'master' and 'master' of https://github.com/rfermann/e…
rfermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# import/no-unused-modules | ||
|
||
Reports: | ||
- modules without any exports | ||
- individual exports not being statically `import`ed or `require`ed from other modules in the same project | ||
|
||
Note: dynamic imports are currently not supported. | ||
|
||
## Rule Details | ||
|
||
|
||
### Options | ||
|
||
This rule takes the following option: | ||
|
||
- `src`: an array with files/paths to be analyzed. It only applies to unused exports. Defaults to `process.cwd()`, if not provided | ||
- `ignoreExports`: an array with files/paths for which unused exports will not be reported (e.g module entry points in a published package) | ||
- `missingExports`: if `true`, files without any exports are reported | ||
- `unusedExports`: if `true`, exports without any static usage within other modules are reported. | ||
|
||
|
||
### Example for missing exports | ||
#### The following will be reported | ||
```js | ||
const class MyClass { /*...*/ } | ||
|
||
function makeClass() { return new MyClass(...arguments) } | ||
``` | ||
|
||
#### The following will not be reported | ||
|
||
```js | ||
export default function () { /*...*/ } | ||
``` | ||
```js | ||
export const foo = function () { /*...*/ } | ||
``` | ||
```js | ||
export { foo, bar } | ||
``` | ||
```js | ||
export { foo as bar } | ||
``` | ||
|
||
### Example for unused exports | ||
given file-f: | ||
```js | ||
import { e } from 'file-a' | ||
import { f } from 'file-b' | ||
import * from 'file-c' | ||
export * from 'file-d' | ||
export { default, i0 } from 'file-e' // both will be reported | ||
|
||
export const j = 99 // will be reported | ||
``` | ||
and file-e: | ||
```js | ||
export const i0 = 9 // will not be reported | ||
export const i1 = 9 // will be reported | ||
export default () => {} // will not be reported | ||
``` | ||
and file-d: | ||
```js | ||
export const h = 8 // will not be reported | ||
export default () => {} // will be reported, as export * only considers named exports and ignores default exports | ||
``` | ||
and file-c: | ||
```js | ||
export const g = 7 // will not be reported | ||
export default () => {} // will not be reported | ||
``` | ||
and file-b: | ||
```js | ||
import two, { b, c, doAnything } from 'file-a' | ||
|
||
export const f = 6 // will not be reported | ||
``` | ||
and file-a: | ||
```js | ||
const b = 2 | ||
const c = 3 | ||
const d = 4 | ||
|
||
export const a = 1 // will be reported | ||
|
||
export { b, c } // will not be reported | ||
|
||
export { d as e } // will not be reported | ||
|
||
export function doAnything() { | ||
// some code | ||
} // will not be reported | ||
|
||
export default 5 // will not be reported | ||
``` | ||
|
||
|
||
|
||
## When not to use | ||
|
||
If you don't mind having unused files or dead code within your codebase, you can disable this rule | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.