Gatsby: V1: gatsby-plugin-eslint fails tests

Created on 5 Sep 2018  Â·  2Comments  Â·  Source: gatsbyjs/gatsby

When I add eslint to a project, I am getting eslint errors straight away because eslint thinks 'graphql' is an undefined variable.

......./page.js
33:26  error  'graphql' is not defined  no-undef
✖ 1 problem (1 error, 0 warnings)

Is there anyway around this? I am using GatsbyV1.

Most helpful comment

Hi,

This is because Eslint doesn't know that Gatsby will handle and extract graphql statements during build. To Eslint it simply looks like you forgot the define the variable.

The simplest way around this is to add /* global graphql */ in your file.

But assigning graphql as a global in your .eslintrc is probably preferable.

{
    "globals": {
        "graphql": false
    }
}

You can read more about the no-undef rule here or assigning globals here.

All 2 comments

Hi,

This is because Eslint doesn't know that Gatsby will handle and extract graphql statements during build. To Eslint it simply looks like you forgot the define the variable.

The simplest way around this is to add /* global graphql */ in your file.

But assigning graphql as a global in your .eslintrc is probably preferable.

{
    "globals": {
        "graphql": false
    }
}

You can read more about the no-undef rule here or assigning globals here.

@gabbes Thank you!

Was this page helpful?
0 / 5 - 0 ratings