insin / nwb

A toolkit for React, Preact, Inferno & vanilla JS apps, React libraries and other npm modules for the web, with no configuration (until you need it)
Other
5.57k stars 331 forks source link

Add built-in linting #157

Open insin opened 8 years ago

insin commented 8 years ago

I removed linting from an early version of nwb because code style is too divisive a subject, but create-react-app shows how useful including a default ESLint setup which only lints for correctness is.

kabriel commented 7 years ago

Would really like to see this, or at least a guide showing how I could add this via the nwb config.

insin commented 7 years ago

Assuming you have eslint, eslint-loader and whatever plugins you need installed, plus an .eslintrc, it should be something like this:

var extraWebpackConfig = {
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'pre',
        loader: 'eslint-loader',
        exclude: /node_modules/
      }
    ]
  }
}

module.exports = {
  webpack: {
    extra: extraWebpackConfig
  }
}

We would also need a way to disable use of NoEmitOnErrorsPlugin, which nwb could do automatically if ESLint support is added and enabled.

insin commented 7 years ago

Created https://github.com/MoOx/eslint-loader/issues/153, which would allow nwb to manage the ESLint dependency for you in a way which supports global usage.

kabriel commented 7 years ago

@insin How would I now run just a linter step? I want to run the linter as part of the CI/CD pipeline so I would want something like the following in my package.json right?

"scripts": { "lint": "nwb lint" }

Or is there another way? This would need to terminate with a proper error code so the CI pipeline can respond correctly.

cedricdelpoux commented 7 years ago

The PR MoOx/eslint-loader#183 been merged @insin.

Could we hope a default config with prettier and react plugins?

{
  "parser": "babel-eslint",
  "plugins": [
    "prettier",
    "react"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:react/recommended",
    "prettier"
  ]
}
walliski commented 6 years ago

@insin Is there any progress on this matter? I agree with you that some kind of linting would be nice to have, if not to check style, to only detect common pitfalls in the code.