22

This is my directory structure.

enter image description here

I want to config some eslint rule to detect my code.

In .eslintrc, I write these configuration items.

{
  "extends": "airbnb",
  "rules": {
    "valid-jsdoc": 2,
    // Disable until Flow supports let and const
    "no-var": 0,
    "react/jsx-uses-react": 1,
    "react/jsx-no-undef": 2,
    "react/wrap-multilines": 2,
    "func-names": 0,
    "new-cap": 0,
    "no-undef": 0,
  },
  "plugins": [
    "react"
  ]
}

I have used npm script to run eslint.

  "scripts": {
    "lint": "eslint src"
  },

Normally, when I run npm run lint, it will detect all the files in src directory.

But, unfortunately, nothing output.

enter image description here

I don't know why. I guess maybe I have writed wrong configuration items. But after I write npm scripts "lint": "eslint src/component/App.jsx", eslint works.

So where is the problems? Eslint can detect single file well, but it can't detect all the files in some directory.

enter image description here

qiuyuntao
  • 2,314
  • 4
  • 19
  • 24
  • 1
    Do `eslint src/**` – Andrew Li Mar 05 '17 at 07:58
  • Useless @AndrewLi – qiuyuntao Mar 05 '17 at 08:00
  • 3
    Huh. What OS? Maybe try `eslint . --ext .jsx` in the root directory of the project? Or with quotes: `eslint 'src/**'`? – Andrew Li Mar 05 '17 at 08:00
  • eslint 'src/**' will be ok. But why eslint can't parse "eslint src", "eslint 'src/**" will be ok? – qiuyuntao Mar 05 '17 at 08:06
  • 1
    _eslint_ utilizes [glob](https://www.npmjs.com/package/glob#glob-primer) for file matching _(aka: "globbing")_. Read the _primer_ to find out more on the various kinds of _"globs"_ you can use with _eslint_. You can also use a `.eslintignore` file to specify which files and directories to exclude from linting. In some scenarios it's easier to match everything in the project directory then exclude the directories you don't want to match e.g. `node_modules` in `.eslintignore`. More info in the _"Ignoring Files and Directories"_ section [here](http://eslint.org/docs/user-guide/configuring). – RobC Mar 05 '17 at 14:30

1 Answers1

40

when you run eslint src, by default its looking for all the files with .js extension. I think in your case you want to change command to eslint src --ext .js,.jsx. This will look for all the files inside src with .js and/or .jsx extensions. (personally recommend)

If you want to use glob to solve this issue then you can change your cmd to eslint src/**/*.jsx

CLI docs: http://eslint.org/docs/user-guide/command-line-interface

Glob patterns help: http://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories

Gyandeep
  • 12,726
  • 4
  • 31
  • 42