@graphql-eslint/eslint-plugin 2.3.2-alpha-53e82da.0 → 2.3.2-alpha-759bc9e.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.
Files changed (3) hide show
  1. package/index.js +23 -28
  2. package/index.mjs +23 -28
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1626,7 +1626,7 @@ const rule$8 = {
1626
1626
  });
1627
1627
  if (result.ok === false) {
1628
1628
  context.report({
1629
- loc: getLocation(node.loc, node.value),
1629
+ node,
1630
1630
  message: result.errorMessage,
1631
1631
  data: {
1632
1632
  prefix,
@@ -1653,16 +1653,10 @@ const rule$8 = {
1653
1653
  return {
1654
1654
  Name: node => {
1655
1655
  if (node.value.startsWith('_') && options.leadingUnderscore === 'forbid') {
1656
- context.report({
1657
- loc: getLocation(node.loc, node.value),
1658
- message: 'Leading underscores are not allowed',
1659
- });
1656
+ context.report({ node, message: 'Leading underscores are not allowed' });
1660
1657
  }
1661
1658
  if (node.value.endsWith('_') && options.trailingUnderscore === 'forbid') {
1662
- context.report({
1663
- loc: getLocation(node.loc, node.value),
1664
- message: 'Trailing underscores are not allowed',
1665
- });
1659
+ context.report({ node, message: 'Trailing underscores are not allowed' });
1666
1660
  }
1667
1661
  },
1668
1662
  ObjectTypeDefinition: node => {
@@ -2522,17 +2516,15 @@ const rule$h = {
2522
2516
  },
2523
2517
  create(context) {
2524
2518
  return {
2525
- Directive(node) {
2526
- if (node && node.name && node.name.value === 'deprecated') {
2527
- const args = node.arguments || [];
2528
- const reasonArg = args.find(arg => arg.name && arg.name.value === 'reason');
2529
- const value = reasonArg ? String(valueFromNode(reasonArg.value) || '').trim() : null;
2530
- if (!value) {
2531
- context.report({
2532
- node: node.name,
2533
- message: 'Directive "@deprecated" must have a reason!',
2534
- });
2535
- }
2519
+ 'Directive[name.value=deprecated]'(node) {
2520
+ const args = node.arguments || [];
2521
+ const reasonArg = args.find(arg => arg.name && arg.name.value === 'reason');
2522
+ const value = reasonArg ? String(valueFromNode(reasonArg.value) || '').trim() : null;
2523
+ if (!value) {
2524
+ context.report({
2525
+ loc: getLocation(node.loc, node.name.value, { offsetEnd: 0 }),
2526
+ message: 'Directive "@deprecated" must have a reason!',
2527
+ });
2536
2528
  }
2537
2529
  },
2538
2530
  };
@@ -2689,18 +2681,22 @@ const rule$j = {
2689
2681
  if (!mutationType || !queryType) {
2690
2682
  return {};
2691
2683
  }
2692
- const selector = `:matches(${graphql.Kind.OBJECT_TYPE_DEFINITION}, ${graphql.Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}] > ${graphql.Kind.FIELD_DEFINITION}`;
2684
+ const selector = [
2685
+ `:matches(${graphql.Kind.OBJECT_TYPE_DEFINITION}, ${graphql.Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
2686
+ '>',
2687
+ graphql.Kind.FIELD_DEFINITION,
2688
+ graphql.Kind.NAMED_TYPE,
2689
+ ].join(' ');
2693
2690
  return {
2694
2691
  [selector](node) {
2695
- const rawNode = node.rawNode();
2696
- const typeName = getTypeName(rawNode);
2692
+ const typeName = node.name.value;
2697
2693
  const graphQLType = schema.getType(typeName);
2698
2694
  if (graphql.isObjectType(graphQLType)) {
2699
2695
  const { fields } = graphQLType.astNode;
2700
2696
  const hasQueryType = fields.some(field => getTypeName(field) === queryType.name);
2701
2697
  if (!hasQueryType) {
2702
2698
  context.report({
2703
- node,
2699
+ loc: getLocation(node.loc, typeName),
2704
2700
  message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}".`,
2705
2701
  });
2706
2702
  }
@@ -3195,16 +3191,15 @@ const rule$m = {
3195
3191
  }
3196
3192
  return isValidIdName && isValidIdType;
3197
3193
  });
3198
- const typeName = node.name.value;
3199
3194
  // Usually, there should be only one unique identifier field per type.
3200
3195
  // Some clients allow multiple fields to be used. If more people need this,
3201
3196
  // we can extend this rule later.
3202
3197
  if (validIds.length !== 1) {
3203
3198
  context.report({
3204
- loc: getLocation(node.name.loc, typeName),
3205
- message: `{{ typeName }} must have exactly one non-nullable unique identifier. Accepted name(s): {{ acceptedNamesString }} ; Accepted type(s): {{ acceptedTypesString }}`,
3199
+ node,
3200
+ message: '{{nodeName}} must have exactly one non-nullable unique identifier. Accepted name(s): {{acceptedNamesString}} ; Accepted type(s): {{acceptedTypesString}}',
3206
3201
  data: {
3207
- typeName,
3202
+ nodeName: node.name.value,
3208
3203
  acceptedNamesString: options.acceptedIdNames.join(','),
3209
3204
  acceptedTypesString: options.acceptedIdTypes.join(','),
3210
3205
  },
package/index.mjs CHANGED
@@ -1620,7 +1620,7 @@ const rule$8 = {
1620
1620
  });
1621
1621
  if (result.ok === false) {
1622
1622
  context.report({
1623
- loc: getLocation(node.loc, node.value),
1623
+ node,
1624
1624
  message: result.errorMessage,
1625
1625
  data: {
1626
1626
  prefix,
@@ -1647,16 +1647,10 @@ const rule$8 = {
1647
1647
  return {
1648
1648
  Name: node => {
1649
1649
  if (node.value.startsWith('_') && options.leadingUnderscore === 'forbid') {
1650
- context.report({
1651
- loc: getLocation(node.loc, node.value),
1652
- message: 'Leading underscores are not allowed',
1653
- });
1650
+ context.report({ node, message: 'Leading underscores are not allowed' });
1654
1651
  }
1655
1652
  if (node.value.endsWith('_') && options.trailingUnderscore === 'forbid') {
1656
- context.report({
1657
- loc: getLocation(node.loc, node.value),
1658
- message: 'Trailing underscores are not allowed',
1659
- });
1653
+ context.report({ node, message: 'Trailing underscores are not allowed' });
1660
1654
  }
1661
1655
  },
1662
1656
  ObjectTypeDefinition: node => {
@@ -2516,17 +2510,15 @@ const rule$h = {
2516
2510
  },
2517
2511
  create(context) {
2518
2512
  return {
2519
- Directive(node) {
2520
- if (node && node.name && node.name.value === 'deprecated') {
2521
- const args = node.arguments || [];
2522
- const reasonArg = args.find(arg => arg.name && arg.name.value === 'reason');
2523
- const value = reasonArg ? String(valueFromNode(reasonArg.value) || '').trim() : null;
2524
- if (!value) {
2525
- context.report({
2526
- node: node.name,
2527
- message: 'Directive "@deprecated" must have a reason!',
2528
- });
2529
- }
2513
+ 'Directive[name.value=deprecated]'(node) {
2514
+ const args = node.arguments || [];
2515
+ const reasonArg = args.find(arg => arg.name && arg.name.value === 'reason');
2516
+ const value = reasonArg ? String(valueFromNode(reasonArg.value) || '').trim() : null;
2517
+ if (!value) {
2518
+ context.report({
2519
+ loc: getLocation(node.loc, node.name.value, { offsetEnd: 0 }),
2520
+ message: 'Directive "@deprecated" must have a reason!',
2521
+ });
2530
2522
  }
2531
2523
  },
2532
2524
  };
@@ -2683,18 +2675,22 @@ const rule$j = {
2683
2675
  if (!mutationType || !queryType) {
2684
2676
  return {};
2685
2677
  }
2686
- const selector = `:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}] > ${Kind.FIELD_DEFINITION}`;
2678
+ const selector = [
2679
+ `:matches(${Kind.OBJECT_TYPE_DEFINITION}, ${Kind.OBJECT_TYPE_EXTENSION})[name.value=${mutationType.name}]`,
2680
+ '>',
2681
+ Kind.FIELD_DEFINITION,
2682
+ Kind.NAMED_TYPE,
2683
+ ].join(' ');
2687
2684
  return {
2688
2685
  [selector](node) {
2689
- const rawNode = node.rawNode();
2690
- const typeName = getTypeName(rawNode);
2686
+ const typeName = node.name.value;
2691
2687
  const graphQLType = schema.getType(typeName);
2692
2688
  if (isObjectType$1(graphQLType)) {
2693
2689
  const { fields } = graphQLType.astNode;
2694
2690
  const hasQueryType = fields.some(field => getTypeName(field) === queryType.name);
2695
2691
  if (!hasQueryType) {
2696
2692
  context.report({
2697
- node,
2693
+ loc: getLocation(node.loc, typeName),
2698
2694
  message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}".`,
2699
2695
  });
2700
2696
  }
@@ -3189,16 +3185,15 @@ const rule$m = {
3189
3185
  }
3190
3186
  return isValidIdName && isValidIdType;
3191
3187
  });
3192
- const typeName = node.name.value;
3193
3188
  // Usually, there should be only one unique identifier field per type.
3194
3189
  // Some clients allow multiple fields to be used. If more people need this,
3195
3190
  // we can extend this rule later.
3196
3191
  if (validIds.length !== 1) {
3197
3192
  context.report({
3198
- loc: getLocation(node.name.loc, typeName),
3199
- message: `{{ typeName }} must have exactly one non-nullable unique identifier. Accepted name(s): {{ acceptedNamesString }} ; Accepted type(s): {{ acceptedTypesString }}`,
3193
+ node,
3194
+ message: '{{nodeName}} must have exactly one non-nullable unique identifier. Accepted name(s): {{acceptedNamesString}} ; Accepted type(s): {{acceptedTypesString}}',
3200
3195
  data: {
3201
- typeName,
3196
+ nodeName: node.name.value,
3202
3197
  acceptedNamesString: options.acceptedIdNames.join(','),
3203
3198
  acceptedTypesString: options.acceptedIdTypes.join(','),
3204
3199
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "2.3.2-alpha-53e82da.0",
3
+ "version": "2.3.2-alpha-759bc9e.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"