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.

1
  • 1
    *.+(js|jsx) seems to be part of a regular expression. Glob is what shells implement for file path matching. Commented May 11, 2021 at 8:06

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
It's a glob pattern (or maybe some "extended form" or it).
Wanted to keep it simple, but i suppose I should use the correct term :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.