-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f5d1dd
commit 5310068
Showing
9 changed files
with
133 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,39 @@ | ||
# eslint-plugin-node | ||
|
||
I'm working on this now. | ||
[![Build Status](https://travis-ci.org/mysticatea/eslint-plugin-node.svg?branch=master)](https://travis-ci.org/mysticatea/eslint-plugin-node) | ||
[![Coverage Status](https://coveralls.io/repos/mysticatea/eslint-plugin-node/badge.svg?branch=master)](https://coveralls.io/r/mysticatea/eslint-plugin-node?branch=master) | ||
[![Dependency Status](https://david-dm.org/mysticatea/eslint-plugin-node.svg)](https://david-dm.org/mysticatea/eslint-plugin-node) | ||
[![npm version](https://badge.fury.io/js/eslint-plugin-node.svg)](http://badge.fury.io/js/eslint-plugin-node) | ||
|
||
Additional ESLint's rules for Node.js | ||
|
||
Some rules are slow because it searches `package.json` and opens it. | ||
|
||
## Install & Usage | ||
|
||
``` | ||
> npm install --save-dev eslint eslint-plugin-node | ||
``` | ||
|
||
**.eslintrc** | ||
|
||
```json | ||
{ | ||
"extends": "eslint:recommended", | ||
"plugins": ["node"], | ||
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"node/no-missing-import": 2, | ||
"node/no-missing-require": 2, | ||
"node/shebang": 2 | ||
} | ||
} | ||
``` | ||
|
||
## Rules | ||
|
||
- [no-missing-import](docs/rules/no-missing-import.md) - Disallow invalid `import` and `export` declarations. | ||
- [no-missing-require](docs/rules/no-missing-require.md) - Disallow invalid `require()`s. | ||
- [shebang](docs/rules/shebang.md) - Suggest correct usage of shebang. |
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 |
---|---|---|
@@ -1,17 +1,25 @@ | ||
# (no-missing-import) | ||
# Disallow invalid `import` and `export` declarations (no-missing-import) | ||
|
||
This is similar to [no-missing-require](no-missing-require.md), but this rule handles `import` and `export` declarations. | ||
|
||
**NOTE:** ECMAScript 2015 (ES6) does not define the lookup logic. So this rule spec might be changed in future. | ||
|
||
## Rule Details | ||
|
||
See [no-missing-require](no-missing-require.md#rule-details). | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
``` | ||
import typoFile from "./typo-file"; /*error "./typo-file" is not found.*/ | ||
import typoModule from "typo-module"; /*error "typo-module" is not found.*/ | ||
|
||
The following patterns are considered not problems: | ||
|
||
```js | ||
// If the module is not written in "dependencies" and "peerDependencies".... | ||
import someone from "someone"; /*error "someone" is not published.*/ | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you don't want to ***, then it's safe to disable this rule. | ||
This rule should not be used in ES3/5 environments. | ||
|
||
If you don't want to be notified about usage of `import` and `export` declarations, then it's safe to disable this rule. |
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 |
---|---|---|
@@ -1,17 +1,54 @@ | ||
# Check whether or not `require()` is valid (no-missing-require) | ||
# Disallow invalid `require()`s (no-missing-require) | ||
|
||
Maybe we cannot find typo of import paths until run it. | ||
Also, maybe we cannot find lacking of `dependencies` of `package.json` until publish it. | ||
|
||
So this rule checks import paths and `dependencies` of `package.json`. | ||
|
||
## Rule Details | ||
|
||
This rule does two checks. | ||
|
||
1. This rule checks whether or not the files of import paths exist. | ||
If those do not exist, it reports the invalid `require()`. | ||
2. This rule looks up `package.json` file from each linitng target file. | ||
Starting from the directory of the target file, it goes up ancestor directories until found. | ||
Then it checks whether or not the imported modules are published properly. | ||
|
||
This does not check for dynamic imports. | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
var typoFile = require("./typo-file"); /*error "./typo-file" is not found.*/ | ||
var typoModule = require("typo-module"); /*error "typo-module" is not found.*/ | ||
|
||
// If the module is not written in "dependencies" and "peerDependencies".... | ||
var someone = require("someone"); /*error "someone" is not published.*/ | ||
``` | ||
|
||
The following patterns are considered not problems: | ||
|
||
```js | ||
var existingFile = require("./existing"); | ||
|
||
// If it's installed and it's written in `dependencies` or `peerDependencies`. | ||
var eslint = require("eslint"); | ||
``` | ||
|
||
### Options | ||
|
||
```json | ||
{ | ||
"no-missing-require": [2, {"publish": "+(./*|./{bin,lib,src}/**)"}] | ||
} | ||
``` | ||
|
||
- `publish` (`string`) - A glob pattern. | ||
If a linting target file is matched this pattern, the file is addressed as a published file. | ||
`require()` in the published files cannot import files which are not published. | ||
On the other hand, other files can import files which are not published. | ||
|
||
## When Not To Use It | ||
|
||
If you don't want to ***, then it's safe to disable this rule. | ||
If you don't want to be notified about usage of `require()`, then it's safe to disable this rule. |
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 |
---|---|---|
@@ -1,17 +1,48 @@ | ||
# (shebang) | ||
# Suggest correct usage of shebang (node/shebang) | ||
|
||
When we make a CLI tool on Node.js, we add `bin` field to `package.json`, then we add a shebang the entry file. | ||
This rule suggests correct usage of shebang. | ||
|
||
## Rule Details | ||
|
||
This rule looks up `package.json` file from each linitng target file. | ||
Starting from the directory of the target file, it goes up ancestor directories until found. | ||
|
||
If `package.json` was not found, this rule does nothing. | ||
|
||
This rule checks `bin` field of `package.json`, then if a target file matches one of `bin` files, it checks whether or not there is a correct shebang. | ||
Otherwise it checks whether or not there is not a shebang. | ||
|
||
### For files in `bin` field of `package.json`: | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
console.log("hello"); /*error This file needs shebang "#!/usr/bin/env node".*/ | ||
``` | ||
|
||
The following patterns are considered not problems: | ||
|
||
```js | ||
#!/usr/bin/env node | ||
console.log("hello"); | ||
``` | ||
|
||
### For other files: | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
#!/usr/bin/env node /*error This file needs no shebang.*/ | ||
console.log("hello"); | ||
``` | ||
|
||
The following patterns are considered not problems: | ||
|
||
```js | ||
console.log("hello"); | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you don't want to ***, then it's safe to disable this rule. | ||
If you don't want to be notified about usage of shebang, then it's safe to disable this rule. |
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 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