@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 +22 -19
- package/index.mjs +22 -19
- package/package.json +1 -1
- package/rules/alphabetize.d.ts +3 -10
- package/rules/index.d.ts +1 -2
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
|
-
|
786
|
-
|
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
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
if (
|
958
|
-
|
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
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
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
|
-
|
780
|
-
|
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
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
if (
|
952
|
-
|
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
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
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
package/rules/alphabetize.d.ts
CHANGED
@@ -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
|
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
|
-
|
10
|
-
ignoreSuffix?: string[];
|
9
|
+
groups?: string[];
|
11
10
|
}[], false>;
|
12
11
|
'description-style': import("..").GraphQLESLintRule<{
|
13
12
|
style?: "block" | "inline";
|