Skip to content

Commit

Permalink
Update: add "excluding files" feature to convertPath option (fixes #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Feb 5, 2017
1 parent 390c9ec commit f8a5e0b
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 146 deletions.
26 changes: 25 additions & 1 deletion docs/rules/no-unpublished-bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ For example:
"rules": {
"node/no-unpublished-bin": ["error", {
"convertPath": {
"src/bin/**/*.js": ["^src/bin/(.+)$", "bin/$1"]
"src/bin/**/*.js": ["^src/(.+)$", "$1"]
}
}]
}
Expand All @@ -60,6 +60,30 @@ path.replace(new RegExp(fromRegExp), toString);

So on this example, `src/bin/index.js` is handled as `bin/index.js`.

The `convertPath` option can be an array as well.

For example:

```json
{
"rules": {
"node/no-unpublished-bin": ["error", {
"convertPath": [
{
"include": ["src/bin/**/*.js"],
"exclude": ["**/*.spec.js"],
"replace": ["^src/(.+)$", "$1"]
}
]
}]
}
}
```

In this style, this option has the following shape as the same expression as above: `{include: [<targetFiles>], replace: [<fromRegExp>, <toString>]}`.
In addition, we can specify glob patterns to exclude files.


## Shared Settings

The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings).
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/no-unpublished-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ path.replace(new RegExp(fromRegExp), toString);

So on this example, `src/a/foo.jsx` is handled as `lib/a/foo.js`.

The `convertPath` option can be an array as well.

For example:

```json
{
"rules": {
"node/no-unpublished-import": ["error", {
"convertPath": [
{
"include": ["src/**/*.js"],
"exclude": ["**/*.spec.js"],
"replace": ["^src/(.+)$", "lib/$1"]
}
]
}]
}
}
```

In this style, this option has the following shape as the same expression as above: `{include: [<targetFiles>], replace: [<fromRegExp>, <toString>]}`.
In addition, we can specify glob patterns to exclude files.

### tryExtensions

When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists.
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/no-unpublished-require.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ path.replace(new RegExp(fromRegExp), toString);

So on this example, `src/a/foo.jsx` is handled as `lib/a/foo.js`.

The `convertPath` option can be an array as well.

For example:

```json
{
"rules": {
"node/no-unpublished-require": ["error", {
"convertPath": [
{
"include": ["src/**/*.js"],
"exclude": ["**/*.spec.js"],
"replace": ["^src/(.+)$", "lib/$1"]
}
]
}]
}
}
```

In this style, this option has the following shape as the same expression as above: `{include: [<targetFiles>], replace: [<fromRegExp>, <toString>]}`.
In addition, we can specify glob patterns to exclude files.

### tryExtensions

When an import path does not exist, this rule checks whether or not any of `path.js`, `path.json`, and `path.node` exists.
Expand Down
23 changes: 23 additions & 0 deletions docs/rules/shebang.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,29 @@ path.replace(new RegExp(fromRegExp), toString);

So on this example, `src/a/foo.jsx` is handled as `lib/a/foo.js`.

The `convertPath` option can be an array as well.

For example:

```json
{
"rules": {
"node/shebang": ["error", {
"convertPath": [
{
"include": ["src/**/*.js"],
"exclude": ["**/*.spec.js"],
"replace": ["^src/(.+)$", "lib/$1"]
}
]
}]
}
}
```

In this style, this option has the following shape as the same expression as above: `{include: [<targetFiles>], replace: [<fromRegExp>, <toString>]}`.
In addition, we can specify glob patterns to exclude files.

## Shared Settings

The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings).
Expand Down
20 changes: 4 additions & 16 deletions lib/rules/no-missing-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
//------------------------------------------------------------------------------

