Skip to content

Commit 24a09a9

Browse files
committed
feat: add support for Nix files
Signed-off-by: Austin Seipp <aseipp@pobox.com>
1 parent 44c18b3 commit 24a09a9

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

internal/core/format.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ var CommentsByNormedExt = map[string]map[string]string{
5353
"blockStart": `(\{-.*)`,
5454
"blockEnd": `(.*-\})`,
5555
},
56+
".nix": {
57+
"inline": `(#.+)`,
58+
"blockStart": `(/\*.*)`,
59+
"blockEnd": `(.*\*/)`,
60+
},
5661
}
5762

5863
// FormatByExtension associates a file extension with its "normed" extension
@@ -92,6 +97,7 @@ var FormatByExtension = map[string][]string{
9297
`\.(?:yaml|yml)$`: {".yml", "data"},
9398
`\.(?:json)$`: {".json", "data"},
9499
`\.(?:toml)$`: {".toml", "data"},
100+
`\.(?:nix)$`: {".nix", "code"},
95101
}
96102

97103
// FormatFromExt takes a file extension and returns its [normExt, format]

testdata/features/lint.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ Feature: Lint
4343
test.proto:31:1:vale.Annotations:'NOTE' left in text
4444
"""
4545

46+
Scenario: Lint a Nix file
47+
When I lint "test.nix"
48+
Then the output should contain exactly:
49+
"""
50+
test.nix:3:3:vale.Annotations:'NOTE' left in text
51+
test.nix:7:5:vale.Annotations:'XXX' left in text
52+
test.nix:10:6:vale.Annotations:'NOTE' left in text
53+
test.nix:17:7:vale.Annotations:'TODO' left in text
54+
"""
55+
4656
Scenario: Lint an Org file
4757
When I lint "test.org"
4858
Then the output should contain exactly:

testdata/fixtures/formats/test.nix

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
# NOTE: This is a sample Nix configuration file
4+
let
5+
myVar = "hello world";
6+
7+
# XXX: This needs to be fixed later
8+
brokenFunction = x: y: x + y + 1;
9+
10+
/* NOTE: Multi-line comment
11+
that spans multiple lines
12+
*/
13+
myPackage = pkgs.stdenv.mkDerivation {
14+
pname = "example";
15+
version = "1.0.0";
16+
17+
# TODO: Add proper source
18+
src = ./.;
19+
20+
buildPhase = ''
21+
echo "Building..."
22+
'';
23+
};
24+
in
25+
{
26+
inherit myPackage;
27+
28+
# XXX should not match in code
29+
xxx = "XXX";
30+
}

0 commit comments

Comments
 (0)