Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: highlight yarn format usage on errors #1259

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "yarn@4.5.0",
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
Loading