Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
check-openapi: Print diffs for Prettier formatting errors.
Anders Kaseorg8854cd794568
diff --git a/package.json b/package.jsonindex 10cffd12ce5..e290cc0fc97 100644--- a/package.json+++ b/package.json@@ -99,6 +99,7 @@"@typescript-eslint/parser": "^4.0.1","babel-plugin-rewire-ts": "^1.4.0","callsites": "^3.1.0",+ "diff": "^4.0.1","difflib": "^0.2.4","es-check": "^6.0.0","eslint": "^7.2.0",diff --git a/tools/check-openapi b/tools/check-openapiindex 139bf0a6f1a..c30ed98a81b 100755--- a/tools/check-openapi+++ b/tools/check-openapi@@ -4,6 +4,7 @@const fs = require("fs");+const Diff = require("diff");const ExampleValidator = require("openapi-examples-validator");const Prettier = require("prettier");const SwaggerParser = require("swagger-parser");@@ -64,7 +65,20 @@ async function checkFile(file) {if (formatted !== node.value.value) {ok = false;const {line, col} = lineCounter.linePos(node.value.range[0]);- console.error("%s:%d:%d: Format description with Prettier", file, line, col);+ console.error("%s:%d:%d: Format description with Prettier:", file, line, col);+ let diff = "";+ for (const part of Diff.diffLines(node.value.value, formatted)) {+ const prefix = part.added+ ? "\u001B[32m+"+ : part.removed+ ? "\u001B[31m-"+ : "\u001B[34m ";+ diff += prefix;+ diff += part.value.replace(/\n$/, "").replace(/\n/g, "\n" + prefix);+ diff += "\n";+ }+ diff += "\u001B[0m";+ console.error(diff);}}},