electron-userland / electron-forge-templates

Templates bundled with Electron Forge <= 5 to create Electron apps using popular JavaScript frameworks
107 stars 23 forks source link

Add ESLint support to React template #11

Closed soulchainer closed 7 years ago

soulchainer commented 7 years ago

Just as #9, React template needs ESLint support out of the box.

It has the .eslintrc file ok, but it's simply unused without the eslint packages. And, of course, like in the mentionated issue, the generated package.json contains:

  "lint": "echo \"No linting configured\""

Most peculiar thing about this?

The default "Vanilla ES6/7" template, that doesn't need it, installs the devDependencies that the React template needs and don't have. Just copy pasted from a generated "Vanilla ES6/7" package.json:

"devDependencies": {
        "babel-plugin-transform-async-to-generator": "^6.22.0",
        "babel-preset-env": "^1.1.8",
        "babel-preset-react": "^6.23.0",
        "electron-prebuilt-compile": "1.4.15",
        "eslint": "^3.15.0",
        "eslint-config-airbnb": "^14.1.0",
        "eslint-plugin-import": "^2.2.0",
        "eslint-plugin-jsx-a11y": "^4.0.0",
        "eslint-plugin-react": "^6.10.0"
   }

These two last dependencies get unused in a vanilla ES6/7 project.

I think this happens just because eslint-config-airbnb shouldn't be used in "Vanilla ES6/7". Why? Because what you just saw: it includes config about React.

There are two eslint-config-whatever official npm packages available for enforcing airbnb coding style:

  1. eslint-config-airbnb. Includes everything: vanilla ES6+ React.
  2. eslint-config-airbnb-base. Includes only vanilla ES6.

So "Vanilla ES6/7" template ends having these extra packages it doesn't need and doesn't use: this only makes the download bigger. And "React" template ends not having these extra packages it needs for linting and with linting not out-the-box because the linting it need it's going to "Vanilla ES6/7" :(.

If there is a "React" template, this template should be the one having the React-related stuff.

I took a brief look to all the files here, thinking about to make a PR, but I'm a bit lost about all the importing and etc. I didn't get where are coming all the imported pieces in that time, so better leave it here to someone more close to it ñ_ñ.

Apart from the proper packages, I think the other only needed change is with the lint npm script (and adding .eslintcache to .gitignore):

  "lint": "eslint --cache --ext .jsx,.js src"

Would suffice. At least, I think so: for now, it lints.