@graphql-eslint/eslint-plugin 3.1.0 → 3.1.1-alpha-f19a99b.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -335,30 +335,42 @@ function getLocation(loc, fieldName = '', offset) {
335
335
  };
336
336
  }
337
337
 
338
- function extractRuleName(stack) {
339
- const match = (stack || '').match(/validation[/\\]rules[/\\](.*?)\.js:/) || [];
340
- return match[1] || null;
341
- }
342
- function validateDoc(sourceNode, context, schema, documentNode, rules, ruleName = null) {
343
- var _a;
344
- if (((_a = documentNode === null || documentNode === void 0 ? void 0 : documentNode.definitions) === null || _a === void 0 ? void 0 : _a.length) > 0) {
345
- try {
346
- const validationErrors = schema ? graphql.validate(schema, documentNode, rules) : validate.validateSDL(documentNode, null, rules);
347
- for (const error of validationErrors) {
348
- const validateRuleName = ruleName || `[${extractRuleName(error.stack)}]`;
349
- context.report({
350
- loc: getLocation({ start: error.locations[0] }),
351
- message: ruleName ? error.message : `${validateRuleName} ${error.message}`,
352
- });
353
- }
354
- }
355
- catch (e) {
338
+ function validateDoc(sourceNode, context, schema, documentNode, rules) {
339
+ if (documentNode.definitions.length === 0) {
340
+ return;
341
+ }
342
+ try {
343
+ const validationErrors = schema
344
+ ? graphql.validate(schema, documentNode, rules)
345
+ : validate.validateSDL(documentNode, null, rules);
346
+ for (const error of validationErrors) {
347
+ /*
348
+ * TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
349
+ * Example: loc.end always equal loc.start
350
+ * {
351
+ * token: {
352
+ * type: 'Name',
353
+ * loc: { start: { line: 4, column: 13 }, end: { line: 4, column: 13 } },
354
+ * value: 'veryBad',
355
+ * range: [ 40, 47 ]
356
+ * }
357
+ * }
358
+ */
359
+ const { line, column } = error.locations[0];
360
+ const ancestors = context.getAncestors();
361
+ const token = ancestors[0].tokens.find(token => token.loc.start.line === line && token.loc.start.column === column);
356
362
  context.report({
357
- node: sourceNode,
358
- message: e.message,
363
+ loc: getLocation({ start: error.locations[0] }, token === null || token === void 0 ? void 0 : token.value),
364
+ message: error.message,
359
365
  });
360
366
  }
361
367
  }
368
+ catch (e) {
369
+ context.report({
370
+ node: sourceNode,
371
+ message: e.message,
372
+ });
373
+ }
362
374
  }
363
375
  const isGraphQLImportFile = rawSDL => {
364
376
  const trimmedRawSDL = rawSDL.trimLeft();
@@ -405,7 +417,7 @@ const validationToRule = (name, ruleName, docs, getDocumentNode) => {
405
417
  if (isRealFile && getDocumentNode) {
406
418
  documentNode = getDocumentNode(context);
407
419
  }
408
- validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn], ruleName);
420
+ validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn]);
409
421
  },
410
422
  };
411
423
  },
package/index.mjs CHANGED
@@ -329,30 +329,42 @@ function getLocation(loc, fieldName = '', offset) {
329
329
  };
330
330
  }
331
331
 
