eslint-plugin-node-dependencies 0.6.0 → 0.7.0
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/README.md +1 -0
- package/dist/rules/absolute-version.js +156 -0
- package/dist/utils/regexp.js +21 -0
- package/dist/utils/rules.js +2 -0
- package/dist/utils/semver.js +6 -2
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -125,6 +125,7 @@ The rules with the following star :star: are included in the `plugin:node-depend
|
|
|
125
125
|
|
|
126
126
|
| Rule ID | Description | |
|
|
127
127
|
|:--------|:------------|:---|
|
|
128
|
+
| [node-dependencies/absolute-version](https://ota-meshi.github.io/eslint-plugin-node-dependencies/rules/absolute-version.html) | require or disallow absolute version of dependency. | |
|
|
128
129
|
| [node-dependencies/no-deprecated](https://ota-meshi.github.io/eslint-plugin-node-dependencies/rules/no-deprecated.html) | disallow having dependencies on deprecate packages. | |
|
|
129
130
|
|
|
130
131
|
### Deprecated
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsonc_eslint_parser_1 = require("jsonc-eslint-parser");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const ast_utils_1 = require("../utils/ast-utils");
|
|
6
|
+
const regexp_1 = require("../utils/regexp");
|
|
7
|
+
const semver_1 = require("../utils/semver");
|
|
8
|
+
const PREFERS = ["always", "never", "ignore"];
|
|
9
|
+
const SCHEMA_FOR_DEPS_PROPERTIES = {
|
|
10
|
+
dependencies: { enum: PREFERS },
|
|
11
|
+
peerDependencies: { enum: PREFERS },
|
|
12
|
+
optionalDependencies: { enum: PREFERS },
|
|
13
|
+
devDependencies: { enum: PREFERS },
|
|
14
|
+
};
|
|
15
|
+
const DEFAULT = {
|
|
16
|
+
dependencies: "ignore",
|
|
17
|
+
peerDependencies: "ignore",
|
|
18
|
+
optionalDependencies: "ignore",
|
|
19
|
+
devDependencies: "always",
|
|
20
|
+
};
|
|
21
|
+
function stringToOption(option) {
|
|
22
|
+
return {
|
|
23
|
+
dependencies: option,
|
|
24
|
+
peerDependencies: option,
|
|
25
|
+
optionalDependencies: option,
|
|
26
|
+
devDependencies: option,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function objectToOption(option, defaults) {
|
|
30
|
+
return {
|
|
31
|
+
dependencies: option.dependencies || defaults.dependencies,
|
|
32
|
+
peerDependencies: option.peerDependencies || defaults.peerDependencies,
|
|
33
|
+
optionalDependencies: option.optionalDependencies || defaults.optionalDependencies,
|
|
34
|
+
devDependencies: option.devDependencies || defaults.devDependencies,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function parseOption(option) {
|
|
38
|
+
if (!option) {
|
|
39
|
+
return () => DEFAULT;
|
|
40
|
+
}
|
|
41
|
+
if (typeof option === "string") {
|
|
42
|
+
const objectOption = stringToOption(option);
|
|
43
|
+
return () => objectOption;
|
|
44
|
+
}
|
|
45
|
+
const baseOption = objectToOption(option, DEFAULT);
|
|
46
|
+
if (!option.overridePackages) {
|
|
47
|
+
return () => baseOption;
|
|
48
|
+
}
|
|
49
|
+
const overridePackages = Object.entries(option.overridePackages).map(([packageName, opt]) => {
|
|
50
|
+
const regexp = (0, regexp_1.toRegExp)(packageName);
|
|
51
|
+
return Object.assign({ test: (s) => regexp.test(s) }, (typeof opt === "string"
|
|
52
|
+
? stringToOption(opt)
|
|
53
|
+
: objectToOption(opt, baseOption)));
|
|
54
|
+
});
|
|
55
|
+
return (name) => {
|
|
56
|
+
for (const overridePackage of overridePackages) {
|
|
57
|
+
if (overridePackage.test(name)) {
|
|
58
|
+
return overridePackage;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return baseOption;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.default = (0, utils_1.createRule)("absolute-version", {
|
|
65
|
+
meta: {
|
|
66
|
+
docs: {
|
|
67
|
+
description: "require or disallow absolute version of dependency.",
|
|
68
|
+
category: "Best Practices",
|
|
69
|
+
recommended: false,
|
|
70
|
+
},
|
|
71
|
+
schema: [
|
|
72
|
+
{
|
|
73
|
+
oneOf: [
|
|
74
|
+
{ enum: PREFERS.filter((p) => p !== "ignore") },
|
|
75
|
+
{
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: Object.assign(Object.assign({}, SCHEMA_FOR_DEPS_PROPERTIES), { overridePackages: {
|
|
78
|
+
type: "object",
|
|
79
|
+
patternProperties: {
|
|
80
|
+
"^(?:\\S+)$": {
|
|
81
|
+
oneOf: [
|
|
82
|
+
{ enum: PREFERS },
|
|
83
|
+
{
|
|
84
|
+
type: "object",
|
|
85
|
+
properties: SCHEMA_FOR_DEPS_PROPERTIES,
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
minProperties: 1,
|
|
92
|
+
additionalProperties: false,
|
|
93
|
+
} }),
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
messages: {},
|
|
100
|
+
type: "suggestion",
|
|
101
|
+
},
|
|
102
|
+
create(context) {
|
|
103
|
+
const getOption = parseOption(context.options[0]);
|
|
104
|
+
function defineVisitor(visitName) {
|
|
105
|
+
return (node) => {
|
|
106
|
+
const ver = (0, jsonc_eslint_parser_1.getStaticJSONValue)(node.value);
|
|
107
|
+
if (typeof ver !== "string" || ver == null) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const name = String((0, ast_utils_1.getKeyFromJSONProperty)(node));
|
|
111
|
+
const option = getOption(name)[visitName];
|
|
112
|
+
const semver = (0, semver_1.getSemverRange)(ver);
|
|
113
|
+
if (semver == null) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (option === "always") {
|
|
117
|
+
if (isAbsoluteVersion(semver)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
context.report({
|
|
121
|
+
loc: node.value.loc,
|
|
122
|
+
message: "Use the absolute version instead.",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else if (option === "never") {
|
|
126
|
+
if (!isAbsoluteVersion(semver)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
context.report({
|
|
130
|
+
loc: node.value.loc,
|
|
131
|
+
message: "Do not use the absolute version.",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return (0, utils_1.defineJsonVisitor)({
|
|
137
|
+
dependencies: defineVisitor("dependencies"),
|
|
138
|
+
peerDependencies: defineVisitor("peerDependencies"),
|
|
139
|
+
optionalDependencies: defineVisitor("optionalDependencies"),
|
|
140
|
+
devDependencies: defineVisitor("devDependencies"),
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
function isAbsoluteVersion(semver) {
|
|
145
|
+
for (const comparators of semver.set) {
|
|
146
|
+
for (const comparator of comparators) {
|
|
147
|
+
if ((0, semver_1.isAnyComparator)(comparator)) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (comparator.operator !== "=" && comparator.operator !== "") {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toRegExp = void 0;
|
|
4
|
+
function toRegExp(str) {
|
|
5
|
+
const regexp = parseRegExp(str);
|
|
6
|
+
if (regexp) {
|
|
7
|
+
return regexp;
|
|
8
|
+
}
|
|
9
|
+
return { test: (s) => s === str };
|
|
10
|
+
}
|
|
11
|
+
exports.toRegExp = toRegExp;
|
|
12
|
+
function parseRegExp(str) {
|
|
13
|
+
if (!str.startsWith("/")) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const lastSlashIndex = str.lastIndexOf("/");
|
|
17
|
+
if (lastSlashIndex <= 1) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return new RegExp(str.slice(1, lastSlashIndex), str.slice(lastSlashIndex + 1));
|
|
21
|
+
}
|
package/dist/utils/rules.js
CHANGED
|
@@ -4,11 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.rules = void 0;
|
|
7
|
+
const absolute_version_1 = __importDefault(require("../rules/absolute-version"));
|
|
7
8
|
const compat_engines_1 = __importDefault(require("../rules/compat-engines"));
|
|
8
9
|
const no_deprecated_1 = __importDefault(require("../rules/no-deprecated"));
|
|
9
10
|
const valid_engines_1 = __importDefault(require("../rules/valid-engines"));
|
|
10
11
|
const valid_semver_1 = __importDefault(require("../rules/valid-semver"));
|
|
11
12
|
exports.rules = [
|
|
13
|
+
absolute_version_1.default,
|
|
12
14
|
compat_engines_1.default,
|
|
13
15
|
no_deprecated_1.default,
|
|
14
16
|
valid_engines_1.default,
|
package/dist/utils/semver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.maxNextVersion = exports.normalizeSemverRange = exports.normalizeVer = exports.getSemverRange = void 0;
|
|
3
|
+
exports.isAnyComparator = exports.maxNextVersion = exports.normalizeSemverRange = exports.normalizeVer = exports.getSemverRange = void 0;
|
|
4
4
|
const semver_1 = require("semver");
|
|
5
5
|
function getSemverRange(value) {
|
|
6
6
|
if (value == null) {
|
|
@@ -171,7 +171,7 @@ function maxNextVersion(range) {
|
|
|
171
171
|
let max = null;
|
|
172
172
|
let hasMin = false;
|
|
173
173
|
for (const comparator of comparators) {
|
|
174
|
-
if (
|
|
174
|
+
if (isAnyComparator(comparator)) {
|
|
175
175
|
return null;
|
|
176
176
|
}
|
|
177
177
|
const compVer = new semver_1.SemVer(comparator.semver.version);
|
|
@@ -204,3 +204,7 @@ function maxNextVersion(range) {
|
|
|
204
204
|
return maxVer;
|
|
205
205
|
}
|
|
206
206
|
exports.maxNextVersion = maxNextVersion;
|
|
207
|
+
function isAnyComparator(comparator) {
|
|
208
|
+
return !comparator.semver.version;
|
|
209
|
+
}
|
|
210
|
+
exports.isAnyComparator = isAnyComparator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-node-dependencies",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "ESLint plugin to check Node.js dependencies.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^12 || >=14"
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"json"
|
|
42
42
|
],
|
|
43
43
|
"author": "Yosuke Ota (https://github.com/ota-meshi)",
|
|
44
|
+
"funding": "https://github.com/sponsors/ota-meshi",
|
|
44
45
|
"license": "MIT",
|
|
45
46
|
"bugs": {
|
|
46
47
|
"url": "https://github.com/ota-meshi/eslint-plugin-node-dependencies/issues"
|
|
@@ -52,10 +53,10 @@
|
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@ota-meshi/eslint-plugin": "^0.10.0",
|
|
54
55
|
"@types/chai": "^4.2.18",
|
|
55
|
-
"@types/eslint": "^
|
|
56
|
+
"@types/eslint": "^8.0.0",
|
|
56
57
|
"@types/eslint-scope": "^3.7.0",
|
|
57
58
|
"@types/eslint-visitor-keys": "^1.0.0",
|
|
58
|
-
"@types/estree": "^0.0.
|
|
59
|
+
"@types/estree": "^0.0.51",
|
|
59
60
|
"@types/mocha": "^9.0.0",
|
|
60
61
|
"@types/node": "^16.0.0",
|
|
61
62
|
"@types/npm-package-arg": "^6.1.1",
|
|
@@ -68,14 +69,14 @@
|
|
|
68
69
|
"eslint-config-prettier": "^8.0.0",
|
|
69
70
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
70
71
|
"eslint-plugin-eslint-plugin": "^4.0.0",
|
|
71
|
-
"eslint-plugin-json-schema-validator": "^
|
|
72
|
+
"eslint-plugin-json-schema-validator": "^2.0.0",
|
|
72
73
|
"eslint-plugin-jsonc": "^2.0.0",
|
|
73
74
|
"eslint-plugin-node": "^11.1.0",
|
|
74
|
-
"eslint-plugin-node-dependencies": "^0.
|
|
75
|
+
"eslint-plugin-node-dependencies": "^0.6.0",
|
|
75
76
|
"eslint-plugin-prettier": "^4.0.0",
|
|
76
77
|
"eslint-plugin-regexp": "^1.0.0",
|
|
77
78
|
"eslint-plugin-vue": "^8.0.0",
|
|
78
|
-
"eslint-plugin-yml": "^0.
|
|
79
|
+
"eslint-plugin-yml": "^0.14.0",
|
|
79
80
|
"eslint4b": "^7.3.1",
|
|
80
81
|
"mocha": "^9.0.0",
|
|
81
82
|
"mocha-chai-jest-snapshot": "^1.1.2",
|
|
@@ -84,7 +85,7 @@
|
|
|
84
85
|
"raw-loader": "^4.0.1",
|
|
85
86
|
"stylelint": "^14.0.0",
|
|
86
87
|
"stylelint-config-recommended-vue": "^1.0.0",
|
|
87
|
-
"stylelint-config-standard": "^
|
|
88
|
+
"stylelint-config-standard": "^25.0.0",
|
|
88
89
|
"stylelint-plugin-stylus": "^0.13.0",
|
|
89
90
|
"ts-node": "^10.0.0",
|
|
90
91
|
"typescript": "^4.0.0",
|