sheerun / prettier-standard

Formats with Prettier and lints with ESLint+Standard! (✿◠‿◠)
MIT License
868 stars 44 forks source link

lint flag not working with projects generated by create-react-app #88

Closed gbrlsnchs closed 4 years ago

gbrlsnchs commented 4 years ago

I have checked some closed issues about linting but I really don't understand the flag's purpose. When I run npx prettier-standard --lint <my-file>.js, it formats the file and then outputs All matched files use Standard code style!, although there are unused variables inside such file.

Does it run standard? If so, it's not working, because running npx standard <my-file>.js does detect the unused variable. So does it only check for formatting issues? If so, why? It should never fail since it formats the file just before checking.

Sorry if I missed anything here.

sheerun commented 4 years ago

Can you paste minimal example file to reproduce? Do you have .eslintrc or .eslintignore file?

It should check for all issues standard is checking for.

gbrlsnchs commented 4 years ago

It happens in projects built using create-react-app. I have created a test project by running npx create-react-app prettier-standard-react-bug and then installed prettier-standard by running yarn add -D prettier-standard.

Then, I ran npx prettier-standard --lint src/index.js (src/index.js is generated by create-react-app) and it passed linting, which was expected and correct.

Then I added an unused variable to that same file and ran again npx prettier-standard --lint src/index.js, which passed again, this time erroneously.

Here's the package.json content:

{
  "name": "prettier-standard-react-bug",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "react-scripts": "3.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "prettier-standard": "^15.0.1"
  }
}

Everything in it is generated by create-react-app expect for the devDependencies, which I added myself to test all of this.

I tested the same steps in a regular Node project with only prettier-standard and nothing else installed and it correctly detected the unused variable. Something tells me that eslintConfig is the culprit for React projects generated by create-react-app.

sheerun commented 4 years ago

prettier-standard allows for overridding eslint configuration

Please remove eslintConfig from your package.json to have pure standard configuration

gbrlsnchs commented 4 years ago

Does prettier-standard follow eslintConfig? If so, then I shall close this issue, since that's what I expect from this package.

sheerun commented 4 years ago

yes

gbrlsnchs commented 4 years ago

Okay, thanks!