Home > Net >  What purpose does the Asterisk (*) serve in package.json files?
What purpose does the Asterisk (*) serve in package.json files?

Time:03-20

I want to use lint-staged to run hooks only on staged files in a node.js project. The docs suggest adding the following code to the package.json file;

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

I have also seen the following code elsewhere in another codebase;

"lint-staged": {
        "**/*": "prettier --write --ignore-unknown"
    }

What purpose does the asterisk(s) serve? I don't suppose it's simply a placeholder. Thanks for the help.

CodePudding user response:

As the readme says, those are glob patterns.

"*": "your-cmd"

will match any file (* matches anything by definition)

"**/*": "prettier --write --ignore-unknown"

will match:

  • ** - "≥ 0 characters crossing directory boundaries", followed by
  • / - A directory boundary, followed by
  • * - Anything
  • Related