Skip to content

Commit 39db1f4

Browse files
committed
Cleanup
1 parent 0bf399e commit 39db1f4

5 files changed

Lines changed: 33 additions & 21 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@
173173
"start:test-dev-server": "cd packages && cd test && cd dev-server && npm start",
174174
"start:test-harness": "cd packages && cd test && cd harness && npm start",
175175
"start:test-page-object": "cd packages && cd test && cd page-object && npm start",
176-
"test": "jest"
176+
"test": "jest",
177+
"vg": "vg"
177178
},
178179
"pinDependencies": {
179180
"@testing-library/react": [

packages/vibe-grep/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Built on top of [`ast-grep`](https://ast-grep.github.io/), vibe-grep provides ex
2525
Create a `.js` file in the `commands/` directory:
2626

2727
```js
28+
export const description = 'Short command description.';
29+
2830
export function help(...args) {
2931
// Print command help (optional)
3032
}

packages/vibe-grep/src/commands/ast-check.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ const dirname = path.dirname(new URL(import.meta.url).pathname);
1111

1212
const parseAllToJSON = yamlContent => YAML.parseAllDocuments(yamlContent).map(doc => doc.toJSON());
1313

14+
export const description = 'Verify one or more files using an AST-Grep preset.';
15+
1416
export function help() {
1517
console.log(`Usage: vg ast-check <preset> <files...>
1618
17-
Verify one or more files using an AST‑Grep preset.
19+
${description}
1820
1921
Arguments:
20-
<preset> Name of the preset to use. Presets are located in the "rules"
22+
<preset> Name of the preset to use. Presets are located in the "rules"
2123
directory next to this script and can be YAML or JS files.
22-
<files...> One or more files to verify. Shell glob expansion happens
24+
<files...> One or more files to verify. Shell glob expansion happens
2325
outside this tool, so pass files directly.
2426
`);
2527

@@ -28,7 +30,6 @@ Arguments:
2830
.readdirSync(path.resolve(dirname, '../rules'))
2931
.filter(file => file.endsWith('.yaml') || file.endsWith('.yml') || file.endsWith('.js'));
3032

31-
const examples = [];
3233
console.log('Available presets:');
3334
for (const rule of rules) {
3435
// eslint-disable-next-line security/detect-non-literal-fs-filename
@@ -42,27 +43,23 @@ Arguments:
4243
for (const ruleData of rules) {
4344
console.log(` ${ruleData.id || '(unnamed)'} - ${ruleData.description || 'No description provided.'}`);
4445
if (ruleData.args && Array.isArray(ruleData.args)) {
45-
examples.push(`vg ast-check ${ruleName} ${ruleData.args.join(' ')}`);
46+
console.log(` Example: vg ast-check ${ruleName} ${ruleData.args.join(' ')}`);
4647
}
4748
}
4849
}
49-
if (examples.length > 0) {
50-
console.log('\nExample usage:');
51-
for (const example of examples) {
52-
console.log(` ${example}`);
53-
}
54-
}
5550
}
5651

5752
export default async function run(...args) {
5853
if (args.length === 0) {
5954
console.error('Error: no preset specified for ast-check command.');
55+
help();
6056
return;
6157
}
6258
const preset = args.shift();
6359
const files = args;
6460
if (files.length === 0) {
6561
console.error('Error: no files provided for ast-check command.');
62+
help();
6663
return;
6764
}
6865
// Resolve the preset file.
@@ -132,13 +129,14 @@ export default async function run(...args) {
132129
const matches = root.findAll(matcher);
133130
if (matches.length > 0) {
134131
hasViolation = isFatalRule || hasViolation;
135-
console.error(`❌ FAIL ${file}: found ${matches.length} violation(s) for rule '${id}'.`);
132+
console.error(
133+
`${isFatalRule ? '🔴 FAIL' : '🟡 SKIP'} ${file}: found ${matches.length} violation(s) for rule '${id}'.`
134+
);
136135
// Print custom message from the rule if provided.
137136
if (rule.message) {
138137
console.error(` ${rule.severity || 'note'}: ${rule.message}`);
139138
}
140139
try {
141-
// Extract 1‑based line numbers for each match using ast‑grep's range API.
142140
const lines = matches.map(node => {
143141
const rng = node.range();
144142
return rng.start.line + 1;
@@ -153,7 +151,7 @@ export default async function run(...args) {
153151
console.error(` ${file}: <unable to determine line numbers>`);
154152
}
155153
} else {
156-
console.log(` PASS ${file}: ${id}.`);
154+
console.log(`🟢 PASS ${file}: ${id}.`);
157155
}
158156
}
159157
}

packages/vibe-grep/src/commands/help.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import path from 'node:path';
77

88
const dirname = path.dirname(new URL(import.meta.url).pathname);
99

10+
export const description = 'Show help information for available commands.';
11+
1012
export function help(...args) {
1113
const command = args.shift();
1214

1315
if (command === 'help') {
1416
console.log(`Usage: vg help [command]
1517
16-
Show help information. If a command is specified, show help for that command.`);
18+
${description}`);
1719
return;
1820
}
1921

@@ -30,17 +32,26 @@ Show help information. If a command is specified, show help for that command.`)
3032
console.log(`Unknown command: ${command}`);
3133
}
3234

33-
export default function run(...args) {
35+
export default async function run(...args) {
3436
// eslint-disable-next-line security/detect-non-literal-fs-filename
3537
const commands = fs.readdirSync(dirname).filter(file => file.endsWith('.js'));
3638

3739
if (args.length === 0) {
3840
console.log('Available commands:');
39-
for (const commandFile of commands) {
41+
const modules = await Promise.all(
42+
commands.map(command =>
43+
import(`./${command}`).catch(() => ({
44+
description: '<error loading command module>'
45+
}))
46+
)
47+
);
48+
for (let i = 0; i < commands.length; i++) {
49+
const commandFile = commands.at(i);
50+
const commandModule = modules.at(i);
4051
const command = commandFile.slice(0, -3);
41-
console.log(` ${command}`);
52+
console.log(` ${command} - ${commandModule.description || '(no description provided)'}`);
4253
}
43-
console.log(`\nUse 'vg help <command>' to get help for a specific command.`);
54+
console.log(`\nUse 'vg help [command]' to get help for a specific command.`);
4455
return;
4556
}
4657
return help(...args);

packages/vibe-grep/src/rules/dist-types.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This rule checks that generated TypeScript declaration files do not
33
# contain any import or export statements that reference modules
44
# under the '@msinternal/' namespace. Such imports/exports indicate
5-
# that the declarations were not rolled up by the dtsroll tool.
5+
# that the declarations were not processed by the dtsroll tool.
66

77
id: no-msinternal
88
language: TypeScript

0 commit comments

Comments
 (0)