I just wrote a executable for linting nix programs (intended to be consumed in high-level “UI”)
It can produce structured outputs (JSON) of diagnostics, including locations, fixes, kinds.
echo '{ a, ..., ...} : 1' | build/libnixf/nixf-tidy --pretty-print --variable-lookup
[
{
"args": [],
"fixes": [
{
"edits": [
{
"newText": "",
"range": {
"lCur": {
"column": 3,
"line": 0,
"offset": 3
},
"rCur": {
"column": 8,
"line": 0,
"offset": 8
}
}
}
],
"message": "remove `...`"
}
],
"kind": 22,
"message": "extra `...` for lambda formal",
"notes": [],
"range": {
"lCur": {
"column": 3,
"line": 0,
"offset": 3
},
"rCur": {
"column": 8,
"line": 0,
"offset": 8
}
},
"severity": 1,
"sname": "sema-formal-extra-ellipsis",
"tag": []
},
{
"args": [
"a"
],
"fixes": [],
"kind": 27,
"message": "definition `{}` is not used",
"notes": [],
"range": {
"lCur": {
"column": 2,
"line": 0,
"offset": 2
},
"rCur": {
"column": 3,
"line": 0,
"offset": 3
}
},
"severity": 2,
"sname": "sema-def-not-used",
"tag": [
0
]
}
]
I’d like to integrate this somehow into GitHub CI/CD (for example producing PR reviews based on it). Anyone wants to take this ?
You can test the command using:
nix build github:nix-community/nixd?rev=55b9fd28ac1f82345783af1006565cee768c8dd5#nixd
For example
❯ echo 'rec { }' | result/bin/nixf-tidy --variable-lookup --pretty-print
[
{
"args": [],
"fixes": [
{
"edits": [
{
"newText": "",
"range": {
"lCur": {
"column": 0,
"line": 0,
"offset": 0
},
"rCur": {
"column": 3,
"line": 0,
"offset": 3
}
}
}
],
"message": "remove `rec` keyword"
}
],
"kind": 28,
"message": "attrset is not necessary to be `rec`ursive ",
"notes": [],
"range": {
"lCur": {
"column": 0,
"line": 0,
"offset": 0
},
"rCur": {
"column": 3,
"line": 0,
"offset": 3
}
},
"severity": 2,
"sname": "sema-extra-rec",
"tag": [
0
]
}
]
Also I would like to write some patterns commonly used in Nixpkgs. (e.g. lib
, stdenv
occurrences), any suggestion?