Lint-staged: Validation Warning: Unknown option "*.js" with value XXX was found in the config root.

Created on 6 Jul 2018  ·  12Comments  ·  Source: okonet/lint-staged

Description

I get this error on precommit hook:
● Validation Warning:

Unknown option "*.js" with value ['prettier-eslint --write', 'git add'] was found in the config root.

You are probably trying to mix simple and advanced config formats. Adding

"linters": {
"*.js": ["prettier-eslint --write","git add"]
}

will fix it and remove this message.

Please refer to https://github.com/okonet/lint-staged#configuration for more information...

It seems that in the last version 7.2.0 the configuration options changed:
from

  "lint-staged": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    "ignore": [
      "**/src/scripts/*.min.js"
    ]
  },

to

  "lint-staged": {
    "linters": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    },
    "ignore": [
      "**/src/scripts/*.min.js"
    ]
  },

Documentation need to be updated.

Steps to reproduce

Install version 7.20
Add the following config in package.json:

  "lint-staged": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    "ignore": [
      "**/src/scripts/*.min.js"
    ]
  },

Environment

  • OS: macOS High Sierra
  • Node.js: v9.10.1
  • lint-staged: 7.2.0

Most helpful comment

We are to the classic problem here, who writes the code thinks usage/documentation is clear and obvious.
Neither the advance config format neither the warning does not explain, or give an example how a correct config should be. Literally here is the avance format:

Advanced config format
_To set options and keep lint-staged extensible, advanced format can be used. This should hold linters object in linters property._

To set options and keep lint-staged extensible, advanced format can be used
This does not say nothing, what options?, what does it mean keep extensible?
What about: To customize lint-staged some advance options are available:

This should hold linters object in linters property.
What is the linters object? What is the linters property? and where should I keep it?
What about: To use the avance options the config format should be as the following:

   "lint-staged": {
    "linters": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    },
    "ignore": [
      "**/src/scripts/*.min.js"
    ]
  }

Now is useless to discuss on this and point references how documentation should be written. Just keep in mind that when we write configuration documentation we should put ourself in other shoes.

All 12 comments

No there was no change. The warning points you to the relevant documentation. This is happening because you must have added ignore field. Closing as lint-staged is working as intended and the warning is as helpful as it can be.

The important part of the waring is You are probably trying to mix simple and advanced config formats.

The warning does not point any where relevant to the warning it self, indeed I have added ignore field if you see the above example. The documentation is wrong because it does not explain how to config properly. This is what litteraly is written in the documentation:

{
  "lint-staged": {
    "*": "your-cmd"
  }
}

And the configuration option itself are ambiguous and confusing:
So if I do not have advance option I should use:

  "lint-staged": {
    "linters": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    }
  },

But If I have advance options I have to use (nest into linters the config, why?)

  "lint-staged": {
    "linters": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    },
    "ignore": [
      "**/src/scripts/*.min.js"
    ]
  }

And an explanatory example of the above is missing

Do you see that there are 2 sub headings under Configuration, namely Simple config format and Advanced config format? Please read through these. Because as the warning told you, you are mixing these 2 formats. If you have any specific suggestions about how the documentation could be clearer, a PR is welcome. But in this case I genuinely do not think the documentation is at fault.

We are to the classic problem here, who writes the code thinks usage/documentation is clear and obvious.
Neither the advance config format neither the warning does not explain, or give an example how a correct config should be. Literally here is the avance format:

Advanced config format
_To set options and keep lint-staged extensible, advanced format can be used. This should hold linters object in linters property._

To set options and keep lint-staged extensible, advanced format can be used
This does not say nothing, what options?, what does it mean keep extensible?
What about: To customize lint-staged some advance options are available:

This should hold linters object in linters property.
What is the linters object? What is the linters property? and where should I keep it?
What about: To use the avance options the config format should be as the following:

   "lint-staged": {
    "linters": {
      "*.{js,scss}": [
        "prettier-eslint --write",
        "git add"
      ]
    },
    "ignore": [
      "**/src/scripts/*.min.js"
    ]
  }

Now is useless to discuss on this and point references how documentation should be written. Just keep in mind that when we write configuration documentation we should put ourself in other shoes.

Nice rant. Like I said. A PR is welcome.

Thats exactly the reason I’d like to kill 2 different formats.

@okonet I am still seeing this warning. Here is my package.json, I have tried couple of variation to setup lint-staged
Try 1:

{
  scripts:{
      "lint-staged": "lint-staged"
  },
  "lint-staged": {
        "**/*.js": "git add"
  }
}

Try 2:

{
  scripts:{
      "lint-staged": "lint-staged"
  },
  "lint-staged": {
        "linters": {
          "**/*.js": [
            "git add"
          ]
        },
        "ignore": [
          "**/dist/*.min.js"
        ]
      }
}

@rgadda the issue you are facing is a different one. See #482.

I am also running into this issue, on 7.2.2 version of lint-staged with 0.14.3 version of husky. This is my package.json:

{
  "scripts: {
    "precommit": "lint-staged"
  },
  "lint-staged": {
    "linters": {
      "*.{js,jsx}": ["npm run prettier", "git add"]
    }
  }
}

Based off documentation, this should be the correct format, but I am still receiving the warning.

  },
  "lint-staged": {
    "linters": {
      "src/**/*.{js,jsx,json,css}": [
        "prettier --single-quote --write",
        "git add"
      ]
    }
  },
  "scripts": {
    "precommit": "lint-staged",
     [...]
   }

Getting the same warning, any update son this issue?

@imthinhvu, @marco-fp Please continue the discussion in #482 as this issue is quite different from the one you are facing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shermendev picture shermendev  ·  4Comments

benjamincharity picture benjamincharity  ·  4Comments

thedamon picture thedamon  ·  3Comments

pumanitro picture pumanitro  ·  7Comments

jitenderchand1 picture jitenderchand1  ·  3Comments