-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New:
no-unpublished-*
rules (refs #3)
- Loading branch information
1 parent
82958d4
commit af82240
Showing
26 changed files
with
810 additions
and
64 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
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,43 @@ | ||
# Disallow `import` and `export` declarations for files that are not published (no-unpublished-import) | ||
|
||
This is similar to [no-unpublished-require](no-unpublished-require.md), but this rule handles `import` and `export` declarations. | ||
|
||
**NOTE:** ECMAScript 2015 (ES6) does not define the lookup logic and Node does not support modules yet. So this rule spec might be changed in future. | ||
|
||
## Rule Details | ||
|
||
This rule checks the file paths of `import` and `export` declarations. | ||
If the file paths are not published, this reports these. | ||
|
||
"published" is that satisfying the following conditions: | ||
|
||
- If it's a file: | ||
- `"files"` field of `package.json` includes the file, or the field is nothing. | ||
- `.npmignore` does not include the file. | ||
- If it's a module: | ||
- `"dependencies"` or `"peerDependencies"` field of `package.json` includes the module. | ||
If the file `require` is written is not published then it's also OK that `"devDependencies"` field of `package.json` includes the module. | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
/*eslint node/no-unpublished-import: 2*/ | ||
|
||
import ignoredFile from "./ignored-file"; /*error "./ignored-file" is not published.*/ | ||
import notDependedModule from "not-depended-module"; /*error "not-depended-module" is not published.*/ | ||
``` | ||
|
||
The following patterns are considered not problems: | ||
|
||
```js | ||
/*eslint node/no-unpublished-import: 2*/ | ||
|
||
import publishedFile from "./published-file"; | ||
import dependedModule from "depended-module"; | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Disallow `require()`s for files that files that are not published (no-unpublished-require) | ||
|
||
If `require()` targets are not published, the program works in local, but will not work after published to npm. | ||
This rule catches `require()` for files and modules that not published. | ||
|
||
## Rule Details | ||
|
||
This rule checks the file paths of `require()`s. | ||
If the file paths are not published, this reports these. | ||
|
||
"published" is that satisfying the following conditions: | ||
|
||
- If it's a file: | ||
- `"files"` field of `package.json` includes the file, or the field is nothing. | ||
- `.npmignore` does not include the file. | ||
- If it's a module: | ||
- `"dependencies"` or `"peerDependencies"` field of `package.json` includes the module. | ||
If the file `require` is written is not published then it's also OK that `"devDependencies"` field of `package.json` includes the module. | ||
|
||
The following patterns are considered problems: | ||
|
||
```js | ||
/*eslint node/no-unpublished-require: 2*/ | ||
|
||
var ignoredFile = require("./ignored-file"); /*error "./ignored-file" is not published.*/ | ||
var notDependedModule = require("not-depended-module"); /*error "not-depended-module" is not published.*/ | ||
``` | ||
|
||
The following patterns are considered not problems: | ||
|
||
```js | ||
/*eslint node/no-unpublished-require: 2*/ | ||
|
||
var publishedFile = require("./published-file"); | ||
var dependedModule = require("depended-module"); | ||
|
||
// This rule cannot check for dynamic imports. | ||
var foo = require(FOO_NAME); | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
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
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,37 @@ | ||
/** | ||
* @author Toru Nagashima | ||
* @copyright 2016 Toru Nagashima. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var checkPublish = require("../util/check-publish"); | ||
var getImportExportTargets = require("../util/get-import-export-targets"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function(context) { | ||
var filePath = context.getFilename(); | ||
if (filePath === "<input>") { | ||
return {}; | ||
} | ||
|
||
return { | ||
"Program:exit": function(node) { | ||
checkPublish( | ||
context, | ||
filePath, | ||
getImportExportTargets(context, node) | ||
); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = []; |
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,37 @@ | ||
/** | ||
* @author Toru Nagashima | ||
* @copyright 2016 Toru Nagashima. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
var checkPublish = require("../util/check-publish"); | ||
var getRequireTargets = require("../util/get-require-targets"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Rule Definition | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = function(context) { | ||
var filePath = context.getFilename(); | ||
if (filePath === "<input>") { | ||
return {}; | ||
} | ||
|
||
return { | ||
"Program:exit": function() { | ||
checkPublish( | ||
context, | ||
filePath, | ||
getRequireTargets(context) | ||
); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports.schema = []; |
Oops, something went wrong.