@graphql-eslint/eslint-plugin 3.14.0-alpha-20221220173226-ecd822d → 3.14.0-alpha-20221220195106-78926c0

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -782,8 +782,11 @@ const schema = {
782
782
  description: 'Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.',
783
783
  default: false,
784
784
  },
785
- ignorePrefix: ARRAY_DEFAULT_OPTIONS,
786
- ignoreSuffix: ARRAY_DEFAULT_OPTIONS,
785
+ groups: {
786
+ ...ARRAY_DEFAULT_OPTIONS,
787
+ minItems: 2,
788
+ description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.",
789
+ },
787
790
  },
788
791
  },
789
792
  };
@@ -879,6 +882,7 @@ const rule = {
879
882
  arguments: argumentsEnum,
880
883
  // TODO: add in graphql-eslint v4
881
884
  // definitions: true,
885
+ // groups: ['id', '*', 'createdAt', 'updatedAt']
882
886
  },
883
887
  ],
884
888
  operations: [
@@ -949,28 +953,27 @@ const rule = {
949
953
  const prevName = ('alias' in prevNode && ((_c = prevNode.alias) === null || _c === void 0 ? void 0 : _c.value)) ||
950
954
  ('name' in prevNode && ((_d = prevNode.name) === null || _d === void 0 ? void 0 : _d.value));
951
955
  if (prevName) {
952
- if ((opts.ignorePrefix || []).length > 0) {
953
- const shouldSkipIgnorePrefix = opts.ignorePrefix.some(prefix => prefix === prevName ||
954
- prefix === currName ||
955
- prevName.startsWith(prefix) ||
956
- currName.startsWith(prefix));
957
- if (shouldSkipIgnorePrefix) {
958
- continue;
956
+ // Compare with lexicographic order
957
+ const compareResult = prevName.localeCompare(currName);
958
+ const { groups } = opts;
959
+ let shouldSortByGroup = false;
960
+ if (groups === null || groups === void 0 ? void 0 : groups.length) {
961
+ if (!groups.includes('*')) {
962
+ throw new Error('`groups` option should contain `*` string.');
959
963
  }
960
- }
961
- if ((opts.ignoreSuffix || []).length > 0) {
962
- const shouldSkipIgnoreSuffix = opts.ignoreSuffix.some(suffix => suffix === prevName ||
963
- suffix === currName ||
964
- prevName.endsWith(suffix) ||
965
- currName.endsWith(suffix));
966
- if (shouldSkipIgnoreSuffix) {
964
+ let indexForPrev = groups.indexOf(prevName);
965
+ if (indexForPrev === -1)
966
+ indexForPrev = groups.indexOf('*');
967
+ let indexForCurr = groups.indexOf(currName);
968
+ if (indexForCurr === -1)
969
+ indexForCurr = groups.indexOf('*');
970
+ shouldSortByGroup = indexForPrev - indexForCurr > 0;
971
+ if (indexForPrev < indexForCurr) {
967
972
  continue;
968
973
  }
969
974
  }
970
- // Compare with lexicographic order
971
- const compareResult = prevName.localeCompare(currName);
972
975
  const shouldSort = compareResult === 1;
973
- if (!shouldSort) {
976
+ if (!shouldSortByGroup && !shouldSort) {
974
977
  const isSameName = compareResult === 0;
975
978
  if (!isSameName ||
976
979
  !prevNode.kind.endsWith('Extension') ||
package/index.mjs CHANGED
@@ -776,8 +776,11 @@ const schema = {
776
776
  description: 'Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.',
777
777
  default: false,
778
778
  },
779
- ignorePrefix: ARRAY_DEFAULT_OPTIONS,
780
- ignoreSuffix: ARRAY_DEFAULT_OPTIONS,
779
+ groups: {
780
+ ...ARRAY_DEFAULT_OPTIONS,
781
+ minItems: 2,
782
+ description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.",
783
+ },
781
784
  },
782
785
  },
783
786
  };
@@ -873,6 +876,7 @@ const rule = {
873
876
  arguments: argumentsEnum,
874
877
  // TODO: add in graphql-eslint v4
875
878
  // definitions: true,
879
+ // groups: ['id', '*', 'createdAt', 'updatedAt']
876
880
  },
877
881
  ],
878
882
  operations: [
@@ -943,28 +947,27 @@ const rule = {
943
947
  const prevName = ('alias' in prevNode && ((_c = prevNode.alias) === null || _c === void 0 ? void 0 : _c.value)) ||
944
948
  ('name' in prevNode && ((_d = prevNode.name) === null || _d === void 0 ? void 0 : _d.value));
945
949
  if (prevName) {
946
- if ((opts.ignorePrefix || []).length > 0) {
947
- const shouldSkipIgnorePrefix = opts.ignorePrefix.some(prefix => prefix === prevName ||
948
- prefix === currName ||
949
- prevName.startsWith(prefix) ||
950
- currName.startsWith(prefix));
951
- if (shouldSkipIgnorePrefix) {
952
- continue;
950
+ // Compare with lexicographic order
951
+ const compareResult = prevName.localeCompare(currName);
952
+ const { groups } = opts;
953
+ let shouldSortByGroup = false;
954
+ if (groups === null || groups === void 0 ? void 0 : groups.length) {
955
+ if (!groups.includes('*')) {
956
+ throw new Error('`groups` option should contain `*` string.');
953
957
  }
954
- }
955
- if ((opts.ignoreSuffix || []).length > 0) {
956
- const shouldSkipIgnoreSuffix = opts.ignoreSuffix.some(suffix => suffix === prevName ||
957
- suffix === currName ||
958
- prevName.endsWith(suffix) ||
959
- currName.endsWith(suffix));
960
- if (shouldSkipIgnoreSuffix) {
958
+ let indexForPrev = groups.indexOf(prevName);
959
+ if (indexForPrev === -1)
960
+ indexForPrev = groups.indexOf('*');
961
+ let indexForCurr = groups.indexOf(currName);
962
+ if (indexForCurr === -1)
963
+ indexForCurr = groups.indexOf('*');
964
+ shouldSortByGroup = indexForPrev - indexForCurr > 0;
965
+ if (indexForPrev < indexForCurr) {
961
966
  continue;
962
967
  }
963
968
  }
964
- // Compare with lexicographic order
965
- const compareResult = prevName.localeCompare(currName);
966
969
  const shouldSort = compareResult === 1;
967
- if (!shouldSort) {
970
+ if (!shouldSortByGroup && !shouldSort) {
968
971
  const isSameName = compareResult === 0;
969
972
  if (!isSameName ||
970
973
  !prevNode.kind.endsWith('Extension') ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.14.0-alpha-20221220173226-ecd822d",
3
+ "version": "3.14.0-alpha-20221220195106-78926c0",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -59,18 +59,11 @@ declare const schema: {
59
59
  readonly description: "Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.";
60
60
  readonly default: false;
61
61
  };
62
- readonly ignorePrefix: {
62
+ readonly groups: {
63
+ readonly minItems: 2;
64
+ readonly description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.";
63
65
  readonly type: "array";
64
66
  readonly uniqueItems: true;
65
- readonly minItems: 1;
66
- readonly items: {
67
- readonly type: "string";
68
- };
69
- };
70
- readonly ignoreSuffix: {
71
- readonly type: "array";
72
- readonly uniqueItems: true;
73
- readonly minItems: 1;
74
67
  readonly items: {
75
68
  readonly type: "string";
76
69
  };
package/rules/index.d.ts CHANGED
@@ -6,8 +6,7 @@ export declare const rules: {
6
6
  values?: "EnumTypeDefinition"[];
7
7
  fields?: import("json-schema-to-ts/lib/types/type-utils").Writable<"ObjectTypeDefinition" | "InterfaceTypeDefinition" | "InputObjectTypeDefinition">[];
8
8
  variables?: "OperationDefinition"[];
9
- ignorePrefix?: string[];
10
- ignoreSuffix?: string[];
9
+ groups?: string[];
11
10
  }[], false>;
12
11
  'description-style': import("..").GraphQLESLintRule<{
13
12
  style?: "block" | "inline";