332
- function extractRuleName(stack) {
333
- const match = (stack || '').match(/validation[/\\]rules[/\\](.*?)\.js:/) || [];
334
- return match[1] || null;
335
- }
336
- function validateDoc(sourceNode, context, schema, documentNode, rules, ruleName = null) {
337
- var _a;
338
- if (((_a = documentNode === null || documentNode === void 0 ? void 0 : documentNode.definitions) === null || _a === void 0 ? void 0 : _a.length) > 0) {
339
- try {
340
- const validationErrors = schema ? validate(schema, documentNode, rules) : validateSDL(documentNode, null, rules);
341
- for (const error of validationErrors) {
342
- const validateRuleName = ruleName || `[${extractRuleName(error.stack)}]`;
343
- context.report({
344
- loc: getLocation({ start: error.locations[0] }),
345
- message: ruleName ? error.message : `${validateRuleName} ${error.message}`,
346
- });
347
- }
348
- }
349
- catch (e) {
332
+ function validateDoc(sourceNode, context, schema, documentNode, rules) {
333
+ if (documentNode.definitions.length === 0) {
334
+ return;
335
+ }
336
+ try {
337
+ const validationErrors = schema
338
+ ? validate(schema, documentNode, rules)
339
+ : validateSDL(documentNode, null, rules);
340
+ for (const error of validationErrors) {
341
+ /*
342
+ * TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
343
+ * Example: loc.end always equal loc.start
344
+ * {
345
+ * token: {
346
+ * type: 'Name',
347
+ * loc: { start: { line: 4, column: 13 }, end: { line: 4, column: 13 } },
348
+ * value: 'veryBad',
349
+ * range: [ 40, 47 ]
350
+ * }
351
+ * }
352
+ */
353
+ const { line, column } = error.locations[0];
354
+ const ancestors = context.getAncestors();
355
+ const token = ancestors[0].tokens.find(token => token.loc.start.line === line && token.loc.start.column === column);
350
356
  context.report({
351
- node: sourceNode,
352
- message: e.message,
357
+ loc: getLocation({ start: error.locations[0] }, token === null || token === void 0 ? void 0 : token.value),
358
+ message: error.message,
353
359
  });
354
360
  }
355
361
  }
362
+ catch (e) {
363
+ context.report({
364
+ node: sourceNode,
365
+ message: e.message,
366
+ });
367
+ }
356
368
  }
357
369
  const isGraphQLImportFile = rawSDL => {
358
370
  const trimmedRawSDL = rawSDL.trimLeft();
@@ -399,7 +411,7 @@ const validationToRule = (name, ruleName, docs, getDocumentNode) => {
399
411
  if (isRealFile && getDocumentNode) {
400
412
  documentNode = getDocumentNode(context);
401
413
  }
402
- validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn], ruleName);
414
+ validateDoc(node, context, schema, documentNode || node.rawNode(), [ruleFn]);
403
415
  },
404
416
  };
405
417
  },
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.1.0",
3
+ "version": "3.1.1-alpha-f19a99b.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
9
  "@babel/code-frame": "7.16.0",
10
- "@graphql-tools/code-file-loader": "7.2.2",
10
+ "@graphql-tools/code-file-loader": "7.2.3",
11
11
  "@graphql-tools/graphql-tag-pluck": "7.1.4",
12
- "@graphql-tools/import": "6.6.1",
13
- "@graphql-tools/utils": "8.5.3",
12
+ "@graphql-tools/import": "6.6.2",
13
+ "@graphql-tools/utils": "8.5.4",
14
14
  "graphql-config": "4.1.0",
15
15
  "graphql-depth-limit": "1.1.0",
16
16
  "lodash.lowercase": "4.3.0"
@@ -1,5 +1,5 @@
1
1
  import { GraphQLSchema, DocumentNode, ASTNode, ValidationRule } from 'graphql';
2
2
  import { GraphQLESLintRule, GraphQLESLintRuleContext } from '../types';
3
3
  import { GraphQLESTreeNode } from '../estree-parser';
4
- export declare function validateDoc(sourceNode: GraphQLESTreeNode<ASTNode>, context: GraphQLESLintRuleContext, schema: GraphQLSchema | null, documentNode: DocumentNode, rules: ReadonlyArray<ValidationRule>, ruleName?: string | null): void;
4
+ export declare function validateDoc(sourceNode: GraphQLESTreeNode<ASTNode>, context: GraphQLESLintRuleContext, schema: GraphQLSchema | null, documentNode: DocumentNode, rules: ReadonlyArray<ValidationRule>): void;
5
5
  export declare const GRAPHQL_JS_VALIDATIONS: Record<string, GraphQLESLintRule<any[], false>>;