Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Add eslint-loader including eslint-plugin-graphql #1287

Closed
KyleAMathews opened this issue Jun 28, 2017 · 8 comments
Closed

[1.0] Add eslint-loader including eslint-plugin-graphql #1287

KyleAMathews opened this issue Jun 28, 2017 · 8 comments
Assignees

Comments

@KyleAMathews
Copy link
Contributor

Debugging GraphQL is a barrier to many people as most people aren't yet familiar with GraphQL. This would help a lot.

https://github.com/apollographql/eslint-plugin-graphql

For the rest of the eslint config, we should just copy CRA.

@cr101
Copy link

cr101 commented Aug 1, 2017

graphql-cli was announced today and it would be awesome if GatsbyJS worked with it out of the box

@maiertech
Copy link

Is there an example on how to configure eslint-plugin-graphql to make it work with Gatsby GraphQL queries?

@ryami333
Copy link

I considered creating gatsby-plugin-eslint, but for some reason you're not allowed to use enforce: "pre" in loader config, which is a bit of a deal breaker.

@jarodtaylor
Copy link

I added eslint-loader, by adding it to my gatsby-node.js file:

exports.modifyWebpackConfig = ({ config, stage }) => {
  if (stage === 'develop') {
    config.preLoader('eslint-loader', {
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
    });
  }
  return config;
};

It all seems to work fine, but when an eslint error pops up, it kills HMR, so I wanted to add in emitWarning: true to stop it from happening:

exports.modifyWebpackConfig = ({ config, stage }) => {
  if (stage === 'develop') {
    config.preLoader('eslint-loader', {
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
      options: {
        emitWarning: false,
      },
    });
  }
  return config;
};

Unfortunately, it fails:

There were errors with your webpack config:
[1]
module.preLoaders.0.options
object.allowUnknown , "options" is not allowed


Your Webpack config does not appear to be valid. This could be because of
something you added or a plugin. If you don't recognize the invalid keys listed
above try removing plugins and rebuilding to identify the culprit.
error Command failed with exit code 1.

@pieh
Copy link
Contributor

pieh commented Feb 21, 2018

@jarodtaylor check https://www.npmjs.com/package/webpack-configurator#configloaderkey-config-resolver - specifically "Config as an object with a resolver function.". options was not there in webpack 1 which gatsby currently uses

@jarodtaylor
Copy link

Thanks, @pieh. Yeah, I keep getting caught up in the Webpack 1/2/3 incompatibilities.

For anyone that stumbles across this and wants to find the solution. I was able to get it to work using config.merge instead:

exports.modifyWebpackConfig = ({ config, stage }) => {
  if (stage === 'develop') {
    config.preLoader('eslint-loader', {
      test: /\.(js|jsx)$/,
      exclude: /node_modules/,
    });
    config.merge({
      eslint: {
        emitWarning: true,
      }
    });
  }
  return config;
};

@kkemple
Copy link
Contributor

kkemple commented Apr 2, 2018

I'll be taking this on and rolling up all eslint work!

@m-allanson
Copy link
Contributor

Done in #4893, thanks @kkemple! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants