Skip to content

Commit e205db8

Browse files
committed
chore(lint/docs): add granular npm-package-json-lint env toggles, enable CI step, and standardize doc link guidance
- add NPMPKGJSONLINT_REQUIRE_* and NPMPKGJSONLINT_DISABLE_ORDER vars to .env.example - support granular require toggles in npmpackagejsonlint.config.cjs; relax scope/license enforcement - update package.json script to use config file and remove forced disable-order flag - run npm-package-json-lint in CI (add step and env defaults in .github/workflows/lint.yml) - document npm-package-json-lint env vars, examples, and usage in docs/LINTING.md - consolidate universal repo-local link guidance (/blob/HEAD/) across docs instructions (docs, readme, markdown-style-guide, coding-standards)
1 parent 69551f6 commit e205db8

File tree

9 files changed

+207
-37
lines changed

9 files changed

+207
-37
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ NPMPKGJSONLINT_NAME_FORMAT=error
172172
# Enable required fields validation (default: true)
173173
NPMPKGJSONLINT_REQUIRE_FIELDS=true
174174

175+
# Granular required metadata toggles (override master NPMPKGJSONLINT_REQUIRE_FIELDS)
176+
# Set any of these to "false" to disable a single required rule while leaving others on.
177+
NPMPKGJSONLINT_REQUIRE_DESCRIPTION=true
178+
NPMPKGJSONLINT_REQUIRE_REPOSITORY=true
179+
NPMPKGJSONLINT_REQUIRE_LICENSE=true
180+
NPMPKGJSONLINT_REQUIRE_AUTHOR=true
181+
182+
# Disable property ordering enforcement (prefer-property-order rule)
183+
NPMPKGJSONLINT_DISABLE_ORDER=false
184+
175185
# =============================================================================
176186
# Stylelint Configuration
177187
# =============================================================================

.github/instructions/coding-standards.instructions.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ This document is the single source of truth for all coding standards in LightSpe
9191

9292
## Documentation Standards
9393

