javascripteslint

Cross platform ESLint command to run on the 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 documentation.

    "scripts": {
      "lint": "eslint . --ext .js,.ts,.tsx",
    }
    

    Unix-like: ✅ 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",
    }
    

    Unix-like: 🚫 Windows: ✅

  3. GLOB matching pattern with quotes.

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

    Unix-like: ✅ 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?


Solution

  • I’m 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.