const checkExistence = require("../util/check-existence")
const getAllowModules = require("../util/get-allow-modules")
const getImportExportTargets = require("../util/get-import-export-targets")
const getTryExtensions = require("../util/get-try-extensions")

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -37,22 +39,8 @@ module.exports.schema = [
{
type: "object",
properties: {
allowModules: {
type: "array",
items: {
type: "string",
pattern: "^(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
},
uniqueItems: true,
},
tryExtensions: {
type: "array",
items: {
type: "string",
pattern: "^\\.",
},
uniqueItems: true,
},
allowModules: getAllowModules.schema,
tryExtensions: getTryExtensions.schema,
},
additionalProperties: false,
},
Expand Down
20 changes: 4 additions & 16 deletions lib/rules/no-missing-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
//------------------------------------------------------------------------------

const checkExistence = require("../util/check-existence")
const getAllowModules = require("../util/get-allow-modules")
const getRequireTargets = require("../util/get-require-targets")
const getTryExtensions = require("../util/get-try-extensions")

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -37,22 +39,8 @@ module.exports.schema = [
{
type: "object",
properties: {
allowModules: {
type: "array",
items: {
type: "string",
pattern: "^(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
},
uniqueItems: true,
},
tryExtensions: {
type: "array",
items: {
type: "string",
pattern: "^\\.",
},
uniqueItems: true,
},
allowModules: getAllowModules.schema,
tryExtensions: getTryExtensions.schema,
},
additionalProperties: false,
},
Expand Down
16 changes: 2 additions & 14 deletions lib/rules/no-unpublished-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,8 @@ module.exports = {
schema: [
{
type: "object",
properties: {
convertPath: {
type: "object",
properties: {},
patternProperties: {
"^.+$": {
type: "array",
items: {type: "string"},
minItems: 2,
maxItems: 2,
},
},
additionalProperties: false,
},
properties: { //
convertPath: getConvertPath.schema,
},
},
],
Expand Down
35 changes: 6 additions & 29 deletions lib/rules/no-unpublished-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
//------------------------------------------------------------------------------

const checkPublish = require("../util/check-publish")
const getAllowModules = require("../util/get-allow-modules")
const getConvertPath = require("../util/get-convert-path")
const getImportExportTargets = require("../util/get-import-export-targets")
const getTryExtensions = require("../util/get-try-extensions")

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -37,35 +40,9 @@ module.exports.schema = [
{
type: "object",
properties: {
allowModules: {
type: "array",
items: {
type: "string",
pattern: "^(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
},
uniqueItems: true,
},
convertPath: {
type: "object",
properties: {},
patternProperties: {
"^.+$": {
type: "array",
items: {type: "string"},
minItems: 2,
maxItems: 2,
},
},
additionalProperties: false,
},
tryExtensions: {
type: "array",
items: {
type: "string",
pattern: "^\\.",
},
uniqueItems: true,
},
allowModules: getAllowModules.schema,
convertPath: getConvertPath.schema,
tryExtensions: getTryExtensions.schema,
},
additionalProperties: false,
},
Expand Down
35 changes: 6 additions & 29 deletions lib/rules/no-unpublished-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
//------------------------------------------------------------------------------

const checkPublish = require("../util/check-publish")
const getAllowModules = require("../util/get-allow-modules")
const getConvertPath = require("../util/get-convert-path")
const getRequireTargets = require("../util/get-require-targets")
const getTryExtensions = require("../util/get-try-extensions")

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -37,35 +40,9 @@ module.exports.schema = [
{
type: "object",
properties: {
allowModules: {
type: "array",
items: {
type: "string",
pattern: "^(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
},
uniqueItems: true,
},
convertPath: {
type: "object",
properties: {},
patternProperties: {
"^.+$": {
type: "array",
items: {type: "string"},
minItems: 2,
maxItems: 2,
},
},
additionalProperties: false,
},
tryExtensions: {
type: "array",
items: {
type: "string",
pattern: "^\\.",
},
uniqueItems: true,
},
allowModules: getAllowModules.schema,
convertPath: getConvertPath.schema,
tryExtensions: getTryExtensions.schema,
},
additionalProperties: false,
},
Expand Down
13 changes: 2 additions & 11 deletions lib/rules/shebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,8 @@ module.exports = function(context) {
module.exports.schema = [
{
type: "object",
properties: {
convertPath: {
type: "object",
properties: {},
additionalProperties: {
type: "array",
items: {type: "string"},
minItems: 2,
maxItems: 2,
},
},
properties: { //
convertPath: getConvertPath.schema,
},
additionalProperties: false,
},
Expand Down
9 changes: 9 additions & 0 deletions lib/util/get-allow-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ module.exports = function getAllowModules(context) {
DEFAULT_VALUE
)
}

module.exports.schema = {
type: "array",
items: {
type: "string",
pattern: "^(?:@[a-zA-Z0-9_\\-.]+/)?[a-zA-Z0-9_\\-.]+$",
},
uniqueItems: true,
}
Loading

0 comments on commit f8a5e0b

Please sign in to comment.