@ota-meshi/eslint-plugin 0.10.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/configs/+eslint-plugin.js +81 -84
- package/lib/configs/+json.js +17 -17
- package/lib/configs/+md.js +16 -16
- package/lib/configs/+node.js +31 -28
- package/lib/configs/+package-json.js +14 -14
- package/lib/configs/+prettier.js +56 -67
- package/lib/configs/+toml.js +14 -14
- package/lib/configs/+typescript.js +150 -144
- package/lib/configs/+vue2.js +26 -26
- package/lib/configs/+vue3.js +26 -26
- package/lib/configs/+yaml.js +21 -21
- package/lib/configs/base-plugins/eslint-comments.js +10 -10
- package/lib/configs/base-plugins/regexp.js +13 -13
- package/lib/configs/json-schema/config.js +33 -33
- package/lib/configs/recommended.js +254 -246
- package/lib/configs/ts/index.js +15 -15
- package/lib/index.js +29 -29
- package/lib/rules/missing-module-for-config.js +57 -67
- package/lib/utils/find-root-dir.js +15 -15
- package/lib/utils/get-linters.js +22 -22
- package/lib/utils/module.js +48 -51
- package/package.json +56 -57
|
@@ -1,78 +1,68 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const { spawnSync } = require("child_process")
|
|
4
|
-
const getLinters = require("../utils/get-linters")
|
|
5
|
-
const findRootDir = require("../utils/find-root-dir")
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const getLinters = require("../utils/get-linters");
|
|
5
|
+
const findRootDir = require("../utils/find-root-dir");
|
|
6
6
|
|
|
7
|
-
let shouldFix = false
|
|
8
|
-
patch()
|
|
7
|
+
let shouldFix = false;
|
|
8
|
+
patch();
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
fixable: "code", // or "code" or "whitespace"
|
|
18
|
-
schema: [
|
|
19
|
-
{
|
|
20
|
-
type: "array",
|
|
21
|
-
items: { type: "string" },
|
|
22
|
-
},
|
|
23
|
-
],
|
|
11
|
+
meta: {
|
|
12
|
+
type: "problem",
|
|
13
|
+
docs: {
|
|
14
|
+
description: "report missing modules",
|
|
15
|
+
url: "https://github.com/ota-meshi/eslint-plugin",
|
|
24
16
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
17
|
+
fixable: "code", // or "code" or "whitespace"
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
type: "array",
|
|
21
|
+
items: { type: "string" },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
create(context) {
|
|
26
|
+
const modules = context.options[0];
|
|
27
|
+
for (const moduleName of modules) {
|
|
28
|
+
let consoleOutput = "";
|
|
29
|
+
if (shouldFix) {
|
|
30
|
+
const cwd = findRootDir(context.getFilename());
|
|
31
|
+
if (cwd) {
|
|
32
|
+
const result = spawnSync("npm", ["install", "-D", moduleName], {
|
|
33
|
+
cwd,
|
|
34
|
+
windowsHide: true,
|
|
35
|
+
maxBuffer: Infinity,
|
|
36
|
+
});
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
context.report({
|
|
49
|
-
loc: { line: 1, column: 0 },
|
|
50
|
-
message: `Missing module of ${moduleName}. run: \`npm i -D ${moduleName}\`${consoleOutput}`,
|
|
51
|
-
})
|
|
38
|
+
if (result.error) {
|
|
39
|
+
throw result.error;
|
|
40
|
+
}
|
|
41
|
+
consoleOutput = `\n${result.output}`;
|
|
52
42
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
43
|
+
}
|
|
44
|
+
context.report({
|
|
45
|
+
loc: { line: 1, column: 0 },
|
|
46
|
+
message: `Missing module of ${moduleName}. run: \`npm i -D ${moduleName}\`${consoleOutput}`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return {};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
56
52
|
|
|
57
53
|
/** Patch */
|
|
58
54
|
function patch() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
)
|
|
73
|
-
},
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
})
|
|
77
|
-
}
|
|
55
|
+
for (const Linter of getLinters()) {
|
|
56
|
+
const verify0 = Linter.prototype.verify;
|
|
57
|
+
Object.defineProperty(Linter.prototype, "verify", {
|
|
58
|
+
// eslint-disable-next-line no-loop-func -- ignore
|
|
59
|
+
value(textOrSourceCode, config, options, ...args) {
|
|
60
|
+
shouldFix =
|
|
61
|
+
options && typeof options.fix !== "undefined" && options.fix;
|
|
62
|
+
return verify0.call(this, textOrSourceCode, config, options, ...args);
|
|
63
|
+
},
|
|
64
|
+
configurable: true,
|
|
65
|
+
writable: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
78
68
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const fs = require("fs")
|
|
4
|
-
const path = require("path")
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
5
|
|
|
6
6
|
/** Check has package json */
|
|
7
7
|
function hasPackageJson(dir) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const filePath = path.join(dir, "package.json");
|
|
9
|
+
return fs.existsSync(filePath);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
module.exports = function findRootDir(startPath) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
dir = nextDir
|
|
13
|
+
const startDir = path.dirname(path.resolve(startPath));
|
|
14
|
+
let dir = startDir;
|
|
15
|
+
while (!hasPackageJson(dir)) {
|
|
16
|
+
const nextDir = path.dirname(dir);
|
|
17
|
+
if (!nextDir || nextDir === dir) {
|
|
18
|
+
return null;
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
}
|
|
20
|
+
dir = nextDir;
|
|
21
|
+
}
|
|
22
|
+
return dir;
|
|
23
|
+
};
|
package/lib/utils/get-linters.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const path = require("path")
|
|
4
|
-
const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}`;
|
|
5
5
|
|
|
6
6
|
module.exports = () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const eslintPaths = new Set(
|
|
8
|
+
Object.keys(require.cache)
|
|
9
|
+
.filter((id) => id.includes(needle))
|
|
10
|
+
.map((id) => id.slice(0, id.indexOf(needle) + needle.length))
|
|
11
|
+
);
|
|
12
|
+
const linters = [];
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
for (const eslintPath of eslintPaths) {
|
|
15
|
+
try {
|
|
16
|
+
const linter = require(eslintPath).Linter;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
18
|
+
if (linter) {
|
|
19
|
+
linters.push(linter);
|
|
20
|
+
}
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (error.code !== "MODULE_NOT_FOUND") {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
26
25
|
}
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
}
|
|
28
|
+
return linters;
|
|
29
|
+
};
|
package/lib/utils/module.js
CHANGED
|
@@ -1,78 +1,75 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const semver = require("semver")
|
|
3
|
+
const semver = require("semver");
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
has,
|
|
7
|
+
requireOf,
|
|
8
|
+
};
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Checks if exists module
|
|
12
12
|
* @param {string} name
|
|
13
13
|
*/
|
|
14
14
|
function has(name) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const pkg = require(`${parts.slice(0, -1).join("@")}/package.json`)
|
|
20
|
-
return semver.lte(v, pkg.version)
|
|
21
|
-
} catch (_e) {
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
24
|
-
}
|
|
15
|
+
const parts = name.split(/@/u);
|
|
16
|
+
if (parts.length > 1 && parts[0]) {
|
|
17
|
+
const v = parts[parts.length - 1];
|
|
25
18
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
const pkg = require(`${parts.slice(0, -1).join("@")}/package.json`);
|
|
20
|
+
return semver.lte(v, pkg.version);
|
|
28
21
|
} catch (_e) {
|
|
29
|
-
|
|
22
|
+
return false;
|
|
30
23
|
}
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
require.resolve(name);
|
|
27
|
+
return true;
|
|
28
|
+
} catch (_e) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* Checks exists module and return config
|
|
35
35
|
*/
|
|
36
36
|
function requireOf(names, getConfig, fallback) {
|
|
37
|
-
|
|
37
|
+
let missings = names.filter((n) => !has(n));
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
if (missings.length) {
|
|
40
|
+
const fb =
|
|
41
|
+
(typeof fallback === "function"
|
|
42
|
+
? {
|
|
43
|
+
fallback,
|
|
44
|
+
}
|
|
45
|
+
: fallback) || {};
|
|
46
|
+
if (fb.fallback) {
|
|
47
|
+
Object.assign(fb, fb.fallback());
|
|
48
|
+
delete fb.fallback;
|
|
49
|
+
}
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
plugins: ["@ota-meshi"],
|
|
57
|
-
rules: {
|
|
58
|
-
"@ota-meshi/missing-module-for-config": [
|
|
59
|
-
"error",
|
|
60
|
-
missings,
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
|
-
...fb,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
51
|
+
// getFallback, files
|
|
52
|
+
if (fb.files && fb.files.length) {
|
|
53
|
+
return {
|
|
54
|
+
overrides: [
|
|
55
|
+
{
|
|
69
56
|
plugins: ["@ota-meshi"],
|
|
70
57
|
rules: {
|
|
71
|
-
|
|
58
|
+
"@ota-meshi/missing-module-for-config": ["error", missings],
|
|
72
59
|
},
|
|
73
60
|
...fb,
|
|
74
|
-
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
75
64
|
}
|
|
65
|
+
return {
|
|
66
|
+
plugins: ["@ota-meshi"],
|
|
67
|
+
rules: {
|
|
68
|
+
"@ota-meshi/missing-module-for-config": ["error", missings],
|
|
69
|
+
},
|
|
70
|
+
...fb,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
76
73
|
|
|
77
|
-
|
|
74
|
+
return getConfig();
|
|
78
75
|
}
|
package/package.json
CHANGED
|
@@ -1,59 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
}
|
|
2
|
+
"name": "@ota-meshi/eslint-plugin",
|
|
3
|
+
"version": "0.11.3",
|
|
4
|
+
"description": "ESLint configuration plugin for me.",
|
|
5
|
+
"repository": "git+https://github.com/ota-meshi/eslint-plugin.git",
|
|
6
|
+
"homepage": "https://github.com/ota-meshi/eslint-plugin#readme",
|
|
7
|
+
"author": "Yosuke Ota (https://github.com/ota-meshi)",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"JounQin (https://github.com/JounQin)"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"packageManager": "yarn@1.22.19",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^12.20.0 || ^14.14.0 || >=16"
|
|
15
|
+
},
|
|
16
|
+
"main": "lib/index.js",
|
|
17
|
+
"files": [
|
|
18
|
+
"lib"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"lint:fix": "eslint . --fix",
|
|
23
|
+
"test": "mocha \"tests/lib/**/*.js\" --reporter dot --timeout 60000"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"eslint": "^7.0.0 || ^8.0.0",
|
|
27
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
28
|
+
"eslint-plugin-regexp": "^1.0.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"semver": "^7.3.4"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0-0",
|
|
35
|
+
"@typescript-eslint/parser": "^5.0.0-0",
|
|
36
|
+
"eslint": "^8.0.0",
|
|
37
|
+
"eslint-config-prettier": "^8.0.0",
|
|
38
|
+
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
39
|
+
"eslint-plugin-eslint-plugin": "^4.0.0",
|
|
40
|
+
"eslint-plugin-json-schema-validator": "^3.0.0",
|
|
41
|
+
"eslint-plugin-jsonc": "^2.0.0",
|
|
42
|
+
"eslint-plugin-markdown": "^2.0.0",
|
|
43
|
+
"eslint-plugin-node": "^11.1.0",
|
|
44
|
+
"eslint-plugin-node-dependencies": "^0.9.0",
|
|
45
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
46
|
+
"eslint-plugin-regexp": "^1.0.0",
|
|
47
|
+
"eslint-plugin-toml": "^0.3.1",
|
|
48
|
+
"eslint-plugin-vue": "^9.0.0",
|
|
49
|
+
"eslint-plugin-yml": "^1.0.0",
|
|
50
|
+
"mocha": "^10.0.0",
|
|
51
|
+
"prettier": "^2.0.5",
|
|
52
|
+
"prettier-plugin-pkg": "^0.16.0",
|
|
53
|
+
"typescript": "^4.1.5"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
59
58
|
}
|