npm-pkg-lint 5.3.0 → 5.3.2
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 +2 -2
- package/dist/index.js +101 -91
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# NPM Package linting
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ext/npm-pkg-lint/actions?query=workflow%3ABuild)
|
|
4
|
-
[](https://coveralls.io/github/ext/npm-pkg-lint?branch=main)
|
|
5
5
|
|
|
6
6
|
Opinionated linter for NPM package tarball and `package.json` metadata.
|
|
7
7
|
|
|
@@ -68,7 +68,7 @@ This tool can be used directly with Github Actions:
|
|
|
68
68
|
- name: Setup Node.js
|
|
69
69
|
uses: actions/setup-node@v4
|
|
70
70
|
- name: npm-pkg-lint
|
|
71
|
-
uses: ext/npm-pkg-lint@
|
|
71
|
+
uses: ext/npm-pkg-lint@v5.3.0
|
|
72
72
|
```
|
|
73
73
|
|
|
74
74
|
> [!IMPORTANT]
|
package/dist/index.js
CHANGED
|
@@ -2421,7 +2421,11 @@ var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
|
2421
2421
|
var __getProtoOf2 = Object.getPrototypeOf;
|
|
2422
2422
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
2423
2423
|
var __commonJS2 = (cb, mod) => function __require2() {
|
|
2424
|
-
|
|
2424
|
+
try {
|
|
2425
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
2426
|
+
} catch (e) {
|
|
2427
|
+
throw mod = 0, e;
|
|
2428
|
+
}
|
|
2425
2429
|
};
|
|
2426
2430
|
var __copyProps2 = (to2, from, except, desc) => {
|
|
2427
2431
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -2534,12 +2538,11 @@ function yellow(value) {
|
|
|
2534
2538
|
function red(value) {
|
|
2535
2539
|
return styleText("red", value);
|
|
2536
2540
|
}
|
|
2537
|
-
var Severity =
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
})(Severity || {});
|
|
2541
|
+
var Severity = {
|
|
2542
|
+
OFF: 0,
|
|
2543
|
+
WARN: 1,
|
|
2544
|
+
ERROR: 2
|
|
2545
|
+
};
|
|
2543
2546
|
function pluralize(word, count) {
|
|
2544
2547
|
return count === 1 ? word : `${word}s`;
|
|
2545
2548
|
}
|
|
@@ -2547,7 +2550,7 @@ function centerLineColumn(el) {
|
|
|
2547
2550
|
return el.replace(/(\d+)\s+(\d+)/u, (_m, p1, p2) => dim(`${p1}:${p2}`));
|
|
2548
2551
|
}
|
|
2549
2552
|
function stripAnsi(text) {
|
|
2550
|
-
return text.replaceAll(/\
|
|
2553
|
+
return text.replaceAll(/\u{001B}\[[\d;]*m/gu, "");
|
|
2551
2554
|
}
|
|
2552
2555
|
function stylish(results) {
|
|
2553
2556
|
let output = "\n";
|
|
@@ -2567,7 +2570,7 @@ function stylish(results) {
|
|
|
2567
2570
|
fixableWarningCount += result.fixableWarningCount;
|
|
2568
2571
|
const rows = messages.map((message) => {
|
|
2569
2572
|
let messageType;
|
|
2570
|
-
if (Boolean(message.fatal) || message.severity ===
|
|
2573
|
+
if (Boolean(message.fatal) || message.severity === Severity.ERROR) {
|
|
2571
2574
|
messageType = red("error");
|
|
2572
2575
|
summaryColor = red;
|
|
2573
2576
|
} else {
|
|
@@ -8643,11 +8646,11 @@ function* outdatedEngines(pkg, pkgAst, ignoreNodeVersion) {
|
|
|
8643
8646
|
if (ignoreNodeVersion === true) {
|
|
8644
8647
|
return;
|
|
8645
8648
|
}
|
|
8646
|
-
for (const [
|
|
8649
|
+
for (const [version3, descriptor] of nodeVersions) {
|
|
8647
8650
|
if (!descriptor.eol) {
|
|
8648
8651
|
break;
|
|
8649
8652
|
}
|
|
8650
|
-
const expanded =
|
|
8653
|
+
const expanded = version3.replaceAll(/[*X]/gi, "999");
|
|
8651
8654
|
if (!import_semver2.default.satisfies(expanded, range)) {
|
|
8652
8655
|
continue;
|
|
8653
8656
|
}
|
|
@@ -8657,28 +8660,29 @@ function* outdatedEngines(pkg, pkgAst, ignoreNodeVersion) {
|
|
|
8657
8660
|
return;
|
|
8658
8661
|
}
|
|
8659
8662
|
const nodeRelease = major > 0 ? major : `0.${String(minor)}`;
|
|
8660
|
-
const
|
|
8663
|
+
const message2 = `engines.node is satisfied by Node ${String(nodeRelease)} (EOL since ${descriptor.eol})`;
|
|
8661
8664
|
yield {
|
|
8662
8665
|
ruleId: ruleId9,
|
|
8663
8666
|
severity: severity7,
|
|
8664
|
-
message,
|
|
8667
|
+
message: message2,
|
|
8665
8668
|
line,
|
|
8666
8669
|
column
|
|
8667
8670
|
};
|
|
8668
8671
|
return;
|
|
8669
8672
|
}
|
|
8670
|
-
if (typeof ignoreNodeVersion
|
|
8671
|
-
|
|
8672
|
-
const version2 = `v${String(ignoreNodeVersion)}.x`;
|
|
8673
|
-
const message = `--ignore-node-version=${option} used but engines.node="${range}" does not match ${version2} or the version is not EOL yet`;
|
|
8674
|
-
yield {
|
|
8675
|
-
ruleId: ruleId9,
|
|
8676
|
-
severity: severity7,
|
|
8677
|
-
message,
|
|
8678
|
-
line,
|
|
8679
|
-
column
|
|
8680
|
-
};
|
|
8673
|
+
if (typeof ignoreNodeVersion !== "number") {
|
|
8674
|
+
return;
|
|
8681
8675
|
}
|
|
8676
|
+
const option = String(ignoreNodeVersion);
|
|
8677
|
+
const version2 = `v${String(ignoreNodeVersion)}.x`;
|
|
8678
|
+
const message = `--ignore-node-version=${option} used but engines.node="${range}" does not match ${version2} or the version is not EOL yet`;
|
|
8679
|
+
yield {
|
|
8680
|
+
ruleId: ruleId9,
|
|
8681
|
+
severity: severity7,
|
|
8682
|
+
message,
|
|
8683
|
+
line,
|
|
8684
|
+
column
|
|
8685
|
+
};
|
|
8682
8686
|
}
|
|
8683
8687
|
|
|
8684
8688
|
// src/rules/prefer-types.ts
|
|
@@ -8777,30 +8781,31 @@ function* tsconfigBaseMatchingEngine(pkg, pkgAst) {
|
|
|
8777
8781
|
const [first, ...duplicates] = tsconfig;
|
|
8778
8782
|
if (duplicates.length > 0) {
|
|
8779
8783
|
for (const dup of duplicates) {
|
|
8780
|
-
const { line, column } = jsonLocation(pkgAst, "member", source, dup);
|
|
8784
|
+
const { line: line2, column: column2 } = jsonLocation(pkgAst, "member", source, dup);
|
|
8781
8785
|
yield {
|
|
8782
8786
|
ruleId: ruleId12,
|
|
8783
8787
|
severity: severity10,
|
|
8784
8788
|
message: `${dup} and ${first} cannot be used at the same time`,
|
|
8785
|
-
line,
|
|
8786
|
-
column
|
|
8789
|
+
line: line2,
|
|
8790
|
+
column: column2
|
|
8787
8791
|
};
|
|
8788
8792
|
}
|
|
8789
8793
|
continue;
|
|
8790
8794
|
}
|
|
8791
8795
|
const match2 = matchDependency.exec(first);
|
|
8792
8796
|
const baseVersion = Number(match2[1]);
|
|
8793
|
-
if (baseVersion
|
|
8794
|
-
|
|
8795
|
-
const expectedVersion = `v${String(nodeVersion.major)}`;
|
|
8796
|
-
yield {
|
|
8797
|
-
ruleId: ruleId12,
|
|
8798
|
-
severity: severity10,
|
|
8799
|
-
message: `${first} does not match engines.node ${expectedVersion}`,
|
|
8800
|
-
line,
|
|
8801
|
-
column
|
|
8802
|
-
};
|
|
8797
|
+
if (baseVersion === nodeVersion.major) {
|
|
8798
|
+
continue;
|
|
8803
8799
|
}
|
|
8800
|
+
const { line, column } = jsonLocation(pkgAst, "member", source, first);
|
|
8801
|
+
const expectedVersion = `v${String(nodeVersion.major)}`;
|
|
8802
|
+
yield {
|
|
8803
|
+
ruleId: ruleId12,
|
|
8804
|
+
severity: severity10,
|
|
8805
|
+
message: `${first} does not match engines.node ${expectedVersion}`,
|
|
8806
|
+
line,
|
|
8807
|
+
column
|
|
8808
|
+
};
|
|
8804
8809
|
}
|
|
8805
8810
|
}
|
|
8806
8811
|
|
|
@@ -8826,18 +8831,19 @@ function* typesNodeMatchingEngine(pkg, pkgAst) {
|
|
|
8826
8831
|
if (!nodeVersion || !typesVersion) {
|
|
8827
8832
|
continue;
|
|
8828
8833
|
}
|
|
8829
|
-
if (typesVersion.major
|
|
8830
|
-
|
|
8831
|
-
const actualVersion = `v${String(typesVersion.major)}`;
|
|
8832
|
-
const expectedVersion = `v${String(nodeVersion.major)}`;
|
|
8833
|
-
yield {
|
|
8834
|
-
ruleId: ruleId13,
|
|
8835
|
-
severity: severity11,
|
|
8836
|
-
message: `@types/node ${actualVersion} does not equal engines.node ${expectedVersion}`,
|
|
8837
|
-
line,
|
|
8838
|
-
column
|
|
8839
|
-
};
|
|
8834
|
+
if (typesVersion.major === nodeVersion.major) {
|
|
8835
|
+
continue;
|
|
8840
8836
|
}
|
|
8837
|
+
const { line, column } = jsonLocation(pkgAst, "value", source, "@types/node");
|
|
8838
|
+
const actualVersion = `v${String(typesVersion.major)}`;
|
|
8839
|
+
const expectedVersion = `v${String(nodeVersion.major)}`;
|
|
8840
|
+
yield {
|
|
8841
|
+
ruleId: ruleId13,
|
|
8842
|
+
severity: severity11,
|
|
8843
|
+
message: `@types/node ${actualVersion} does not equal engines.node ${expectedVersion}`,
|
|
8844
|
+
line,
|
|
8845
|
+
column
|
|
8846
|
+
};
|
|
8841
8847
|
}
|
|
8842
8848
|
}
|
|
8843
8849
|
|
|
@@ -8957,11 +8963,12 @@ function nonempty(key, value) {
|
|
|
8957
8963
|
}
|
|
8958
8964
|
return;
|
|
8959
8965
|
}
|
|
8960
|
-
if (value
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8966
|
+
if (!value || typeof value !== "object") {
|
|
8967
|
+
return;
|
|
8968
|
+
}
|
|
8969
|
+
const values = Object.values(value);
|
|
8970
|
+
if (values.length === 0) {
|
|
8971
|
+
throw new ValidationError(nonempty.name, `"${key}" must not be empty`);
|
|
8965
8972
|
}
|
|
8966
8973
|
}
|
|
8967
8974
|
|
|
@@ -9128,32 +9135,34 @@ function verifyDependencies(pkg, pkgAst, options) {
|
|
|
9128
9135
|
if (options.allowTypesDependencies && dependency.startsWith("@types/")) {
|
|
9129
9136
|
continue;
|
|
9130
9137
|
}
|
|
9131
|
-
if (isDisallowedDependency(pkg, dependency)) {
|
|
9132
|
-
|
|
9133
|
-
const name = key === dependency ? `"${dependency}"` : `"${key}" ("npm:${dependency}")`;
|
|
9134
|
-
messages.push({
|
|
9135
|
-
ruleId: "disallowed-dependency",
|
|
9136
|
-
severity: 2,
|
|
9137
|
-
message: `${name} should be a devDependency`,
|
|
9138
|
-
line,
|
|
9139
|
-
column
|
|
9140
|
-
});
|
|
9138
|
+
if (!isDisallowedDependency(pkg, dependency)) {
|
|
9139
|
+
continue;
|
|
9141
9140
|
}
|
|
9141
|
+
const { line, column } = jsonLocation(pkgAst, "member", "dependencies", key);
|
|
9142
|
+
const name = key === dependency ? `"${dependency}"` : `"${key}" ("npm:${dependency}")`;
|
|
9143
|
+
messages.push({
|
|
9144
|
+
ruleId: "disallowed-dependency",
|
|
9145
|
+
severity: 2,
|
|
9146
|
+
message: `${name} should be a devDependency`,
|
|
9147
|
+
line,
|
|
9148
|
+
column
|
|
9149
|
+
});
|
|
9142
9150
|
}
|
|
9143
9151
|
function verifyObsolete(key, version2, source) {
|
|
9144
9152
|
const { name: dependency } = normalizeDependency(key, version2);
|
|
9145
9153
|
const obsolete2 = isObsoleteDependency(dependency);
|
|
9146
|
-
if (obsolete2) {
|
|
9147
|
-
|
|
9148
|
-
const name = key === dependency ? `"${dependency}"` : `"${key}" ("npm:${dependency}")`;
|
|
9149
|
-
messages.push({
|
|
9150
|
-
ruleId: "obsolete-dependency",
|
|
9151
|
-
severity: 2,
|
|
9152
|
-
message: `${name} is obsolete and should no longer be used: ${obsolete2.message}`,
|
|
9153
|
-
line,
|
|
9154
|
-
column
|
|
9155
|
-
});
|
|
9154
|
+
if (!obsolete2) {
|
|
9155
|
+
return;
|
|
9156
9156
|
}
|
|
9157
|
+
const { line, column } = jsonLocation(pkgAst, "member", source, key);
|
|
9158
|
+
const name = key === dependency ? `"${dependency}"` : `"${key}" ("npm:${dependency}")`;
|
|
9159
|
+
messages.push({
|
|
9160
|
+
ruleId: "obsolete-dependency",
|
|
9161
|
+
severity: 2,
|
|
9162
|
+
message: `${name} is obsolete and should no longer be used: ${obsolete2.message}`,
|
|
9163
|
+
line,
|
|
9164
|
+
column
|
|
9165
|
+
});
|
|
9157
9166
|
}
|
|
9158
9167
|
for (const [key, version2] of Object.entries(dependencies)) {
|
|
9159
9168
|
verifyObsolete(key, version2, "dependencies");
|
|
@@ -9264,25 +9273,26 @@ async function verifyPackageLock() {
|
|
|
9264
9273
|
if (pkg.link) {
|
|
9265
9274
|
continue;
|
|
9266
9275
|
}
|
|
9267
|
-
if (
|
|
9268
|
-
|
|
9269
|
-
results.push({
|
|
9270
|
-
messages: [
|
|
9271
|
-
{
|
|
9272
|
-
ruleId: "package-lock-registry",
|
|
9273
|
-
severity: 2,
|
|
9274
|
-
message: `package "${name}" is resolved from "${String(pkg.resolved)}" instead of the npm registry`,
|
|
9275
|
-
line,
|
|
9276
|
-
column
|
|
9277
|
-
}
|
|
9278
|
-
],
|
|
9279
|
-
filePath: lockfilePath,
|
|
9280
|
-
errorCount: 1,
|
|
9281
|
-
warningCount: 0,
|
|
9282
|
-
fixableErrorCount: 0,
|
|
9283
|
-
fixableWarningCount: 0
|
|
9284
|
-
});
|
|
9276
|
+
if (isValidResolved(pkg)) {
|
|
9277
|
+
continue;
|
|
9285
9278
|
}
|
|
9279
|
+
const { line, column } = jsonLocation(ast, "value", "packages", name, "resolved");
|
|
9280
|
+
results.push({
|
|
9281
|
+
messages: [
|
|
9282
|
+
{
|
|
9283
|
+
ruleId: "package-lock-registry",
|
|
9284
|
+
severity: 2,
|
|
9285
|
+
message: `package "${name}" is resolved from "${String(pkg.resolved)}" instead of the npm registry`,
|
|
9286
|
+
line,
|
|
9287
|
+
column
|
|
9288
|
+
}
|
|
9289
|
+
],
|
|
9290
|
+
filePath: lockfilePath,
|
|
9291
|
+
errorCount: 1,
|
|
9292
|
+
warningCount: 0,
|
|
9293
|
+
fixableErrorCount: 0,
|
|
9294
|
+
fixableWarningCount: 0
|
|
9295
|
+
});
|
|
9286
9296
|
}
|
|
9287
9297
|
return results;
|
|
9288
9298
|
}
|