tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.44k stars 93 forks source link

Add a warning for unused contracts #1071

Open rapenne-s opened 1 year ago

rapenne-s commented 1 year ago

Is your feature request related to a problem? Please describe.

It happens that when writing a contract and using it in another file, if we forget to apply the contract or make a typo, nothing will tell us about it

Describe the solution you'd like

some command to make nickel verify all existing contracts in my file and from imported files are used, it should report a warning if a contract isn't used.

Additional context

A concrete example

contract.ncl

{
  MyData = 
  {
    foo | Str,
    attribute | Str | default = "world",
  }
}

data.ncl

let {MyData, ...} = import "contract.ncl" in
{
  data = 
  [
    { foo = "hello", attribute = "monde", },
    { foo = "world", },
  ],
}

This will work, I may think everything is fine, but the contract is just not used here, it's missing data | Array MyData in the example.

yannham commented 1 year ago

As a side note, there is not real notion of "contract" for the interpreter right now: contracts are just values like any other. I guess what we want is a warning for unused variables in general.