@graphql-eslint/eslint-plugin 2.3.2-alpha-13a11c2.0 → 2.3.2-alpha-6c4312e.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
@@ -612,7 +612,7 @@ const rule = {
612
612
  ],
613
613
  },
614
614
  messages: {
615
- [ALPHABETIZE]: '"{{ currName }}" should be before "{{ prevName }}".',
615
+ [ALPHABETIZE]: '"{{ currName }}" should be before "{{ prevName }}"',
616
616
  },
617
617
  schema: {
618
618
  type: 'array',
@@ -669,16 +669,9 @@ const rule = {
669
669
  for (const node of nodes) {
670
670
  const currName = node.name.value;
671
671
  if (prevName && prevName > currName) {
672
- const { start, end } = node.name.loc;
673
672
  const isVariableNode = node.kind === graphql.Kind.VARIABLE;
674
673
  context.report({
675
- loc: {
676
- start: {
677
- line: start.line,
678
- column: start.column - (isVariableNode ? 2 : 1),
679
- },
680
- end,
681
- },
674
+ loc: getLocation(node.loc, node.name.value, { offsetEnd: isVariableNode ? 0 : 1 }),
682
675
  messageId: ALPHABETIZE,
683
676
  data: isVariableNode
684
677
  ? {
@@ -1213,11 +1206,10 @@ const rule$6 = {
1213
1206
  const shouldCheckType = node => (options.checkMutations && isMutationType(node)) || (options.checkQueries && isQueryType(node));
1214
1207
  const listeners = {
1215
1208
  'FieldDefinition > InputValueDefinition': node => {
1216
- const name = node.name.value;
1217
- if (name !== 'input' && shouldCheckType(node.parent.parent)) {
1209
+ if (node.name.value !== 'input' && shouldCheckType(node.parent.parent)) {
1218
1210
  context.report({
1219
- loc: getLocation(node.loc, name),
1220
- message: `Input "${name}" should be called "input"`,
1211
+ node: node.name,
1212
+ message: `Input "${node.name.value}" should be called "input"`,
1221
1213
  });
1222
1214
  }
1223
1215
  },
@@ -1234,12 +1226,11 @@ const rule$6 = {
1234
1226
  const inputValueNode = findInputType(node);
1235
1227
  if (shouldCheckType(inputValueNode.parent.parent)) {
1236
1228
  const mutationName = `${inputValueNode.parent.name.value}Input`;
1237
- const name = node.name.value;
1238
1229
  if ((options.caseSensitiveInputType && node.name.value !== mutationName) ||
1239
- name.toLowerCase() !== mutationName.toLowerCase()) {
1230
+ node.name.value.toLowerCase() !== mutationName.toLowerCase()) {
1240
1231
  context.report({
1241
- loc: getLocation(node.loc, name),
1242
- message: `InputType "${name}" name should be "${mutationName}"`,
1232
+ node,
1233
+ message: `InputType "${node.name.value}" name should be "${mutationName}"`,
1243
1234
  });
1244
1235
  }
1245
1236
  }
@@ -3795,7 +3786,25 @@ class GraphQLRuleTester extends eslint.RuleTester {
3795
3786
  return fs.readFileSync(path.resolve(__dirname, `../tests/mocks/${path$1}`), 'utf-8');
3796
3787
  }
3797
3788
  runGraphQLTests(name, rule, tests) {
3798
- super.run(name, rule, tests);
3789
+ const ruleTests = eslint.Linter.version.startsWith('8')
3790
+ ? tests
3791
+ : {
3792
+ valid: tests.valid.map(test => {
3793
+ if (typeof test === 'string') {
3794
+ return test;
3795
+ }
3796
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3797
+ const { name, ...testCaseOptions } = test;
3798
+ return testCaseOptions;
3799
+ }),
3800
+ invalid: tests.invalid.map(test => {
3801
+ // ESLint 7 throws an error on CI - Unexpected top-level property "name"
3802
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3803
+ const { name, ...testCaseOptions } = test;
3804
+ return testCaseOptions;
3805
+ }),
3806
+ };
3807
+ super.run(name, rule, ruleTests);
3799
3808
  // Skip snapshot testing if `expect` variable is not defined
3800
3809
  if (typeof expect === 'undefined') {
3801
3810
  return;
package/index.mjs CHANGED
@@ -606,7 +606,7 @@ const rule = {
606
606
  ],
607
607
  },
608
608
  messages: {
609
- [ALPHABETIZE]: '"{{ currName }}" should be before "{{ prevName }}".',
609
+ [ALPHABETIZE]: '"{{ currName }}" should be before "{{ prevName }}"',
610
610
  },
611
611
  schema: {
612
612
  type: 'array',
@@ -663,16 +663,9 @@ const rule = {
663
663
  for (const node of nodes) {
664
664
  const currName = node.name.value;
665
665
  if (prevName && prevName > currName) {
666
- const { start, end } = node.name.loc;
667
666
  const isVariableNode = node.kind === Kind.VARIABLE;
668
667
  context.report({
669
- loc: {
670
- start: {
671
- line: start.line,
672
- column: start.column - (isVariableNode ? 2 : 1),
673
- },
674
- end,
675
- },
668
+ loc: getLocation(node.loc, node.name.value, { offsetEnd: isVariableNode ? 0 : 1 }),
676
669
  messageId: ALPHABETIZE,
677
670
  data: isVariableNode
678
671
  ? {
@@ -1207,11 +1200,10 @@ const rule$6 = {
1207
1200
  const shouldCheckType = node => (options.checkMutations && isMutationType(node)) || (options.checkQueries && isQueryType(node));
1208
1201
  const listeners = {
1209
1202
  'FieldDefinition > InputValueDefinition': node => {
1210
- const name = node.name.value;
1211
- if (name !== 'input' && shouldCheckType(node.parent.parent)) {
1203
+ if (node.name.value !== 'input' && shouldCheckType(node.parent.parent)) {
1212
1204
  context.report({
1213
- loc: getLocation(node.loc, name),
1214
- message: `Input "${name}" should be called "input"`,
1205
+ node: node.name,
1206
+ message: `Input "${node.name.value}" should be called "input"`,
1215
1207
  });
1216
1208
  }
1217
1209
  },
@@ -1228,12 +1220,11 @@ const rule$6 = {
1228
1220
  const inputValueNode = findInputType(node);
1229
1221
  if (shouldCheckType(inputValueNode.parent.parent)) {
1230
1222
  const mutationName = `${inputValueNode.parent.name.value}Input`;
1231
- const name = node.name.value;
1232
1223
  if ((options.caseSensitiveInputType && node.name.value !== mutationName) ||
1233
- name.toLowerCase() !== mutationName.toLowerCase()) {
1224
+ node.name.value.toLowerCase() !== mutationName.toLowerCase()) {
1234
1225
  context.report({
1235
- loc: getLocation(node.loc, name),
1236
- message: `InputType "${name}" name should be "${mutationName}"`,
1226
+ node,
1227
+ message: `InputType "${node.name.value}" name should be "${mutationName}"`,
1237
1228
  });
1238
1229
  }
1239
1230
  }
@@ -3789,7 +3780,25 @@ class GraphQLRuleTester extends RuleTester {
3789
3780
  return readFileSync(resolve(__dirname, `../tests/mocks/${path}`), 'utf-8');
3790
3781
  }
3791
3782
  runGraphQLTests(name, rule, tests) {
3792
- super.run(name, rule, tests);
3783
+ const ruleTests = Linter.version.startsWith('8')
3784
+ ? tests
3785
+ : {
3786
+ valid: tests.valid.map(test => {
3787
+ if (typeof test === 'string') {
3788
+ return test;
3789
+ }
3790
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3791
+ const { name, ...testCaseOptions } = test;
3792
+ return testCaseOptions;
3793
+ }),
3794
+ invalid: tests.invalid.map(test => {
3795
+ // ESLint 7 throws an error on CI - Unexpected top-level property "name"
3796
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3797
+ const { name, ...testCaseOptions } = test;
3798
+ return testCaseOptions;
3799
+ }),
3800
+ };
3801
+ super.run(name, rule, ruleTests);
3793
3802
  // Skip snapshot testing if `expect` variable is not defined
3794
3803
  if (typeof expect === 'undefined') {
3795
3804
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "2.3.2-alpha-13a11c2.0",
3
+ "version": "2.3.2-alpha-6c4312e.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"
package/testkit.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare type GraphQLESLintRuleListener<WithTypeInfo extends boolean = fal
6
6
  [K in keyof ASTKindToNode]?: (node: GraphQLESTreeNode<ASTKindToNode[K], WithTypeInfo>) => void;
7
7
  } & Record<string, any>;
8
8
  export declare type GraphQLValidTestCase<Options> = Omit<RuleTester.ValidTestCase, 'options' | 'parserOptions'> & {
9
+ name: string;
9
10
  options?: Options;
10
11
  parserOptions?: ParserOptions;
11
12
  };