Skip to content

Commit

Permalink
Merge pull request #1259 from Agoric/mk/better-format-hint
Browse files Browse the repository at this point in the history
lint: highlight `yarn format` usage on errors
  • Loading branch information
mujahidkay authored Dec 23, 2024
2 parents 63e6d5b + 790be34 commit a67337b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint-fix": "yarn lint --fix",
"lint": "eslint 'snippets/**/*.js'",
"format": "node scripts/markdown-js-snippets-linter.mjs 'main/**/*.md' --fix && prettier --write '**/*.md' --config .prettierrc.json",
"lint:format": "node scripts/markdown-js-snippets-linter.mjs 'main/**/*.md' && prettier --check '**/*.md' --config .prettierrc.json",
"lint:format": "node scripts/format.mjs",
"build": "exit 0"
},
"packageManager": "[email protected]",
Expand Down
12 changes: 12 additions & 0 deletions scripts/format.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { exec } from 'child_process';

exec('node scripts/markdown-js-snippets-linter.mjs "main/**/*.md" && prettier --check "**/*.md" --config .prettierrc.json', (err, stdout, stderr) => {
if (err) {
const modifiedStderr = stderr.replace(
'Run Prettier with --write to fix',
'Run `yarn format` to fix'
);
console.warn(modifiedStderr);
process.exit(1);
}
});
2 changes: 1 addition & 1 deletion scripts/markdown-js-snippets-linter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const processFiles = async (globPattern, fix = false) => {
if (fix) {
console.log("All matching files have been updated with the necessary changes.");
} else {
console.error("Run with --fix to automatically fix these errors and replace \`\`\`javascript with \`\`\`js.");
console.error("Run `yarn format` to automatically fix these errors");
}
} else {
console.log("No errors found in any of the matching files.");
Expand Down

0 comments on commit a67337b

Please sign in to comment.