cursor-lint 0.11.1 → 0.12.0
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 +5 -1
- package/package.json +1 -1
- package/src/cli.js +20 -3
- package/src/index.js +185 -0
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/cursor-lint)
|
|
4
4
|
[](https://www.npmjs.com/package/cursor-lint)
|
|
5
5
|
|
|
6
|
-
Lint your [Cursor](https://cursor.com) rules.
|
|
6
|
+
Lint your [Cursor](https://cursor.com) rules. Find problems before they silently break your output.
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|
|
|
@@ -133,6 +133,10 @@ Made by [nedcodes](https://dev.to/nedcodes) · [Free rules collection](https://g
|
|
|
133
133
|
|
|
134
134
|
---
|
|
135
135
|
|
|
136
|
+
## Stay Updated
|
|
137
|
+
|
|
138
|
+
Get experiment results and Cursor findings in your inbox: [subscribe](https://buttondown.com/nedcodes)
|
|
139
|
+
|
|
136
140
|
## Related
|
|
137
141
|
|
|
138
142
|
- [cursorrules-collection](https://github.com/nedcodes-ok/cursorrules-collection) — 104 free .mdc rules
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -8,12 +8,13 @@ const { fixProject } = require('./fix');
|
|
|
8
8
|
const { generateRules, suggestSkills } = require('./generate');
|
|
9
9
|
const { checkVersions, checkRuleVersionMismatches } = require('./versions');
|
|
10
10
|
|
|
11
|
-
const VERSION = '0.
|
|
11
|
+
const VERSION = '0.12.0';
|
|
12
12
|
|
|
13
13
|
const RED = '\x1b[31m';
|
|
14
14
|
const YELLOW = '\x1b[33m';
|
|
15
15
|
const GREEN = '\x1b[32m';
|
|
16
16
|
const CYAN = '\x1b[36m';
|
|
17
|
+
const BLUE = '\x1b[34m';
|
|
17
18
|
const DIM = '\x1b[2m';
|
|
18
19
|
const RESET = '\x1b[0m';
|
|
19
20
|
|
|
@@ -42,6 +43,14 @@ ${YELLOW}What it checks (default):${RESET}
|
|
|
42
43
|
• Agent skill files (SKILL.md in .claude/skills/, skills/)
|
|
43
44
|
• Vague rules that won't change AI behavior
|
|
44
45
|
• YAML syntax errors
|
|
46
|
+
• Rule length (token waste detection)
|
|
47
|
+
• Missing code examples in rules
|
|
48
|
+
• Empty rule bodies, URL-only rules
|
|
49
|
+
• Description quality (too short/long)
|
|
50
|
+
• Glob pattern issues (too broad, spaces, missing extensions)
|
|
51
|
+
• Excessive rule count (>20 files)
|
|
52
|
+
• Duplicate/near-duplicate rules across files
|
|
53
|
+
• Conflicting directives between rules
|
|
45
54
|
|
|
46
55
|
${YELLOW}What --verify checks:${RESET}
|
|
47
56
|
• Scans code files matching rule globs
|
|
@@ -397,6 +406,7 @@ async function main() {
|
|
|
397
406
|
|
|
398
407
|
let totalErrors = 0;
|
|
399
408
|
let totalWarnings = 0;
|
|
409
|
+
let totalInfo = 0;
|
|
400
410
|
let totalPassed = 0;
|
|
401
411
|
|
|
402
412
|
for (const result of results) {
|
|
@@ -408,7 +418,11 @@ async function main() {
|
|
|
408
418
|
totalPassed++;
|
|
409
419
|
} else {
|
|
410
420
|
for (const issue of result.issues) {
|
|
411
|
-
|
|
421
|
+
let icon;
|
|
422
|
+
if (issue.severity === 'error') icon = `${RED}✗${RESET}`;
|
|
423
|
+
else if (issue.severity === 'info') icon = `${BLUE}ℹ${RESET}`;
|
|
424
|
+
else icon = `${YELLOW}⚠${RESET}`;
|
|
425
|
+
|
|
412
426
|
const lineInfo = issue.line ? ` ${DIM}(line ${issue.line})${RESET}` : '';
|
|
413
427
|
console.log(` ${icon} ${issue.message}${lineInfo}`);
|
|
414
428
|
if (issue.hint) {
|
|
@@ -417,9 +431,11 @@ async function main() {
|
|
|
417
431
|
}
|
|
418
432
|
const errors = result.issues.filter(i => i.severity === 'error').length;
|
|
419
433
|
const warnings = result.issues.filter(i => i.severity === 'warning').length;
|
|
434
|
+
const infos = result.issues.filter(i => i.severity === 'info').length;
|
|
420
435
|
totalErrors += errors;
|
|
421
436
|
totalWarnings += warnings;
|
|
422
|
-
|
|
437
|
+
totalInfo += infos;
|
|
438
|
+
if (errors === 0 && warnings === 0 && infos === 0) totalPassed++;
|
|
423
439
|
}
|
|
424
440
|
console.log();
|
|
425
441
|
}
|
|
@@ -428,6 +444,7 @@ async function main() {
|
|
|
428
444
|
const parts = [];
|
|
429
445
|
if (totalErrors > 0) parts.push(`${RED}${totalErrors} error${totalErrors !== 1 ? 's' : ''}${RESET}`);
|
|
430
446
|
if (totalWarnings > 0) parts.push(`${YELLOW}${totalWarnings} warning${totalWarnings !== 1 ? 's' : ''}${RESET}`);
|
|
447
|
+
if (totalInfo > 0) parts.push(`${BLUE}${totalInfo} info${RESET}`);
|
|
431
448
|
if (totalPassed > 0) parts.push(`${GREEN}${totalPassed} passed${RESET}`);
|
|
432
449
|
console.log(parts.join(', ') + '\n');
|
|
433
450
|
|
package/src/index.js
CHANGED
|
@@ -59,6 +59,37 @@ function parseFrontmatter(content) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// Helper: Get body content after frontmatter
|
|
63
|
+
function getBody(content) {
|
|
64
|
+
const match = content.match(/^---\n[\s\S]*?\n---\n?/);
|
|
65
|
+
if (!match) return content;
|
|
66
|
+
return content.slice(match[0].length);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Helper: Calculate similarity between two texts using Jaccard similarity
|
|
70
|
+
function similarity(textA, textB) {
|
|
71
|
+
const normalize = (text) => text.toLowerCase().replace(/\s+/g, ' ').trim();
|
|
72
|
+
const normA = normalize(textA);
|
|
73
|
+
const normB = normalize(textB);
|
|
74
|
+
|
|
75
|
+
// Check if one is substring of the other
|
|
76
|
+
if (normA.includes(normB) || normB.includes(normA)) {
|
|
77
|
+
return 1.0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Word-based Jaccard similarity
|
|
81
|
+
const wordsA = new Set(normA.split(/\s+/));
|
|
82
|
+
const wordsB = new Set(normB.split(/\s+/));
|
|
83
|
+
|
|
84
|
+
if (wordsA.size === 0 && wordsB.size === 0) return 1.0;
|
|
85
|
+
if (wordsA.size === 0 || wordsB.size === 0) return 0.0;
|
|
86
|
+
|
|
87
|
+
const intersection = new Set([...wordsA].filter(w => wordsB.has(w)));
|
|
88
|
+
const union = new Set([...wordsA, ...wordsB]);
|
|
89
|
+
|
|
90
|
+
return intersection.size / union.size;
|
|
91
|
+
}
|
|
92
|
+
|
|
62
93
|
async function lintMdcFile(filePath) {
|
|
63
94
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
64
95
|
const issues = [];
|
|
@@ -91,6 +122,112 @@ async function lintMdcFile(filePath) {
|
|
|
91
122
|
}
|
|
92
123
|
}
|
|
93
124
|
|
|
125
|
+
// Get body content for additional checks
|
|
126
|
+
const body = getBody(content);
|
|
127
|
+
|
|
128
|
+
// 1. Rule too long
|
|
129
|
+
if (body.length > 2000) {
|
|
130
|
+
issues.push({
|
|
131
|
+
severity: 'warning',
|
|
132
|
+
message: 'Rule body is very long (>2000 chars, ~500+ tokens)',
|
|
133
|
+
hint: 'Shorter, specific rules outperform long generic ones. Consider splitting into focused rules.',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 2. No examples
|
|
138
|
+
const hasCodeBlocks = /```/.test(body) || /\n {4,}\S/.test(body);
|
|
139
|
+
if (body.length > 200 && !hasCodeBlocks) {
|
|
140
|
+
issues.push({
|
|
141
|
+
severity: 'warning',
|
|
142
|
+
message: 'Rule has no code examples',
|
|
143
|
+
hint: 'Rules with examples get followed more reliably by the AI model.',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 3. Empty rule body
|
|
148
|
+
if (fm.found && body.trim().length === 0) {
|
|
149
|
+
issues.push({
|
|
150
|
+
severity: 'error',
|
|
151
|
+
message: 'Rule file has frontmatter but no instructions',
|
|
152
|
+
hint: 'Add rule instructions after the --- frontmatter block.',
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 4. Description too short
|
|
157
|
+
if (fm.data && fm.data.description && fm.data.description.length < 10) {
|
|
158
|
+
issues.push({
|
|
159
|
+
severity: 'warning',
|
|
160
|
+
message: 'Description is very short (<10 chars)',
|
|
161
|
+
hint: 'A descriptive description helps Cursor decide when to apply this rule.',
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 5. Description too long
|
|
166
|
+
if (fm.data && fm.data.description && fm.data.description.length > 200) {
|
|
167
|
+
issues.push({
|
|
168
|
+
severity: 'warning',
|
|
169
|
+
message: 'Description is very long (>200 chars)',
|
|
170
|
+
hint: 'Keep descriptions concise. Put detailed instructions in the rule body, not the description.',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 6. Glob pattern issues
|
|
175
|
+
if (fm.data && fm.data.globs) {
|
|
176
|
+
const globs = parseGlobs(fm.data.globs);
|
|
177
|
+
for (const glob of globs) {
|
|
178
|
+
// Overly broad glob
|
|
179
|
+
if (glob === '*' || glob === '**') {
|
|
180
|
+
issues.push({
|
|
181
|
+
severity: 'warning',
|
|
182
|
+
message: 'Overly broad glob pattern',
|
|
183
|
+
hint: 'This matches everything. Consider using more specific patterns or just alwaysApply: true.',
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
// Glob contains spaces
|
|
187
|
+
if (glob.includes(' ') && !glob.includes('"') && !glob.includes("'")) {
|
|
188
|
+
issues.push({
|
|
189
|
+
severity: 'warning',
|
|
190
|
+
message: 'Glob pattern contains spaces',
|
|
191
|
+
hint: 'Glob patterns with spaces may not match correctly.',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
// Glob is *.
|
|
195
|
+
if (glob === '*.') {
|
|
196
|
+
issues.push({
|
|
197
|
+
severity: 'warning',
|
|
198
|
+
message: 'Glob pattern has no file extension after dot',
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 7. alwaysApply + globs info
|
|
205
|
+
if (fm.data && fm.data.alwaysApply === true && fm.data.globs) {
|
|
206
|
+
const globs = parseGlobs(fm.data.globs);
|
|
207
|
+
if (globs.length > 0) {
|
|
208
|
+
issues.push({
|
|
209
|
+
severity: 'info',
|
|
210
|
+
message: 'alwaysApply is true with globs set',
|
|
211
|
+
hint: 'When alwaysApply is true, globs serve as a hint to the model but don\'t filter. This is fine if intentional.',
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 8. Rule body is just a URL
|
|
217
|
+
const bodyTrimmed = body.trim();
|
|
218
|
+
const urlMatch = bodyTrimmed.match(/^https?:\/\//);
|
|
219
|
+
if (urlMatch) {
|
|
220
|
+
const lines = bodyTrimmed.split('\n').filter(line => line.trim().length > 0);
|
|
221
|
+
const nonUrlLines = lines.filter(line => !line.trim().match(/^https?:\/\//));
|
|
222
|
+
if (nonUrlLines.length < 2) {
|
|
223
|
+
issues.push({
|
|
224
|
+
severity: 'warning',
|
|
225
|
+
message: 'Rule body appears to be just a URL',
|
|
226
|
+
hint: 'Cursor cannot follow URLs. Put the actual instructions in the rule body.',
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
94
231
|
return { file: filePath, issues };
|
|
95
232
|
}
|
|
96
233
|
|
|
@@ -249,6 +386,54 @@ async function lintProject(dir) {
|
|
|
249
386
|
});
|
|
250
387
|
}
|
|
251
388
|
|
|
389
|
+
// 9. Excessive rules count & 10. Duplicate rule content
|
|
390
|
+
const rulesDirPath = path.join(dir, '.cursor', 'rules');
|
|
391
|
+
if (fs.existsSync(rulesDirPath) && fs.statSync(rulesDirPath).isDirectory()) {
|
|
392
|
+
const mdcFiles = fs.readdirSync(rulesDirPath).filter(f => f.endsWith('.mdc'));
|
|
393
|
+
|
|
394
|
+
if (mdcFiles.length > 20) {
|
|
395
|
+
results.push({
|
|
396
|
+
file: rulesDirPath,
|
|
397
|
+
issues: [{
|
|
398
|
+
severity: 'warning',
|
|
399
|
+
message: `Project has ${mdcFiles.length} rule files`,
|
|
400
|
+
hint: 'More rules means more tokens consumed per request. Consider consolidating related rules.',
|
|
401
|
+
}],
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 10. Duplicate rule content
|
|
406
|
+
if (mdcFiles.length > 1) {
|
|
407
|
+
const parsed = [];
|
|
408
|
+
for (const file of mdcFiles) {
|
|
409
|
+
const filePath = path.join(rulesDirPath, file);
|
|
410
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
411
|
+
const body = getBody(content);
|
|
412
|
+
parsed.push({ file, filePath, body });
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Compare each pair
|
|
416
|
+
for (let i = 0; i < parsed.length; i++) {
|
|
417
|
+
for (let j = i + 1; j < parsed.length; j++) {
|
|
418
|
+
const a = parsed[i];
|
|
419
|
+
const b = parsed[j];
|
|
420
|
+
const sim = similarity(a.body, b.body);
|
|
421
|
+
|
|
422
|
+
if (sim > 0.8) {
|
|
423
|
+
results.push({
|
|
424
|
+
file: rulesDirPath,
|
|
425
|
+
issues: [{
|
|
426
|
+
severity: 'warning',
|
|
427
|
+
message: `Possible duplicate rules: ${a.file} and ${b.file}`,
|
|
428
|
+
hint: 'These rules have very similar content. Consider merging them.',
|
|
429
|
+
}],
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
252
437
|
return results;
|
|
253
438
|
}
|
|
254
439
|
|