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

How to lint both template strings in JavaScript files and the content of gql files #299

Open
harm-meijer opened this issue Mar 5, 2021 · 1 comment

Comments

@harm-meijer
Copy link

With version 4.0.0 I try to lint deprecated field in a gql file and a template in a js file.

If I configure .eslintrc.js it with:

    'graphql/template-strings': [
      'error',
      {
        env: 'apollo',
        // validators: 'all',
        // eslint-disable-next-line global-require
        schemaJson: require('./graphql.schema.json'),
        tagName:'gql'
      },
    ],
    'graphql/no-deprecated-fields': [
      'error',
      {
        env: 'literal',
        // eslint-disable-next-line global-require
        schemaJson: require('./graphql.schema.json'),
      },
    ],

Then it will find a problem in gql files

me$ node ./node_modules/eslint/bin/eslint.js ./src/components/Cart.gql

/project/src/components/Cart.gql
  48:7  error  The field ShippingMethod.description is deprecated. Use localizedDescription  graphql/no-deprecated-fields

✖ 1 problem (1 error, 0 warnings)

But it won't detect it in javaScript files

When I configure .eslintrc.js with:

    'graphql/template-strings': [
      'error',
      {
        env: 'apollo',
        // validators: 'all',
        // eslint-disable-next-line global-require
        schemaJson: require('./graphql.schema.json'),
        tagName:'gql'
      },
    ],
    'graphql/no-deprecated-fields': [
      'error',
      {
        env: 'apollo',
        // eslint-disable-next-line global-require
        schemaJson: require('./graphql.schema.json'),
      },
    ],

It will find the error in the javaScript file but not in the gql files.

There may be some sort of combination of settings that I haven't tried yet that will do both but I am unable to find it.

@harm-meijer
Copy link
Author

A work around could be to create multiple lint config files, one that is based on the .eslintrs.js but changes the env for the linter plugin and then run the linter twice

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

1 participant