Skip to content

Commit

Permalink
remove validate-against-schema rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed May 18, 2021
1 parent 6d4a356 commit 61251e7
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 258 deletions.
11 changes: 10 additions & 1 deletion .changeset/chilly-foxes-help.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
---
"@graphql-eslint/eslint-plugin": minor
'@graphql-eslint/eslint-plugin': major
---

feat: remove `prettier` rule, add related docs

### BREAKING CHANGE: Remove `prettier` Rule

Since prettier itself support now linting GraphQL code and syntax, we removed the need for this rule from this package.

For more information, see:

- [Migration guide and example](https://github.com/dotansimha/graphql-eslint#prettier-rule)
- [Related PR](https://github.com/dotansimha/graphql-eslint/issues/395)
5 changes: 5 additions & 0 deletions .changeset/new-seas-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': major
---

Remove deprecated rule `validate-against-schema`
5 changes: 5 additions & 0 deletions .changeset/rude-paws-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': major
---

Bump dependencies and update minimum Node version to `v12`
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- [`no-deprecated`](./rules/no-deprecated.md)
- [`unique-fragment-name`](./rules/unique-fragment-name.md)
- [`unique-operation-name`](./rules/unique-operation-name.md)
- [`validate-against-schema`](./rules/validate-against-schema.md)
- [`no-hashtag-description`](./rules/no-hashtag-description.md)
- [`no-anonymous-operations`](./rules/no-anonymous-operations.md)
- [`no-operation-name-suffix`](./rules/no-operation-name-suffix.md)
Expand Down
32 changes: 0 additions & 32 deletions docs/rules/validate-against-schema.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/basic/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
},
],
'@graphql-eslint/unique-fragment-name': 'warn',
'@graphql-eslint/validate-against-schema': 'error',
'@graphql-eslint/no-anonymous-operations': 'warn',
'@graphql-eslint/no-operation-name-suffix': 'error',
'@graphql-eslint/avoid-operation-name-prefix': [
Expand Down
3 changes: 1 addition & 2 deletions examples/graphql-config-code-file/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"rules": {
"@graphql-eslint/require-id-when-available": "warn",
"@graphql-eslint/no-anonymous-operations": "warn",
"@graphql-eslint/no-operation-name-suffix": "error",
"@graphql-eslint/validate-against-schema": "error"
"@graphql-eslint/no-operation-name-suffix": "error"
}
}
]
Expand Down
47 changes: 44 additions & 3 deletions packages/plugin/src/rules/graphql-js-validation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
import { ValidationRule } from 'graphql';
import { GraphQLESLintRule } from '../types';
import { validateDoc } from './validate-against-schema';
import { GraphQLESLintRule, GraphQLESlintRuleContext } from '../types';
import { requireGraphQLSchemaFromContext } from '../utils';

import { validate, GraphQLSchema, DocumentNode, ASTNode, ValidationRule } from 'graphql';
import { validateSDL } from 'graphql/validation/validate';
import { GraphQLESTreeNode } from '../estree-parser';

function extractRuleName(stack: string | undefined): string | null {
const match = (stack || '').match(/validation[/\\\\]rules[/\\\\](.*?)\.js:/);

if (!match) {
return null;
}

return match[1] || null;
}

export function validateDoc(
sourceNode: GraphQLESTreeNode<ASTNode>,
context: GraphQLESlintRuleContext,
schema: GraphQLSchema | null,
documentNode: DocumentNode,
rules: ReadonlyArray<ValidationRule>,
ruleName: string | null = null
): void {
if (documentNode && documentNode.definitions && documentNode.definitions.length > 0) {
try {
const validationErrors = schema ? validate(schema, documentNode, rules) : validateSDL(documentNode, null, rules);

for (const error of validationErrors) {
const validateRuleName = ruleName || `[${extractRuleName(error.stack)}]`;

context.report({
loc: error.locations[0],
message: ruleName ? error.message : `${validateRuleName} ${error.message}`,
});
}
} catch (e) {
context.report({
node: sourceNode,
message: e.message,
});
}
}
}

const validationToRule = (
name: string,
ruleName: string,
Expand Down
2 changes: 0 additions & 2 deletions packages/plugin/src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import validate from './validate-against-schema';
import noUnreachableTypes from './no-unreachable-types';
import noAnonymousOperations from './no-anonymous-operations';
import noOperationNameSuffix from './no-operation-name-suffix';
Expand All @@ -24,7 +23,6 @@ export const rules = {
'no-deprecated': noDeprecated,
'unique-fragment-name': uniqueFragmentName,
'unique-operation-name': uniqueOperationName,
'validate-against-schema': validate,
'no-hashtag-description': noHashtagDescription,
'no-anonymous-operations': noAnonymousOperations,
'no-operation-name-suffix': noOperationNameSuffix,
Expand Down
137 changes: 0 additions & 137 deletions packages/plugin/src/rules/validate-against-schema.ts

This file was deleted.

79 changes: 0 additions & 79 deletions packages/plugin/tests/validate-against-schema.spec.ts

This file was deleted.

0 comments on commit 61251e7

Please sign in to comment.