-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.npmpackagejsonlint.config.cjs
More file actions
136 lines (124 loc) · 4.62 KB
/
.npmpackagejsonlint.config.cjs
File metadata and controls
136 lines (124 loc) · 4.62 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* NPM Package JSON Lint Configuration (schema-compliant)
*
* Supported top-level keys: ignorePaths, rules.
* Helper utilities & advanced custom validation live in:
* scripts/utility/npm-package-json-lint-helpers.js
*
* Environment variables (optional overrides):
* NPMPKGJSONLINT_IGNORE_PATHS Comma-separated extra ignore paths
* NPMPKGJSONLINT_STRICT_MODE Treat version-format as error (default false)
* NPMPKGJSONLINT_NAME_FORMAT Severity for name-format (default error)
* NPMPKGJSONLINT_REQUIRE_FIELDS Backwards-compatible master toggle (if false, disables all require-* rules)
* NPMPKGJSONLINT_REQUIRE_DESCRIPTION Toggle require-description (default true)
* NPMPKGJSONLINT_REQUIRE_REPOSITORY Toggle require-repository (default true)
* NPMPKGJSONLINT_REQUIRE_LICENSE Toggle require-license (default true)
* NPMPKGJSONLINT_REQUIRE_AUTHOR Toggle require-author (default true)
* NPMPKGJSONLINT_DISABLE_ORDER Disable prefer-property-order rule (default false)
*
* NOTE: Only documented rules supported by npm-package-json-lint v7 are enabled.
*/
require('dotenv').config();
/**
* Parse a comma-separated list environment variable safely.
* @param {string|undefined} raw
* @returns {string[]}
*/
function parseList(raw) {
return raw
? raw
.split(',')
.map((p) => p.trim())
.filter(Boolean)
: [];
}
// Environment-controlled flags
const strictMode = process.env.NPMPKGJSONLINT_STRICT_MODE === 'true';
const nameFormat = process.env.NPMPKGJSONLINT_NAME_FORMAT || 'error';
const requireFields = process.env.NPMPKGJSONLINT_REQUIRE_FIELDS !== 'false';
const requireAuthor = process.env.NPMPKGJSONLINT_REQUIRE_AUTHOR !== 'false';
// Granular required field toggles (fall back to master flag)
const requireDescription =
requireFields && process.env.NPMPKGJSONLINT_REQUIRE_DESCRIPTION !== 'false';
const requireRepository =
requireFields && process.env.NPMPKGJSONLINT_REQUIRE_REPOSITORY !== 'false';
const requireLicense =
requireFields && process.env.NPMPKGJSONLINT_REQUIRE_LICENSE !== 'false';
const disableOrder = process.env.NPMPKGJSONLINT_DISABLE_ORDER === 'true';
const ignorePathsEnv = parseList(process.env.NPMPKGJSONLINT_IGNORE_PATHS);
// Base ignores plus any dynamic additions.
// NOTE: Template scaffold directories removed (2025-10-26); cleaned ignores.
const baseIgnore = [
'node_modules',
'dist',
'build',
'coverage',
'vendor',
'logs',
'.cache',
];
/**
* Property ordering aligned with common metadata before scripts/dependencies.
*/
const preferredOrder = [
'name',
'version',
'description',
'license',
'author',
'repository',
'homepage',
'bugs',
'funding',
'keywords',
'contributors',
'engines',
'type',
'main',
'files',
'scripts',
'dependencies',
'devDependencies',
];
/**
* Exported configuration consumed by npm-package-json-lint.
* Only schema-supported keys are present (ignorePaths, rules).
* Additional custom logic moved to scripts/utility/npm-package-json-lint-helpers.js.
*
* @type {{ ignorePaths: string[]; rules: Record<string, any>; }}
*/
module.exports = {
/**
* Paths excluded from evaluation.
*/
ignorePaths: [...baseIgnore, ...ignorePathsEnv],
/**
* Rules validated against npm-package-json-lint v7.
*/
rules: {
// --- Naming & scope rules ---
'name-format': nameFormat,
// Scope validation for @lightspeedwp organization packages
'valid-values-name-scope': ['error', ['@lightspeedwp']],
// --- Version rules ---
'version-format': strictMode ? 'error' : 'warning',
// --- Required metadata (env toggles) ---
'require-description': requireDescription ? 'error' : 'off',
'require-license': requireLicense ? 'error' : 'off',
'require-repository': requireRepository ? 'error' : 'off',
'require-author': requireAuthor ? 'error' : 'off',
// --- Type checks (low risk, ensure JSON shape consistency) ---
'description-type': 'error',
'license-type': 'error',
'repository-type': 'error',
'keywords-type': 'error',
// --- Ordering (optional) ---
'prefer-property-order': disableOrder
? 'off'
: ['warning', preferredOrder],
// --- License values ---
'valid-values-license': ['error', ['GPL-3.0-or-later']],
},
};
// JSDoc compliance note: All functions & top-level structures documented. Additional
// custom validators now reside in scripts/utility/npm-package-json-lint-helpers.js.