Skip to content

Instantly share code, notes, and snippets.

@detain
Created August 16, 2023 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detain/e3809bf129bf726f0eec2fa6fb89568f to your computer and use it in GitHub Desktop.
Save detain/e3809bf129bf726f0eec2fa6fb89568f to your computer and use it in GitHub Desktop.
Run tsc/vue-tsc converting the output to brief/easy to read JSON
#!/bin/bash
npm i -g @aivenio/tsc-output-parser;
echo "Running vue-tsc and parsing output into errors.json";
npx vue-tsc --strict --noEmit | npx tsc-output-parser > errors.json;
echo "remapping errors.json";
echo '<?php
$errors = [];
$jsonOpts = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
$json = json_decode(file_get_contents("errors.json"),true);
foreach ($json as $row) {
$errors[] = [
"path" => $row["value"]["path"]["value"],
"line" => $row["value"]["cursor"]["value"]["line"],
"col" => $row["value"]["cursor"]["value"]["col"],
"code" => $row["value"]["tsError"]["value"]["errorString"],
"text" => trim($row["value"]["message"]["value"])
];
}
file_put_contents("errors.json", json_encode($errors, $jsonOpts));' | php;
sed -e s#"\({\"path\":\)"#"\n \1"#g -e s#"}]$"#"}\n]"#g -i errors.json;
echo "done";
@detain
Copy link
Author

detain commented Aug 16, 2023

Will generate a file errors.json with contents that look something like this:

[
  {"path":"src/components/account/LinkedAccounts.vue","line":25,"col":28,"code":"TS7006","text":"Parameter 'type' implicitly has an 'any' type."},
  {"path":"src/components/account/LinkedAccounts.vue","line":28,"col":53,"code":"TS2554","text":"Expected 1 arguments, but got 2."},
  {"path":"src/components/account/LinkedAccounts.vue","line":41,"col":28,"code":"TS7006","text":"Parameter 'type' implicitly has an 'any' type."},
  {"path":"src/components/Alert.vue","line":13,"col":64,"code":"TS2339","text":"Property 'type' does not exist on type 'never'."}
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment