-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # package.json # src/index.js
- Loading branch information
Showing
36 changed files
with
764 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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,44 @@ | ||
# max-dependencies | ||
|
||
Forbid modules to have too many dependencies (`import` or `require` statements). | ||
|
||
This is a useful rule because a module with too many dependencies is a code smell, and usually indicates the module is doing too much and/or should be broken up into smaller modules. | ||
|
||
Importing multiple named exports from a single module will only count once (e.g. `import {x, y, z} from './foo'` will only count as a single dependency). | ||
|
||
### Options | ||
|
||
This rule takes the following option: | ||
|
||
`max`: The maximum number of dependencies allowed. Anything over will trigger the rule. **Default is 10** if the rule is enabled and no `max` is specified. | ||
|
||
You can set the option like this: | ||
|
||
```js | ||
"import/max-dependencies": ["error", {"max": 10}] | ||
``` | ||
|
||
|
||
## Example | ||
|
||
Given a max value of `{"max": 2}`: | ||
|
||
### Fail | ||
|
||
```js | ||
import a from './a'; // 1 | ||
const b = require('./b'); // 2 | ||
import c from './c'; // 3 - exceeds max! | ||
``` | ||
|
||
### Pass | ||
|
||
```js | ||
import a from './a'; // 1 | ||
const anotherA = require('./a'); // still 1 | ||
import {x, y, z} from './foo'; // 2 | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you don't care how many dependencies a module has. |
This file contains 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,27 @@ | ||
# Forbid import of modules using absolute paths | ||
|
||
Node.js allows the import of modules using an absolute path such as `/home/xyz/file.js`. That is a bad practice as it ties the code using it to your computer, and therefore makes it unusable in packages distributed on `npm` for instance. | ||
|
||
## Rule Details | ||
|
||
### Fail | ||
|
||
```js | ||
import f from '/foo'; | ||
import f from '/some/path'; | ||
|
||
var f = require('/foo'); | ||
var f = require('/some/path'); | ||
``` | ||
|
||
### Pass | ||
|
||
```js | ||
import _ from 'lodash'; | ||
import foo from 'foo'; | ||
import foo from './foo'; | ||
|
||
var _ = require('lodash'); | ||
var foo = require('foo'); | ||
var foo = require('./foo'); | ||
``` |
This file contains 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 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,64 @@ | ||
# no-internal-modules | ||
|
||
Use this rule to prevent importing the submodules of other modules. | ||
|
||
## Rule Details | ||
|
||
This rule has one option, `allow` which is an array of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns that whitelist paths and import statements that can be imported with reaching. | ||
|
||
### Examples | ||
|
||
Given the following folder structure: | ||
|
||
``` | ||
my-project | ||
├── actions | ||
│ └── getUser.js | ||
│ └── updateUser.js | ||
├── reducer | ||
│ └── index.js | ||
│ └── user.js | ||
├── redux | ||
│ └── index.js | ||
│ └── configureStore.js | ||
└── app | ||
│ └── index.js | ||
│ └── settings.js | ||
└── entry.js | ||
``` | ||
|
||
And the .eslintrc file: | ||
``` | ||
{ | ||
... | ||
"rules": { | ||
"import/no-internal-modules": [ "error", { | ||
"allow": [ "**/actions/*", "source-map-support/*" ] | ||
} ] | ||
} | ||
} | ||
``` | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
/** | ||
* in my-project/entry.js | ||
*/ | ||
|
||
import { settings } from './app/index'; // Reaching to "./app/index" is not allowed | ||
import userReducer from './reducer/user'; // Reaching to "./reducer/user" is not allowed | ||
import configureStore from './redux/configureStore'; // Reaching to "./redux/configureStore" is not allowed | ||
``` | ||
|
||
The following patterns are NOT considered problems: | ||
|
||
```js | ||
/** | ||
* in my-project/entry.js | ||
*/ | ||
|
||
import 'source-map-support/register'; | ||
import { settings } from '../app'; | ||
import getUser from '../actions/getUser'; | ||
``` |
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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.