GollyJer
GollyJer

Reputation: 26752

Cross platform ESLint command to run on current directory recursively?

I'm looking to create a cross-platform package.json command to lint all .js, .ts, .tsx files in the current directory, recursively.

Here's what I've tried.

  1. This is directly from the ESLint CLI docs.
"scripts": {
  "lint": "eslint . --ext .js,.ts,.tsx",
}

*nix - ✅ Windows - 🚫

On Windows...

No files matching the pattern "." were found.
Please check for typing mistakes in the pattern.


2. GLOB matching pattern.

"scripts": {
  "lint": "eslint **/*.js **/*.ts **/*.tsx",
}

*nix - 🚫 Windows - ✅


3. GLOB matching pattern with quotes.

"scripts": {
  "lint": "eslint '**/*.js' '**/*.ts' '**/*.tsx'",
}

*nix - ✅ Windows - 🚫


This is a cross-platform project with developers using Mac, Linux, and Windows.

How do I get this single command to work on all three?

Upvotes: 6

Views: 1678

Answers (1)

Aligertor
Aligertor

Reputation: 643

Im working on similar problems right now. I had success with something like.

"scripts": {
  "lint": "eslint \"**/*.js\" \"**/*.ts\" \"**/*.tsx\"",
}

or shorter

"scripts": {
  "lint": "eslint \"**/*.{js,ts,tsx}\"",
}

Replacing single quotes with escaped double quotes is actually a pattern not eslint specific.

Maybe it helps.

Upvotes: 9

Related Questions