3

I'm setting up ESLint and Prettier for my Next.js Project. I have followed one of the articles this one.

Here is my package.json file (partial) so far:

  "lint-staged": {
    "*.{js,jsx}": [
      "eslint '*/**/*.{js,jsx}' --fix"
    ]
  }

Although I have copied and pasted but couldn't able to understand that *.{js,jsx} & */**/*.{js,jsx} what actually these patterns mean? In addition: *.+(js|jsx) want to know about this pattern.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Rashed Rahat
  • 2,357
  • 2
  • 18
  • 38
  • 1
    `*.+(js|jsx)` seems to be part of a regular expression. Glob is what shells implement for file path matching. – Felix Kling May 11 '21 at 08:06

1 Answers1

2

It's regex-like called a glob pattern, so it knows which files it should apply the command to.

foo.js matches that
bar.php does not.

The second one is the actual JS lint command. It basically means that everthing that matches that structure gets eslint.

You could also set "eslint 'src/javascript/*.{js,jsx}' --fix" for example, if that is the only directory you want it to check it, leaving all other JS files alone.

Martijn
  • 15,791
  • 4
  • 36
  • 68
  • 1
    It's not a regex because if it was `*` would be a quantifier for zero to infinity, `.` would be any character, and `{js,jsx}` would not be valid, as it's supposed to be a quantifier but doesn't have numbers for min and max. – VLAZ May 11 '21 at 08:04
  • 2
    It's a [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) (or maybe some "extended form" or it). – Felix Kling May 11 '21 at 08:05
  • Wanted to keep it simple, but i suppose I should use the correct term :) – Martijn May 11 '21 at 08:05