From 790be34008dfa936336d33585ecbf2d12ab5dae0 Mon Sep 17 00:00:00 2001 From: Mujahid Khan <106528609+mujahidkay@users.noreply.github.com> Date: Mon, 23 Dec 2024 15:40:34 +0500 Subject: [PATCH] lint: highlight yarn format usage on errors --- package.json | 2 +- scripts/format.mjs | 12 ++++++++++++ scripts/markdown-js-snippets-linter.mjs | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 scripts/format.mjs diff --git a/package.json b/package.json index 5efcb7678..f413a82c7 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/format.mjs b/scripts/format.mjs new file mode 100644 index 000000000..097f19f78 --- /dev/null +++ b/scripts/format.mjs @@ -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); + } +}); diff --git a/scripts/markdown-js-snippets-linter.mjs b/scripts/markdown-js-snippets-linter.mjs index 31e8b587c..20593b599 100644 --- a/scripts/markdown-js-snippets-linter.mjs +++ b/scripts/markdown-js-snippets-linter.mjs @@ -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.");