94-
- All docs must use Markdown, be linted, and follow [markdownlint](https://github.com/DavidAnson/markdownlint) rules.
95-
- All public functions/classes must have docblocks or docstrings.
96-
- Inline documentation must be clear and reference related files or standards.
97-
98-
---
94+
All documentation links to files within the same repository should use `/blob/HEAD/` in URLs to ensure universality across branches and avoid broken links after merges. Always validate links after editing documentation.
9995

10096
## AI & Copilot Instructions
10197

@@ -116,4 +112,4 @@ This document is the single source of truth for all coding standards in LightSpe
116112
---
117113

118114
_This file is the canonical reference for all code, documentation, and automation standards in LightSpeedWP projects.
119-
All contributors, agents, and AI assistants must comply with these standards._
115+
All contributors, agents, and AI assistants must comply with these standards._
Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,111 @@
11
# Documentation Instructions
22

33
## Expectations
4-
- Update README when behaviour changes.
5-
- For patterns: add screenshot, purpose, usage notes, a11y notes.
6-
- Maintain CHANGELOG entries for user-visible changes.
4+
5+
- All documentation must comply with the standards below and respect the references and cross-linking conventions for every document created or updated.
6+
- Every `.md` file in `docs/` and its subfolders must include YAML frontmatter, clear structure, accessibility, and cross-references as described.
77

88
## Structure
9-
- Keep docs close to code; link from `README.md` to pattern/block docs.
9+
10+
All cross-references and file links must be universal. Avoid branch-specific links unless necessary for historical context. Use `/blob/HEAD/` for repo-local files.
11+
12+
---
13+
14+
# Universal Documentation Standards for `.md` Files
15+
16+
## 1. Frontmatter
17+
18+
Every documentation file should start with YAML frontmatter including:
19+
20+
- `title`: Document title (required)
21+
- `description`: Brief summary of the file’s purpose (required)
22+
- `last_updated`: Date of last meaningful update (required)
23+
- `owners`: Responsible maintainers or teams (required)
24+
- `references`: Related files, specs, or external resources (required; must be real, repo-relative links)
25+
26+
## 2. Structure & Headings
27+
28+
- Use clear, hierarchical headings (`#`, `##`, `###`) for logical organization.
29+
- Include a Table of Contents for files longer than ~100 lines.
30+
- Start with an **Overview** or **Purpose** section.
31+
32+
## 3. Clarity & Language
33+
34+
- Use plain, concise language.
35+
- Avoid jargon unless defined.
36+
- Prefer UK English (per org standards).
37+
38+
## 4. Navigation & Cross-References
39+
40+
- Reference parent indexes and related docs (see `CHECKLIST_CROSSLINKING.md`).
41+
- Ensure bidirectional and lateral links—no dead ends.
42+
- All references must be respected and validated for every document.
43+
- Use `/blob/HEAD/` for repo-local files and relative links for files within the same repo.
44+
45+
## 5. Formatting & Accessibility
46+
47+
- Follow [WCAG 2.2 AA](https://www.w3.org/TR/WCAG22/) and a11y.instructions.md.
48+
- Use lists, tables, and code blocks for clarity.
49+
- Add alt text to images and diagrams.
50+
- Ensure headings and lists are properly spaced for readability.
51+
- Use badges for status, coverage, or compliance where relevant.
52+
- Run markdownlint and Prettier for formatting compliance.
53+
54+
## 6. Diagrams & Visuals
55+
56+
- Use Mermaid diagrams for workflows, architecture, or processes.
57+
- Include screenshots or illustrations where helpful.
58+
59+
## 7. Examples & Usage
60+
61+
- Provide code examples, sample commands, or usage scenarios.
62+
- For configuration or scripts, show input/output and expected results.
63+
64+
## 8. Validation & Testing
65+
66+
- Document how to validate, test, or review the content (e.g., linting, schema checks).
67+
- Validate all links and references after every edit.
68+
69+
## 9. Change Log & Versioning
70+
71+
- For critical or frequently updated docs, include a change log or version history.
72+
- Update `last_updated` and `version` fields on changes.
73+
- Document significant changes in commit messages and changelogs.
74+
75+
## 10. Contribution & Review
76+
77+
- State how to propose changes or report issues.
78+
- Reference contributing guidelines.
79+
- Schedule regular audits and integrate checks into CI/CD.
80+
81+
## 11. Compliance & Security
82+
83+
- For compliance/security docs, include audit status, responsible owner, and incident history.
84+
85+
## 12. Accessibility & Inclusion
86+
87+
- Ensure documentation is accessible to all users (screen reader compatibility, keyboard navigation, etc.).
88+
- Use people-first, bias-aware language.
89+
90+
## 13. Footer
91+
92+
- Add a consistent footer with references, contact info, and license.
93+
94+
---
95+
96+
## Documentation Checklist
97+
98+
- [ ] YAML frontmatter is present and complete
99+
- [ ] Overview or Purpose section is clear
100+
- [ ] Table of Contents included for long files
101+
- [ ] Headings are hierarchical and logical
102+
- [ ] All links use `/blob/HEAD/` for repo-local files
103+
- [ ] All references are respected and validated
104+
- [ ] Formatting is clear and accessible
105+
- [ ] Diagrams and images have alt text
106+
- [ ] Examples and usage are provided where relevant
107+
- [ ] Validation/testing instructions included
108+
- [ ] Change log/version history present if needed
109+
- [ ] Contribution and review process described
110+
- [ ] Compliance/security info present if needed
111+
- [ ] Footer is present and complete

.github/instructions/markdown-style-guide.instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ Wrap the title in square brackets `[title]` immediately followed by the URL in `
4747
[WordPress](https://wordpress.org/)
4848
```
4949

50+
#### Universal Link Guidance
51+
52+
When linking to files in the same repository, always use `/blob/HEAD/` in the URL instead of a branch name. This ensures links remain valid after merges or branch changes.
53+
5054
## Blockquotes
5155

5256
Use `>` for blockquotes, double `>>` to further indent:
@@ -63,6 +67,9 @@ Use `>` for blockquotes, double `>>` to further indent:
6367
Use `-` for unordered lists, and intent two spaces for list subitems:
6468

6569
```md
70+
71+
### Universal Link Guidance
72+
6673
- List
6774
- List
6875
- List

.github/instructions/readme.instructions.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ applyTo: "README.md, *.md"
66
# README Documentation Standards & Update Tasks
77

88
## Universal Required Sections (for all README.md)
9+
910
- **Frontmatter:**
1011
- `description`: What is this file/folder for?
1112
- `references`: Related docs, schemas, instructions (AI cross-linking).
@@ -16,6 +17,7 @@ applyTo: "README.md, *.md"
1617
- **Footer:** Consistent references for human readers.
1718

1819
## Strongly Recommended Sections
20+
1921
- **Owners/Maintainers:** Who is responsible for updates?
2022
- **Version:** For scripts, schemas, configs, or agents.
2123
- **Status/Badges:** Coverage, build, lint, security, etc.
@@ -29,6 +31,7 @@ applyTo: "README.md, *.md"
2931
- **Validation/Testing:** How to validate or test the file/folder.
3032

3133
## Optional Sections (add if relevant)
34+
3235
- **FAQ/Troubleshooting:** Common issues and solutions.
3336
- **Limitations/Notes:** Known issues, future improvements.
3437
- **Related Projects/Links:** Other relevant projects or resources.
@@ -43,6 +46,7 @@ applyTo: "README.md, *.md"
4346
- **Deprecation Notice:** If the file/folder is deprecated or superseded.
4447

4548
## Expanded Guidance by Type
49+
4650
- **Test Folders:** Coverage badge, test matrix, how to run, test dependencies, test data location, test environment.
4751
- **Scripts/Utilities:** Supported platforms, dependencies, input/output, error handling, logging, performance notes.
4852
- **Schemas/Configs:** Schema version, validation instructions, example config, compatibility notes, migration instructions.
@@ -76,16 +80,7 @@ How to use or run this folder/file.
7680
```
7781

7882
## Additional Guidance
79-
- Use Mermaid diagrams for any process, workflow, or architecture that benefits from visualization.
80-
- Add badges for status, coverage, lint, or other relevant metrics.
81-
- Use emoji in headers only when it enhances clarity, accessibility, or engagement (see header-footer instructions).
82-
- Ensure all references in frontmatter are valid relative paths.
83-
- Keep README files concise but comprehensive; use optional sections only when they add value.
84-
- For folders with many files, include a structure diagram and navigation index.
85-
- For scripts/utilities, document all parameters, dependencies, and error handling.
86-
- For agents/AI files, document model, tools, limitations, and integration points.
87-
- For documentation folders, provide update policy, translation status, and accessibility notes.
88-
- For compliance/security folders, include audit status, responsible owner, and incident history.
8983

90-
---
9184
For further guidance, see referenced instructions files above.
85+
86+
When linking to files in the same repository, always use `/blob/HEAD/` in the URL instead of a branch name. This ensures links remain valid after merges or branch changes.

.github/workflows/lint.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ on:
1212
jobs:
1313
lint:
1414
runs-on: ubuntu-latest
15+
env:
16+
NPMPKGJSONLINT_STRICT_MODE: true
17+
NPMPKGJSONLINT_REQUIRE_DESCRIPTION: true
18+
NPMPKGJSONLINT_REQUIRE_REPOSITORY: true
19+
NPMPKGJSONLINT_REQUIRE_LICENSE: true
20+
NPMPKGJSONLINT_REQUIRE_AUTHOR: true
1521
steps:
1622
- uses: actions/checkout@v4
1723
- name: Set up Node.js
@@ -32,4 +38,6 @@ jobs:
3238
run: |
3339
find . -type f -name "*.sh" ! -path "*/node_modules/*" -exec shellcheck {} +
3440
- name: Run yamllint
35-
run: yamllint .
41+
run: yamllint .
42+
- name: Run npm-package-json-lint
43+
run: npm run lint:pkg-json

docs/LINTING.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Our linting strategy follows these core principles:
6464
| **Prettier** | Code formatting | `prettier.config.js` ||
6565
| **markdownlint** | Markdown linting | `.markdownlint.json` ||
6666
| **Spectral** | YAML/JSON linting | `.spectral.yaml` ||
67-
| **npmPkgJsonLint** | package.json validation | `.npmpackagejsonlintrc.json` ||
67+
| **npmPkgJsonLint** | package.json validation | `npmpackagejsonlint.config.cjs` ||
6868

6969
### Tool Selection Rationale
7070

@@ -128,6 +128,47 @@ export default [
128128

129129
### Environment Configuration
130130

131+
### npm-package-json-lint Configuration & Env Vars
132+
133+
The package JSON lint configuration now lives in `npmpackagejsonlint.config.cjs` (CJS for environment variable access and comments). You can influence rule enforcement via the following environment variables in `.env` (see `.env.example`):
134+
135+
| Variable | Purpose | Default |
136+
|----------|---------|---------|
137+
| `NPMPKGJSONLINT_STRICT_MODE` | Treat `version-format` failures as errors (otherwise warning) | `false` |
138+
| `NPMPKGJSONLINT_NAME_FORMAT` | Severity for `name-format` rule (`error`/`warning`/`off`) | `error` |
139+
| `NPMPKGJSONLINT_REQUIRE_FIELDS` | Master toggle for all required metadata rules | `true` |
140+
| `NPMPKGJSONLINT_REQUIRE_DESCRIPTION` | Require `description` field | `true` |
141+
| `NPMPKGJSONLINT_REQUIRE_REPOSITORY` | Require `repository` field | `true` |
142+
| `NPMPKGJSONLINT_REQUIRE_LICENSE` | Require `license` field | `true` |
143+
| `NPMPKGJSONLINT_REQUIRE_AUTHOR` | Require `author` field | `true` |
144+
| `NPMPKGJSONLINT_DISABLE_ORDER` | Disable `prefer-property-order` enforcement | `false` |
145+
| `NPMPKGJSONLINT_IGNORE_PATHS` | Additional comma‑separated paths to ignore | (empty) |
146+
147+
Example script (already defined):
148+
149+
```jsonc
150+
"lint:pkg-json": "npmPkgJsonLint --configFile npmpackagejsonlint.config.cjs ."
151+
```
152+
153+
To temporarily relax ordering while keeping other rules:
154+
155+
```bash
156+
NPMPKGJSONLINT_DISABLE_ORDER=true npm run lint:pkg-json
157+
```
158+
159+
To enforce strict version formatting in CI:
160+
161+
```bash
162+
NPMPKGJSONLINT_STRICT_MODE=true npm run lint:pkg-json
163+
```
164+
165+
Incremental adoption strategy:
166+
167+
1. Enable required metadata (default) and address any missing fields.
168+
2. Turn on strict version formatting (`STRICT_MODE=true`).
169+
3. Keep scope validation off until an allowed scope list is defined.
170+
4. Optionally tighten `valid-values-license` to `error` once all packages normalize licensing.
171+
131172
```bash
132173
# .env - Customize linting behaviour
133174
ESLINT_IGNORE=node_modules/**,build/**,custom-folder/**
@@ -160,7 +201,7 @@ PRETTIER_PRINT_WIDTH=80
160201
"lint:md": "markdownlint '**/*.md' --fix",
161202
"lint:yaml": "spectral lint '**/*.{yml,yaml}' --ruleset .spectral.yaml",
162203
"lint:workflows": "spectral lint '.github/workflows/*.{yml,yaml}' --ruleset .spectral-workflows.yaml",
163-
"lint:pkg-json": "npmPkgJsonLint ."
204+
"lint:pkg-json": "npmPkgJsonLint --configFile npmpackagejsonlint.config.cjs ."
164205
}
165206
}
166207
```

npmpackagejsonlint.config.cjs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
* scripts/utility/npm-package-json-lint-helpers.js
77
*
88
* Environment variables (optional overrides):
9-
* NPMPKGJSONLINT_IGNORE_PATHS Comma-separated extra ignore paths
10-
* NPMPKGJSONLINT_STRICT_MODE Treat version-format as error (default false)
11-
* NPMPKGJSONLINT_NAME_FORMAT Severity for name-format (default error)
12-
* NPMPKGJSONLINT_REQUIRE_FIELDS Toggle description/repository/license (default true)
13-
* NPMPKGJSONLINT_REQUIRE_AUTHOR Toggle require-author rule (default true)
14-
* NPMPKGJSONLINT_DISABLE_ORDER Disable prefer-property-order rule (default false)
9+
* NPMPKGJSONLINT_IGNORE_PATHS Comma-separated extra ignore paths
10+
* NPMPKGJSONLINT_STRICT_MODE Treat version-format as error (default false)
11+
* NPMPKGJSONLINT_NAME_FORMAT Severity for name-format (default error)
12+
* NPMPKGJSONLINT_REQUIRE_FIELDS Backwards-compatible master toggle (if false, disables all require-* rules)
13+
* NPMPKGJSONLINT_REQUIRE_DESCRIPTION Toggle require-description (default true)
14+
* NPMPKGJSONLINT_REQUIRE_REPOSITORY Toggle require-repository (default true)
15+
* NPMPKGJSONLINT_REQUIRE_LICENSE Toggle require-license (default true)
16+
* NPMPKGJSONLINT_REQUIRE_AUTHOR Toggle require-author (default true)
17+
* NPMPKGJSONLINT_DISABLE_ORDER Disable prefer-property-order rule (default false)
1518
*
1619
* NOTE: Only documented rules supported by npm-package-json-lint v7 are enabled.
1720
*/
@@ -36,6 +39,13 @@ const strictMode = process.env.NPMPKGJSONLINT_STRICT_MODE === 'true';
3639
const nameFormat = process.env.NPMPKGJSONLINT_NAME_FORMAT || 'error';
3740
const requireFields = process.env.NPMPKGJSONLINT_REQUIRE_FIELDS !== 'false';
3841
const requireAuthor = process.env.NPMPKGJSONLINT_REQUIRE_AUTHOR !== 'false';
42+
// Granular required field toggles (fall back to master flag)
43+
const requireDescription =
44+
requireFields && process.env.NPMPKGJSONLINT_REQUIRE_DESCRIPTION !== 'false';
45+
const requireRepository =
46+
requireFields && process.env.NPMPKGJSONLINT_REQUIRE_REPOSITORY !== 'false';
47+
const requireLicense =
48+
requireFields && process.env.NPMPKGJSONLINT_REQUIRE_LICENSE !== 'false';
3949
const disableOrder = process.env.NPMPKGJSONLINT_DISABLE_ORDER === 'true';
4050
const ignorePathsEnv = parseList(process.env.NPMPKGJSONLINT_IGNORE_PATHS);
4151

@@ -100,15 +110,16 @@ module.exports = {
100110
rules: {
101111
// --- Naming & scope rules ---
102112
'name-format': nameFormat,
103-
'valid-values-name-scope': 'error',
113+
// Scope validation remains disabled until an allowed scope list is defined.
114+
'valid-values-name-scope': 'off',
104115

105116
// --- Version rules ---
106117
'version-format': strictMode ? 'error' : 'warning',
107118

108119
// --- Required metadata (env toggles) ---
109-
'require-description': requireFields ? 'error' : 'off',
110-
'require-license': requireFields ? 'error' : 'off',
111-
'require-repository': requireFields ? 'error' : 'off',
120+
'require-description': requireDescription ? 'error' : 'off',
121+
'require-license': requireLicense ? 'error' : 'off',
122+
'require-repository': requireRepository ? 'error' : 'off',
112123
'require-author': requireAuthor ? 'error' : 'off',
113124

114125
// --- Type checks (low risk, ensure JSON shape consistency) ---
@@ -122,8 +133,8 @@ module.exports = {
122133
? 'off'
123134
: ['warning', preferredOrder],
124135

125-
// --- License values (relaxed set; enable later if stricter policy adopted) ---
126-
'valid-values-license': 'error',
136+
// --- License values ---
137+
'valid-values-license': ['warning', ['GPL-3.0-or-later']],
127138
},
128139
};
129140

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"typescript": "^5.0.0"
109109
},
110110
"scripts": {
111-
"lint:pkg-json": "NPMPKGJSONLINT_DISABLE_ORDER=true npmPkgJsonLint --configFile npmpackagejsonlint.config.cjs .",
111+
"lint:pkg-json": "npmPkgJsonLint --configFile npmpackagejsonlint.config.cjs .",
112112
"lint:yaml": "spectral lint '**/*.{yml,yaml}' --ruleset spectral.config.js",
113113
"lint:workflows": "spectral lint '.github/workflows/*.{yml,yaml}' --ruleset spectral.config.js",
114114
"lint": "npm run lint:js && npm run lint:css && npm run lint:yaml && npm run lint:pkg-json",

0 commit comments

Comments
 (0)