@ota-meshi/eslint-plugin 0.9.0 → 0.11.1

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.
@@ -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
- meta: {
12
- type: "problem",
13
- docs: {
14
- description: "report missing modules",
15
- url: "https://github.com/ota-meshi/eslint-plugin",
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
- 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(
33
- "npm",
34
- ["install", "-D", moduleName],
35
- {
36
- cwd,
37
- windowsHide: true,
38
- maxBuffer: Infinity,
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
- if (result.error) {
43
- throw result.error
44
- }
45
- consoleOutput = `\n${result.output}`
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
- return {}
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
- for (const Linter of getLinters()) {
60
- const verify0 = Linter.prototype.verify
61
- Object.defineProperty(Linter.prototype, "verify", {
62
- // eslint-disable-next-line no-loop-func -- ignore
63
- value(textOrSourceCode, config, options, ...args) {
64
- shouldFix =
65
- options && typeof options.fix !== "undefined" && options.fix
66
- return verify0.call(
67
- this,
68
- textOrSourceCode,
69
- config,
70
- options,
71
- ...args,
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
- const filePath = path.join(dir, "package.json")
9
- return fs.existsSync(filePath)
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
- 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
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
- return dir
23
- }
20
+ dir = nextDir;
21
+ }
22
+ return dir;
23
+ };
@@ -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
- 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 = []
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
- for (const eslintPath of eslintPaths) {
15
- try {
16
- const linter = require(eslintPath).Linter
14
+ for (const eslintPath of eslintPaths) {
15
+ try {
16
+ const linter = require(eslintPath).Linter;
17
17
 
18
- if (linter) {
19
- linters.push(linter)
20
- }
21
- } catch (error) {
22
- if (error.code !== "MODULE_NOT_FOUND") {
23
- throw error
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
- return linters
29
- }
28
+ return linters;
29
+ };
@@ -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
- has,
7
- requireOf,
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
- const parts = name.split(/@/u)
16
- if (parts.length > 1 && parts[0]) {
17
- const v = parts[parts.length - 1]
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
- require.resolve(name)
27
- return true
19
+ const pkg = require(`${parts.slice(0, -1).join("@")}/package.json`);
20
+ return semver.lte(v, pkg.version);
28
21
  } catch (_e) {
29
- return false
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
- let missings = names.filter((n) => !has(n))
37
+ let missings = names.filter((n) => !has(n));
38
38
 
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
- }
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
- // getFallback, files
52
- if (fb.files && fb.files.length) {
53
- return {
54
- overrides: [
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
- "@ota-meshi/missing-module-for-config": ["error", missings],
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
- return getConfig()
74
+ return getConfig();
78
75
  }
package/package.json CHANGED
@@ -1,59 +1,58 @@
1
1
  {
2
- "name": "@ota-meshi/eslint-plugin",
3
- "version": "0.9.0",
4
- "publishConfig": {
5
- "access": "public"
6
- },
7
- "description": "ESLint configuration plugin for me.",
8
- "main": "lib/index.js",
9
- "engines": {
10
- "node": "^12.20.0 || ^14.14.0 || >=16"
11
- },
12
- "files": [
13
- "lib"
14
- ],
15
- "scripts": {
16
- "lint": "eslint .",
17
- "lint:fix": "eslint . --fix",
18
- "test": "mocha \"tests/lib/**/*.js\" --reporter dot --timeout 60000"
19
- },
20
- "repository": {
21
- "type": "git",
22
- "url": "git+https://github.com/ota-meshi/eslint-plugin.git"
23
- },
24
- "author": "Yosuke Ota",
25
- "license": "MIT",
26
- "bugs": {
27
- "url": "https://github.com/ota-meshi/eslint-plugin/issues"
28
- },
29
- "homepage": "https://github.com/ota-meshi/eslint-plugin#readme",
30
- "peerDependencies": {
31
- "eslint": "^7.0.0",
32
- "eslint-plugin-regexp": "^1.0.0",
33
- "eslint-plugin-eslint-comments": "^3.2.0"
34
- },
35
- "devDependencies": {
36
- "@typescript-eslint/eslint-plugin": "^4.0.0",
37
- "@typescript-eslint/parser": "^4.0.0",
38
- "eslint": "^7.7.0",
39
- "eslint-config-prettier": "^8.0.0",
40
- "eslint-plugin-eslint-comments": "^3.2.0",
41
- "eslint-plugin-eslint-plugin": "^3.0.0",
42
- "eslint-plugin-json-schema-validator": "^1.0.0",
43
- "eslint-plugin-jsonc": "^1.0.0",
44
- "eslint-plugin-markdown": "^2.0.0",
45
- "eslint-plugin-node": "^11.1.0",
46
- "eslint-plugin-node-dependencies": "^0.5.0",
47
- "eslint-plugin-prettier": "^3.1.4",
48
- "eslint-plugin-regexp": "^1.0.0",
49
- "eslint-plugin-toml": "0.2.0",
50
- "eslint-plugin-vue": "^7.0.0-0",
51
- "eslint-plugin-yml": "^0.10.0",
52
- "mocha": "^9.0.0",
53
- "prettier": "^2.0.5",
54
- "typescript": "^4.1.5"
55
- },
56
- "dependencies": {
57
- "semver": "^7.3.4"
58
- }
2
+ "name": "@ota-meshi/eslint-plugin",
3
+ "version": "0.11.1",
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.8.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.14.1",
53
+ "typescript": "^4.1.5"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ }
59
58
  }