Add warn-short-path-literals setting#13489
Conversation
|
We'd much appreciate a test case as well. I see that |
Never done tests in Meson, but I can try to. Should I commit the test for |
216cea4 to
2b6822e
Compare
|
@k1gen Sounds good to me. Unrelated: looks like the formatter needs to be run on the current diff. |
2b6822e to
e4e7369
Compare
Yeah, my bad. Thought I did that... How does the test look? |
|
Oops. Works on my machine: [olk@think:~/dev/nix/build]$ ../outputs/out/bin/nix eval --expr 'test/subdir'
/home/olk/dev/nix/build/test/subdir
[olk@think:~/dev/nix]$ checkPhase
...
65/205 nix-functional-tests:main / short-path-literals OK 0.84s
...
Ok: 199
Fail: 0Any ideas, @roberth? |
e4e7369 to
deb116e
Compare
|
The test passes even if I don't create and populate test directories, should I remove this part in order not to litter in the tests dir? # Create test directories
mkdir -p "$TEST_ROOT/test/subdir"
echo "test content" > "$TEST_ROOT/test/file.txt" |
That'd be good, thanks! |
Add a new setting to warn about path literals that don't start with "." or "/". When enabled, expressions like `foo/bar` will emit a warning suggesting to use `./foo/bar` instead. A functional test is included. The setting defaults to false for backward compatibility but could eventually default to true in the future. Closes: #13374 Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
deb116e to
6d46dc9
Compare
|
Thanks again! |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Add warn-short-path-literals setting
Closes: #13374
Problem
Path literals that don't start with
./or../(likefoo/bar) can be confusing and less explicit than their prefixed counterparts. Even experienced Nix developers are sometimes unaware that bare path literals are valid syntax, leading to inconsistent code style and potential confusion about the role of path expressions.Solution
This PR adds a new
warn-short-path-literalssetting toEvalSettingsthat emits warnings when encountering relative path literals that don't start with.or/. When enabled, expressions likefoo/barwill suggest using./foo/barinstead.The implementation follows the same pattern as the existing
no-url-literalsexperimental feature but uses a regular setting instead, as requested in the issue.Examples
Without the setting (default behavior):
With the setting enabled:
P.S.: Sorry if I've got something wrong, it's my first contribution to OSS in a while, and first one to the Nix project. Thanks.