nwb icon indicating copy to clipboard operation
nwb copied to clipboard

Add built-in linting

Open insin opened this issue 7 years ago • 6 comments

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.

insin avatar Aug 13 '16 14:08 insin

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

kabriel avatar Feb 15 '17 01:02 kabriel

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 avatar Feb 15 '17 01:02 insin

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.

insin avatar Feb 15 '17 02:02 insin

@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.

kabriel avatar Mar 08 '17 19:03 kabriel

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"
  ]
}

cedricdelpoux avatar Jul 20 '17 07:07 cedricdelpoux

@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.

walliski avatar Sep 07 '18 11:09 walliski