Turn the absolute file paths and line numbers in the output of the tool into hyperlinks

This is an example output:

/usr/local/bin/node /usr/local/bin/elm-make src/elm/Main.elm --output=builds/main.js
-- TYPE MISMATCH ---------------------------------------------- src/elm/Main.elm

The type annotation for `init` does not match its definition.

35| init : Maybe Route.Location -> ( Model, Cmd Msg )
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The type annotation is saying:

    Maybe Route.Location -> ( { route : Maybe Route.Location }, Cmd Msg )

But I am inferring that the definition has this type:

    Maybe Route.Location
    -> ( { route : Maybe Route.Location -> Route.Model }, Cmd a )

Detected errors in 1 module.

Process finished with exit code 1

This is the regex that I came across:

http://regexr.com/3egqu

However, creating an output filter from it occurs as follows:

enter image description here

does not work.

So far, I only know that the following works: ------ ($FILE_PATH$)

And it turns the file path into a link:

enter image description here

Help me find a way to include line numbers in links.

+4
source share
1 answer

Here is what I came up with:

Firstly,

elm-make --report json

outputs build errors in structured JSON;

$ elm-make --report json src/main.elm
[{"tag":"unused import","overview":"Module `Bootstrap.CDN` is unused.","details":"Best to remove it. Don't save code quality for later!","region":{"start":{"line":3,"column":1},"end":{"line":3,"column":28}},"type":"warning","file":"src/main.elm"}]

Now you can pass this output through jq (see here). reformat it to

elm make src/main.elm --report json --output ./public/app.js | \
jq '.[] | { type: .type, file: .file, line: .region.start.line|tostring, tag: .tag, column: .region.start.column|tostring, tag: .tag, details: .details }' | \
jq --raw-output '. | "[" + (.type|ascii_upcase) + "] " + .file + ":" + .line + ":" + .column + " " + .tag + " -- " + .details + "\n"'

which gives you formatted output;

[WARNING] src/main.elm:9:1 unused import -- Best to remove it. Don't save code quality for later!

[WARNING] src/main.elm:17:1 missing type annotation -- I inferred the type annotation so you can copy it into your code:

main : Program Never Model Main.Msg

intellij,

$FILE_PATH$:$LINE$:$COLUMN$ $MESSAGE$

, , .

+2

Source: https://habr.com/ru/post/1658822/


All Articles