@graphql-eslint/eslint-plugin 3.14.0-alpha-20221220171818-aa4bda7 → 3.14.0-alpha-20221220194633-1c7f157
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 +24 -1
- package/index.mjs +24 -1
- package/package.json +1 -1
- package/rules/alphabetize.d.ts +9 -0
- package/rules/index.d.ts +1 -0
package/index.js
CHANGED
@@ -782,6 +782,11 @@ const schema = {
|
|
782
782
|
description: 'Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.',
|
783
783
|
default: false,
|
784
784
|
},
|
785
|
+
groups: {
|
786
|
+
...ARRAY_DEFAULT_OPTIONS,
|
787
|
+
minItems: 2,
|
788
|
+
description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.",
|
789
|
+
},
|
785
790
|
},
|
786
791
|
},
|
787
792
|
};
|
@@ -877,6 +882,7 @@ const rule = {
|
|
877
882
|
arguments: argumentsEnum,
|
878
883
|
// TODO: add in graphql-eslint v4
|
879
884
|
// definitions: true,
|
885
|
+
// groups: ['id', '*', 'createdAt', 'updatedAt']
|
880
886
|
},
|
881
887
|
],
|
882
888
|
operations: [
|
@@ -949,8 +955,25 @@ const rule = {
|
|
949
955
|
if (prevName) {
|
950
956
|
// Compare with lexicographic order
|
951
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.');
|
963
|
+
}
|
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) {
|
972
|
+
continue;
|
973
|
+
}
|
974
|
+
}
|
952
975
|
const shouldSort = compareResult === 1;
|
953
|
-
if (!shouldSort) {
|
976
|
+
if (!shouldSortByGroup && !shouldSort) {
|
954
977
|
const isSameName = compareResult === 0;
|
955
978
|
if (!isSameName ||
|
956
979
|
!prevNode.kind.endsWith('Extension') ||
|
package/index.mjs
CHANGED
@@ -776,6 +776,11 @@ const schema = {
|
|
776
776
|
description: 'Definitions – `type`, `interface`, `enum`, `scalar`, `input`, `union` and `directive`.',
|
777
777
|
default: false,
|
778
778
|
},
|
779
|
+
groups: {
|
780
|
+
...ARRAY_DEFAULT_OPTIONS,
|
781
|
+
minItems: 2,
|
782
|
+
description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.",
|
783
|
+
},
|
779
784
|
},
|
780
785
|
},
|
781
786
|
};
|
@@ -871,6 +876,7 @@ const rule = {
|
|
871
876
|
arguments: argumentsEnum,
|
872
877
|
// TODO: add in graphql-eslint v4
|
873
878
|
// definitions: true,
|
879
|
+
// groups: ['id', '*', 'createdAt', 'updatedAt']
|
874
880
|
},
|
875
881
|
],
|
876
882
|
operations: [
|
@@ -943,8 +949,25 @@ const rule = {
|
|
943
949
|
if (prevName) {
|
944
950
|
// Compare with lexicographic order
|
945
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.');
|
957
|
+
}
|
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) {
|
966
|
+
continue;
|
967
|
+
}
|
968
|
+
}
|
946
969
|
const shouldSort = compareResult === 1;
|
947
|
-
if (!shouldSort) {
|
970
|
+
if (!shouldSortByGroup && !shouldSort) {
|
948
971
|
const isSameName = compareResult === 0;
|
949
972
|
if (!isSameName ||
|
950
973
|
!prevNode.kind.endsWith('Extension') ||
|
package/package.json
CHANGED
package/rules/alphabetize.d.ts
CHANGED
@@ -59,6 +59,15 @@ 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 groups: {
|
63
|
+
readonly minItems: 2;
|
64
|
+
readonly description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.";
|
65
|
+
readonly type: "array";
|
66
|
+
readonly uniqueItems: true;
|
67
|
+
readonly items: {
|
68
|
+
readonly type: "string";
|
69
|
+
};
|
70
|
+
};
|
62
71
|
};
|
63
72
|
};
|
64
73
|
};
|
package/rules/index.d.ts
CHANGED
@@ -6,6 +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
|
+
groups?: string[];
|
9
10
|
}[], false>;
|
10
11
|
'description-style': import("..").GraphQLESLintRule<{
|
11
12
|
style?: "block" | "inline";
|