Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspections #26

Open
JojOatXGME opened this issue Jan 26, 2021 · 3 comments
Open

Inspections #26

JojOatXGME opened this issue Jan 26, 2021 · 3 comments

Comments

@JojOatXGME
Copy link
Contributor

JojOatXGME commented Jan 26, 2021

This issue shall list some suggestions for inspections we might want to implement. New suggestions might be added over time. You can of course add your own suggestions in the comments.

Legacy | Expressions not supported in this version

Reports expressions which are not supported in the specified version. This inspection should have an option to specify the version.

Legacy | Usage of unquoted `or`

In certain situations, the Nix Expression Language allows using or as identifier or unquoted attribute. This seems to be permitted for backward compatibility. However, the behavior is not always as expected. See the following expression:

let f = x: x; or = 0; in [ "before" f or "after" ] #-> [ "before" 0 "after" ]

If you replace or with another identifier, the result would be different:

let f = x: x; id = 0; in [ "before" f id "after" ] #-> [ "before" <LAMBDA> 0 "after" ]

Also note that we would get another result if we replace f with a longer attribute path:

let f._ = x: x; or = 0; in [ "before" f._ or "after" ] #-> [ "before" <LAMBDA> ]

Due to this unexpected differences, we should warn at least about the usage in such scenarios. We might optionally also warn the user when the keyword is used as an attribute, although it doesn't have such consequences.

Legacy | Usage of unquoted URL

Reports usages of the URL syntax, which allows using unquoted URLs in the Nix Expression Language. This syntax was deprecated by RFC 45 in Nix 2.4.

Probable bugs | Indented strings inhibitor

Reports tabs and carriage returns (i.e. CR and CRLF). Leading whitespace is usually removed from indented strings (strings in double single quotes). However, tabs and carriage returns prevent this feature from working. (#3759)

Probable bugs | Infinite recursion

Reports attributes in recursive sets which cannot be resolved due to infinite recursion.

rec {
    x = y;
    y = x;
}

Probable bugs | Invalid antiquotation value

Reports expressions in antiquotations which evaluate to something that cannot be coerced into a string. Expressions evaluating to null are ignored in attribute declarations.

Probable bugs | Merging options in modules with `//`

If you merge multiple sets of options with // instead of mkMerge, one of both sets might be ignored.

Probable bugs | Option defined outside `config` attribute

Warns about options which are defined outside the config attribute in a module if there is a config or options attribute. In such case, the option would be ignored. Option definitions outside the config attribute are only respected if the module does not contain any attribute called config or options.

Probable bugs | Path does not exist

Reports path literals which point to non-existent files. This inspection should have an option to ignore absolute pathes.

Probable bugs | Quoted path

Reports string literals when path literals should be used. When a string literals is used as relative path, the path might be resolved differently depending on how the file is loaded. This can be avoided by using path literals which are always resolved relative to the containing file.

Redundancy | Unused attribute or variable

Reports variables and attributes which are never used.

let var = "unused"; in true

or

let
    var = { attr1 = "used"; attr2 = "unused"; };
in
    var.attr1

Verbose or redundant code constructs | Redundant antiquotation

Reports unnecessary antiquotations in strings and attribute paths.

"a ${"b"} c" // → "a b c"
var.${"attr"} // → var."attr"

Verbose or redundant code constructs | Redundant inherit

Reports redundant usage of the inherit keyword. Specifically, this inspection reports the inheritance of a local variable within a let expression.

let x = 42; in
let inherit x; in
x

Verbose or redundant code constructs | Redundant parenthesis

Reports redundant parenthesis.

(1 + 2) + 3

This inspection should have an option to allow clarifying parenthesis which doesn't change the meaning but clarify the precedence.

(1 * 2) + 3

Verbose or redundant code constructs | Redundant quotes in attribute path

Reports unnecessary quotes in an attribute path.

var."attr" // → var.attr
var."${...}" // → var.${...}

Verbose or redundant code constructs | Successive let expressions can be merged

Reports let expressions which have another let expression as its direct parent. For example

let
    var1 = 18;
in
    let
        var2 = 24;
    in
        var1 + var2

can be simplified into

let
    var1 = 18;
    var2 = 24;
in
    var1 + var2

Verbose or redundant code constructs | Unnecessarily escaped character

Reports unnecessarily escaped characters in strings.

''\"'' // → ''"''
"\$" // → "$"

Visibility | Variable hides built-in

Reports variable declarations which hide built-in variables like true, false, null and import.

let false = true; in false

Visibility | Variable hides other variable

Reports variable declarations which hide other variables.

let var = ...; in
let var = ...; in
...

This inspection should have an option to include or exclude with expressions.

This Wiki page might also contain some inspirations: https://nixos.wiki/wiki/Nix_Language_Quirks

@hab25
Copy link

hab25 commented May 26, 2023

related:
https://github.com/astro/deadnix
https://github.com/nerdypepper/statix

@hab25
Copy link

hab25 commented Jun 3, 2023

related:
https://github.com/oxalica/nil/blob/dcd38b96c91a2d07552f824a6480e00dc7b4948a/docs/features.md?plain=1#L46
(note that the link is pinned to a commit and checking updates to this feature is probably worthwhile)

@hab25
Copy link

hab25 commented Jun 3, 2023

nerdypepper/statix

unfortunately looks to be somewhat abandoned (more than 4 months with no maintainer activity)

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

No branches or pull requests

2 participants