-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.markdownlint.config.cjs
More file actions
233 lines (208 loc) · 5.58 KB
/
Copy path.markdownlint.config.cjs
File metadata and controls
233 lines (208 loc) · 5.58 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
* Markdownlint Configuration for LightSpeedWP Documentation Standards
*
* Markdownlint enforces consistent Markdown formatting across documentation.
* This configuration provides:
* - Comprehensive rule set for professional documentation
* - Environment variable overrides for CI/CD customization
* - Ignore patterns for generated content
* - Custom functions for organization-specific validation
*
* Environment Variables:
* - MARKDOWNLINT_LINE_LENGTH: Override max line length (default: 120)
* - MARKDOWNLINT_STRICT: Enable strict mode for CI (default: false)
* - MARKDOWNLINT_IGNORE_GENERATED: Ignore auto-generated files (default: true)
*/
/**
* Load environment variables with fallback defaults
*/
require("dotenv").config();
const fs = require("fs");
const path = require("path");
/**
* Configuration constants with environment variable overrides
*/
const lineLength = parseInt(process.env.MARKDOWNLINT_LINE_LENGTH) || 120;
const strictMode = process.env.MARKDOWNLINT_STRICT === "true";
const ignoreGenerated = process.env.MARKDOWNLINT_IGNORE_GENERATED !== "false";
/**
* Load ignore patterns from .markdownlintignore file
*/
function loadIgnorePatterns() {
const ignoreFilePath = path.join(__dirname, ".markdownlintignore");
if (!fs.existsSync(ignoreFilePath)) {
return [];
}
try {
const content = fs.readFileSync(ignoreFilePath, "utf-8");
return content
.split("\n")
.map((line) => line.trim())
.filter((line) => line && !line.startsWith("#"))
.map((line) => {
// Convert bare filenames to glob patterns
if (!line.includes("/") && !line.includes("*")) {
return `**/${line}`;
}
return line;
});
} catch (error) {
console.warn("Could not read .markdownlintignore:", error.message);
return [];
}
}
/**
* Markdownlint Configuration Object
*
* @type {import('markdownlint').Configuration}
*/
module.exports = {
/**
* Use default rules as base (enables most common formatting rules)
*/
default: true,
/**
* Files and directories to ignore
* These patterns are loaded from .markdownlintignore (canonical source)
*/
ignorePaths: [
...loadIgnorePatterns(),
],
/**
* Specific files to ignore (supports glob patterns)
*/
ignoreFiles: ["README.template.md", "*.draft.md"],
/**
* Rule customizations
* Each rule can be enabled (true), disabled (false), or configured with options
*/
rules: {
/**
* MD013 - Line length limit
* DISABLED - Line length enforcement removed per project requirements
*/
MD013: false,
/**
* MD025 - Single title/single H1
* DISABLED: Technical documentation often needs multiple H1 headers for structure.
*/
MD025: false,
/**
* MD036 - No emphasis as heading
* DISABLED: Some documentation uses emphasis for section markers.
*/
MD036: false,
/**
* MD033 - Inline HTML
* Allow HTML in Markdown for enhanced formatting
*/
MD033: {
allowed_elements: [
"br",
"sub",
"sup",
"kbd",
"mark",
"details",
"summary",
"img",
"a",
"div",
"span",
"table",
"thead",
"tbody",
"tr",
"th",
"td",
],
},
/**
* MD041 - First line in file should be a top-level heading
* Disabled to allow frontmatter and other content before headings
*/
MD041: false,
/**
* MD024 - Multiple headings with the same content
* DISABLED: Technical docs often reuse heading names in different sections.
*/
MD024: false,
/**
* MD029 - Ordered list item prefix
* Enforce consistent numbering (1. 2. 3. vs 1. 1. 1.)
*/
MD029: {
style: "ordered",
},
/**
* MD040 - Fenced code blocks should have a language specified
* Require language tags for syntax highlighting
*/
MD040: strictMode,
/**
* MD046 - Code block style
* Prefer fenced code blocks over indented
*/
MD046: {
style: "fenced",
},
/**
* MD049 - Emphasis style
* Use asterisks for emphasis instead of underscores
*/
MD049: {
style: "asterisk",
},
/**
* MD050 - Strong style
* Use asterisks for strong text instead of underscores
*/
MD050: {
style: "asterisk",
},
/**
* MD060 - Table column style
* DISABLED: Flexible table formatting for readability.
*/
MD060: false,
},
/**
* Custom functions for advanced validation
* These can be used in custom rules for organization-specific checks
*/
functions: {
/**
* Check for LightSpeedWP branding consistency
*/
checkBranding: function (token, content) {
const brandingTerms = ["lightspeed", "light speed", "light-speed"];
const correctTerm = "LightSpeedWP";
for (const term of brandingTerms) {
if (
content.toLowerCase().includes(term) &&
!content.includes(correctTerm)
) {
return {
lineNumber: token.lineNumber,
detail: `Use '${correctTerm}' for consistent branding`,
};
}
}
return null;
},
},
/**
* Extends additional rulesets
* Can reference external ruleset files or npm packages
*/
extends: [
// Example: '@lightspeedwp/markdownlint-config' - if we had an org package
],
/**
* Include additional configuration files
* Allows modular configuration management
*/
includes: [
// Example: './docs/markdownlint-docs.config.js' - for docs-specific rules
],
};