neutrinojs / neutrino

Create and build modern JavaScript projects with zero initial configuration.
https://neutrinojs.org
Mozilla Public License 2.0
3.95k stars 213 forks source link

airbnb & standardjs presets cause warning if react is not used #1622

Closed davidje13 closed 8 months ago

davidje13 commented 4 years ago

The minimal config:

const library = require('@neutrinojs/library');
const airbnb = require('@neutrinojs/airbnb');

module.exports = {
  options: { root: __dirname },
  use: [airbnb(), library({ name: 'foo' })],
};

package.json

  "scripts": {
    "build": "webpack --mode production"
  }

Produces a warning when npm run build is executed:

Warning: React version was set to "detect" in eslint-plugin-react settings,
but the "react" package is not installed. Assuming latest React version for linting.

This is because both the airbnb and standardjs packages bring in eslint-plugin-react, but this should not be used in projects which do not contain React: https://github.com/yannickcr/eslint-plugin-react/issues/1955#issuecomment-667553828

I'm not sure what the correct fix is here; maybe it's possible to programmatically disable this eslint plugin unless React is being used? Having to provide 2 separate copies of the packages (one with react and one without) doesn't seem like a great solution. The only other option I can think of is to leave it to the user to install the package if it is relevant to them.

It might be nice if the react version could be set to "none" in the eslint-plugin-react settings, but I don't know if they would be willing to add that feature since they've already said it simply shouldn't be installed in non-react projects.

edmorley commented 4 years ago

@davidje13 Hi! The upstream AirBnB preset itself is designed to be React specific -- they have a base version without that, that Neutrino also offers: https://neutrinojs.org/packages/airbnb-base/

So if using AirBnB the solution is to use @neutrinojs/airbnb-base not @neutrinojs/airbnb. If using the Standard JS preset, then yeah I agree there isn't a great option at the moment.

To be honest the demand for the Standard JS preset is so low (and the style quite at odds with both AirBnB and prettier, that I could never recommend it), that I've been thinking of just removing the Neutrino preset for it and letting users add it manually using the @neutrinojs/eslint base preset if needed (it's only half a dozen lines in a NeutrinoJS).

davidje13 commented 4 years ago

Fair enough. I only encountered this while testing my JS->TS lint rule rewriter with StandardJS, but I wouldn't use StandardJS in my own projects anyway.