-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.yamllint.config.cjs
More file actions
259 lines (230 loc) · 7.14 KB
/
.yamllint.config.cjs
File metadata and controls
259 lines (230 loc) · 7.14 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/**
* Enhanced Yamllint Configuration for LightSpeedWP
*
* NOTE: yamllint is a Python tool that natively uses YAML configuration files.
* This JavaScript configuration is provided for:
* - Documentation and reference purposes
* - Potential future JavaScript-based YAML linting tools
* - Integration with Node.js build processes
* - Environment variable customization for CI/CD
*
* To use with yamllint, this configuration would need to be converted to YAML format.
* For direct yamllint usage, refer to the .yamllint file in the repository root.
*
* Environment Variables:
* - YAMLLINT_LINE_LENGTH: Maximum line length (default: 120)
* - YAMLLINT_INDENT_SPACES: Number of spaces for indentation (default: 2)
* - YAMLLINT_STRICT_MODE: Enable strict mode (default: false)
* - YAMLLINT_IGNORE_PATTERNS: Comma-separated ignore patterns
* - YAMLLINT_COMMENTS_INDENT_DISABLE: Disable comment indentation checks (default: true)
* - YAMLLINT_DOCUMENT_START_DISABLE: Disable document start checks (default: true)
* - YAMLLINT_TRAILING_SPACES_DISABLE: Disable trailing spaces checks (default: true)
*/
/**
* Load environment variables with fallback defaults
*/
require("dotenv").config();
/**
* Configuration constants with environment variable overrides
*/
const lineLength = process.env.YAMLLINT_LINE_LENGTH
? parseInt(process.env.YAMLLINT_LINE_LENGTH, 10)
: 120;
const indentSpaces = process.env.YAMLLINT_INDENT_SPACES
? parseInt(process.env.YAMLLINT_INDENT_SPACES, 10)
: 2;
const strictMode = process.env.YAMLLINT_STRICT_MODE === "true";
const ignorePatterns = process.env.YAMLLINT_IGNORE_PATTERNS
? process.env.YAMLLINT_IGNORE_PATTERNS.split(",").map((p) => p.trim())
: [
"*.min.yml",
"*.min.yaml",
"node_modules/**/*.yml",
"node_modules/**/*.yaml",
"vendor/**/*.yml",
"vendor/**/*.yaml",
".git/**/*.yml",
".git/**/*.yaml",
];
const commentsIndentDisable =
process.env.YAMLLINT_COMMENTS_INDENT_DISABLE !== "false";
const documentStartDisable =
process.env.YAMLLINT_DOCUMENT_START_DISABLE !== "false";
const trailingSpacesDisable =
process.env.YAMLLINT_TRAILING_SPACES_DISABLE !== "false";
/**
* Custom validation functions for YAML content
*/
const customValidation = {
/**
* Validate GitHub workflow syntax
*/
validateWorkflow: function (yamlContent) {
const requiredWorkflowKeys = ["name", "on", "jobs"];
const errors = [];
try {
const yaml = require("yaml");
const parsed = yaml.parse(yamlContent);
requiredWorkflowKeys.forEach((key) => {
if (!parsed[key]) {
errors.push(`Missing required workflow key: ${key}`);
}
});
} catch (e) {
errors.push(`YAML parsing error: ${e.message}`);
}
return errors;
},
/**
* Validate GitHub Actions syntax
*/
validateAction: function (yamlContent) {
const requiredActionKeys = ["name", "description", "runs"];
const errors = [];
try {
const yaml = require("yaml");
const parsed = yaml.parse(yamlContent);
requiredActionKeys.forEach((key) => {
if (!parsed[key]) {
errors.push(`Missing required action key: ${key}`);
}
});
} catch (e) {
errors.push(`YAML parsing error: ${e.message}`);
}
return errors;
},
/**
* Validate Docker Compose syntax
*/
validateDockerCompose: function (yamlContent) {
const errors = [];
try {
const yaml = require("yaml");
const parsed = yaml.parse(yamlContent);
if (!parsed.services) {
errors.push("Missing required docker-compose key: services");
}
} catch (e) {
errors.push(`YAML parsing error: ${e.message}`);
}
return errors;
},
/**
* Validate LightSpeedWP specific YAML structures
*/
validateLightSpeedWP: function (yamlContent, filename) {
const errors = [];
try {
const yaml = require("yaml");
const parsed = yaml.parse(yamlContent);
// Check for frontmatter in markdown files
if (filename && filename.endsWith(".md")) {
if (!parsed["file_type"]) {
errors.push(
"Missing file_type in YAML frontmatter (required for LightSpeedWP)",
);
}
if (!parsed["description"]) {
errors.push("Missing description in YAML frontmatter (recommended)");
}
}
// Check for required workflow fields
if (filename && filename.includes("workflow")) {
if (!parsed["name"]) errors.push("Missing workflow name");
if (!parsed["on"]) errors.push("Missing workflow trigger (on)");
if (!parsed["jobs"]) errors.push("Missing workflow jobs");
}
} catch (e) {
errors.push(`YAML validation error: ${e.message}`);
}
return errors;
},
};
/**
* Generate yamllint compatible YAML configuration
* This function can be used to export the configuration to YAML format
*/
function generateYamlConfig() {
return {
extends: "default",
rules: {
line_length: {
max: lineLength,
level: strictMode ? "error" : "warning",
},
indentation: {
spaces: indentSpaces,
level: "error",
},
comments: {
min_spaces_from_content: 1,
},
comments_indentation: commentsIndentDisable ? "disable" : "enable",
document_start: documentStartDisable ? "disable" : "enable",
trailing_spaces: trailingSpacesDisable ? "disable" : "enable",
},
ignore: ignorePatterns,
};
}
/**
* Yamllint Configuration Object (CommonJS format)
*
* This configuration matches the .yamllint file but provides additional
* JavaScript-based functionality for validation and customization.
*
* @typedef {Object} YamllintConfig
* @property {Array<string>} ignorePaths - File paths to ignore during linting
* @property {Array<string>} ignoreFiles - File patterns to ignore during linting
* @property {Object} rules - Yamllint rule configuration with environment variable support
* @property {Object} functions - Custom validation functions for specific YAML types
* @property {string} extends - Base configuration that extends default yamllint rules
* @property {Array<string>} plugins - Additional plugins for extended functionality
* @property {Object} includes - Additional configuration includes and utilities
*/
module.exports = {
/**
* Configuration metadata
*/
extends: "default",
rules: {
line_length: {
max: lineLength,
level: strictMode ? "error" : "warning",
},
indentation: {
spaces: indentSpaces,
level: "error",
},
comments: {
min_spaces_from_content: 1,
},
comments_indentation: commentsIndentDisable ? "disable" : "enable",
document_start: documentStartDisable ? "disable" : "enable",
trailing_spaces: trailingSpacesDisable ? "disable" : "enable",
},
/**
* Ignore patterns
*/
ignore: ignorePatterns,
/**
* Custom validation functions
*/
customValidation,
/**
* Export configuration generator
*/
generateYamlConfig,
/**
* Environment variable overrides
*/
env: {
lineLength,
indentSpaces,
strictMode,
ignorePatterns,
commentsIndentDisable,
documentStartDisable,
trailingSpacesDisable,
},
};