Nwb: Add built-in linting

Created on 13 Aug 2016  路  6Comments  路  Source: insin/nwb

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.

enhancement

Most helpful comment

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.

All 6 comments

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

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.

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

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

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

.eslintrc { "parser": "babel-eslint", "plugins": [ "prettier", "react" ], "extends": [ "eslint:recommended", "plugin:react/recommended", "prettier" ] }

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AquiGorka picture AquiGorka  路  3Comments

rudfoss picture rudfoss  路  4Comments

insin picture insin  路  3Comments

bluce1017 picture bluce1017  路  5Comments

lachlanjc picture lachlanjc  路  3Comments