Skip to content

Commit 4e14baa

Browse files
author
Dimitri POSTOLOV
authored
add unicorn/prefer-array-some rule (#585)
1 parent 3efda63 commit 4e14baa

File tree

6 files changed

+89
-12
lines changed

6 files changed

+89
-12
lines changed

.eslintrc.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"prettier",
77
"plugin:@typescript-eslint/recommended"
88
],
9-
"plugins": ["@typescript-eslint"],
9+
"plugins": ["@typescript-eslint", "unicorn"],
1010
"rules": {
1111
"no-empty": "off",
1212
"no-console": "error",
@@ -22,7 +22,9 @@
2222
"@typescript-eslint/no-non-null-assertion": "off",
2323
"@typescript-eslint/explicit-function-return-type": "off",
2424
"@typescript-eslint/ban-ts-ignore": "off",
25-
"@typescript-eslint/ban-types": "off"
25+
"@typescript-eslint/ban-types": "off",
26+
"unicorn/prefer-array-some": "error",
27+
"unicorn/prefer-includes": "error"
2628
},
2729
"env": {
2830
"es6": true,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"eslint-plugin-standard": "5.0.0",
4646
"husky": "7.0.2",
4747
"jest": "27.1.0",
48+
"eslint-plugin-unicorn": "35.0.0",
4849
"json-schema-to-markdown": "1.1.1",
4950
"lint-staged": "11.1.2",
5051
"patch-package": "6.4.7",

packages/plugin/src/rules/naming-convention.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function checkNameFormat(params: CheckNameFormatParams): { ok: false; errorMessa
5858
errorMessage: '{{nodeType}} name "{{nodeName}}" should have "{{suffix}}" suffix',
5959
};
6060
}
61-
if (style && !acceptedStyles.some(acceptedStyle => acceptedStyle === style)) {
61+
if (style && !acceptedStyles.includes(style)) {
6262
return {
6363
ok: false,
6464
errorMessage: `{{nodeType}} name "{{nodeName}}" should be in one of the following options: ${acceptedStyles.join(

packages/plugin/src/rules/require-id-when-available.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const rule: GraphQLESLintRule<RequireIdWhenAvailableRuleConfig, true> = {
101101
if (selection.kind === 'Field' && selection.name.value === fieldName) {
102102
found = true;
103103
} else if (selection.kind === 'InlineFragment') {
104-
found = !!(selection.selectionSet?.selections || []).find(
104+
found = (selection.selectionSet?.selections || []).some(
105105
s => s.kind === 'Field' && s.name.value === fieldName
106106
);
107107
} else if (selection.kind === 'FragmentSpread') {
@@ -110,7 +110,7 @@ const rule: GraphQLESLintRule<RequireIdWhenAvailableRuleConfig, true> = {
110110
if (foundSpread[0]) {
111111
checkedFragmentSpreads.add(foundSpread[0].document.name.value);
112112

113-
found = !!(foundSpread[0].document.selectionSet?.selections || []).find(
113+
found = (foundSpread[0].document.selectionSet?.selections || []).some(
114114
s => s.kind === 'Field' && s.name.value === fieldName
115115
);
116116
}
@@ -127,7 +127,7 @@ const rule: GraphQLESLintRule<RequireIdWhenAvailableRuleConfig, true> = {
127127
parent.kind === 'InlineFragment' &&
128128
parent.parent &&
129129
parent.parent.kind === 'SelectionSet' &&
130-
!!parent.parent.selections.find(s => s.kind === 'Field' && s.name.value === fieldName);
130+
parent.parent.selections.some(s => s.kind === 'Field' && s.name.value === fieldName);
131131

132132
if (!found && !hasIdFieldInInterfaceSelectionSet) {
133133
context.report({

packages/plugin/src/rules/strict-id-in-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface ShouldIgnoreNodeParams {
2222
const shouldIgnoreNode = ({ node, exceptions }: ShouldIgnoreNodeParams): boolean => {
2323
const rawNode = node.rawNode();
2424

25-
if (exceptions.types && exceptions.types.some(type => rawNode.name.value === type)) {
25+
if (exceptions.types && exceptions.types.includes(rawNode.name.value)) {
2626
return true;
2727
}
2828

yarn.lock

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
semver "^6.3.0"
4848
source-map "^0.5.0"
4949

50-
"@babel/core@^7.1.0", "@babel/core@^7.7.2", "@babel/core@^7.7.5":
50+
"@babel/core@^7.1.0", "@babel/core@^7.12.16", "@babel/core@^7.7.2", "@babel/core@^7.7.5":
5151
version "7.15.0"
5252
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.15.0.tgz#749e57c68778b73ad8082775561f67f5196aafa8"
5353
integrity sha512-tXtmTminrze5HEUPn/a0JtOzzfp0nk+UEXQ/tqIJo3WDGypl/2OFQEMll/zSFU8f/lfmfLXvTaORHF3cfXIQMw==
@@ -68,6 +68,15 @@
6868
semver "^6.3.0"
6969
source-map "^0.5.0"
7070

71+
"@babel/eslint-parser@^7.12.16":
72+
version "7.15.0"
73+
resolved "https://registry.yarnpkg.com/@babel/eslint-parser/-/eslint-parser-7.15.0.tgz#b54f06e04d0e93aebcba99f89251e3bf0ee39f21"
74+
integrity sha512-+gSPtjSBxOZz4Uh8Ggqu7HbfpB8cT1LwW0DnVVLZEJvzXauiD0Di3zszcBkRmfGGrLdYeHUwcflG7i3tr9kQlw==
75+
dependencies:
76+
eslint-scope "^5.1.1"
77+
eslint-visitor-keys "^2.1.0"
78+
semver "^6.3.0"
79+
7180
"@babel/generator@^7.14.9", "@babel/generator@^7.15.0", "@babel/generator@^7.7.2":
7281
version "7.15.0"
7382
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.15.0.tgz#a7d0c172e0d814974bad5aa77ace543b97917f15"
@@ -2562,7 +2571,7 @@ buffer@^5.7.0:
25622571
base64-js "^1.3.1"
25632572
ieee754 "^1.1.13"
25642573

2565-
builtin-modules@^3.1.0:
2574+
builtin-modules@^3.0.0, builtin-modules@^3.1.0:
25662575
version "3.2.0"
25672576
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.2.0.tgz#45d5db99e7ee5e6bc4f362e008bf917ab5049887"
25682577
integrity sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==
@@ -2656,7 +2665,7 @@ ci-info@^2.0.0:
26562665
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-2.0.0.tgz#67a9e964be31a51e15e5010d58e6f12834002f46"
26572666
integrity sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
26582667

2659-
ci-info@^3.1.1:
2668+
ci-info@^3.1.1, ci-info@^3.2.0:
26602669
version "3.2.0"
26612670
resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-3.2.0.tgz#2876cb948a498797b5236f0095bc057d0dca38b6"
26622671
integrity sha512-dVqRX7fLUm8J6FgHJ418XuIgDLZDkYcDFTeL6TA2gt5WlIZUQrrH6EZrNClwT/H0FateUsZkGIOPRrLbP+PR9A==
@@ -2666,6 +2675,13 @@ cjs-module-lexer@^1.0.0:
26662675
resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz#9f84ba3244a512f3a54e5277e8eef4c489864e40"
26672676
integrity sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==
26682677

2678+
clean-regexp@^1.0.0:
2679+
version "1.0.0"
2680+
resolved "https://registry.yarnpkg.com/clean-regexp/-/clean-regexp-1.0.0.tgz#8df7c7aae51fd36874e8f8d05b9180bc11a3fed7"
2681+
integrity sha1-jffHquUf02h06PjQW5GAvBGj/tc=
2682+
dependencies:
2683+
escape-string-regexp "^1.0.5"
2684+
26692685
clean-stack@^2.0.0:
26702686
version "2.2.0"
26712687
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
@@ -3246,6 +3262,24 @@ [email protected]:
32463262
resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-5.0.0.tgz#c43f6925d669f177db46f095ea30be95476b1ee4"
32473263
integrity sha512-eSIXPc9wBM4BrniMzJRBm2uoVuXz2EPa+NXPk2+itrVt+r5SbKFERx/IgrK/HmfjddyKVz2f+j+7gBRvu19xLg==
32483264

3265+
3266+
version "35.0.0"
3267+
resolved "https://registry.yarnpkg.com/eslint-plugin-unicorn/-/eslint-plugin-unicorn-35.0.0.tgz#40797793d4f645bafaaa7a1396b8f4ca7b2a7dbd"
3268+
integrity sha512-FHsaO68tDPQILfs/mGF8eSISJp8RswR4FpUuBDnueK2wyEHC6zmsc9WxjYyldXoIsBuVmru6jQyFCbCWPoW/KQ==
3269+
dependencies:
3270+
"@babel/helper-validator-identifier" "^7.14.9"
3271+
ci-info "^3.2.0"
3272+
clean-regexp "^1.0.0"
3273+
eslint-template-visitor "^2.3.2"
3274+
eslint-utils "^3.0.0"
3275+
is-builtin-module "^3.1.0"
3276+
lodash "^4.17.21"
3277+
pluralize "^8.0.0"
3278+
read-pkg-up "^7.0.1"
3279+
regexp-tree "^0.1.23"
3280+
safe-regex "^2.1.1"
3281+
semver "^7.3.5"
3282+
32493283
eslint-scope@^5.1.1:
32503284
version "5.1.1"
32513285
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
@@ -3254,6 +3288,17 @@ eslint-scope@^5.1.1:
32543288
esrecurse "^4.3.0"
32553289
estraverse "^4.1.1"
32563290

3291+
eslint-template-visitor@^2.3.2:
3292+
version "2.3.2"
3293+
resolved "https://registry.yarnpkg.com/eslint-template-visitor/-/eslint-template-visitor-2.3.2.tgz#b52f96ff311e773a345d79053ccc78275bbc463d"
3294+
integrity sha512-3ydhqFpuV7x1M9EK52BPNj6V0Kwu0KKkcIAfpUhwHbR8ocRln/oUHgfxQupY8O1h4Qv/POHDumb/BwwNfxbtnA==
3295+
dependencies:
3296+
"@babel/core" "^7.12.16"
3297+
"@babel/eslint-parser" "^7.12.16"
3298+
eslint-visitor-keys "^2.0.0"
3299+
esquery "^1.3.1"
3300+
multimap "^1.1.0"
3301+
32573302
eslint-utils@^2.0.0, eslint-utils@^2.1.0:
32583303
version "2.1.0"
32593304
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27"
@@ -3273,7 +3318,7 @@ eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.3.0:
32733318
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
32743319
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==
32753320

3276-
eslint-visitor-keys@^2.0.0:
3321+
eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
32773322
version "2.1.0"
32783323
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
32793324
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
@@ -3381,7 +3426,7 @@ esprima@^4.0.0, esprima@^4.0.1:
33813426
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
33823427
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
33833428

3384-
esquery@^1.4.0:
3429+
esquery@^1.3.1, esquery@^1.4.0:
33853430
version "1.4.0"
33863431
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.4.0.tgz#2148ffc38b82e8c7057dfed48425b3e61f0f24a5"
33873432
integrity sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==
@@ -4034,6 +4079,13 @@ is-boolean-object@^1.1.0:
40344079
call-bind "^1.0.2"
40354080
has-tostringtag "^1.0.0"
40364081

4082+
is-builtin-module@^3.1.0:
4083+
version "3.1.0"
4084+
resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-3.1.0.tgz#6fdb24313b1c03b75f8b9711c0feb8c30b903b00"
4085+
integrity sha512-OV7JjAgOTfAFJmHZLvpSTb4qi0nIILDV1gWPYDnDJUTNFM5aGlRAhk4QcT8i7TuAleeEV5Fdkqn3t4mS+Q11fg==
4086+
dependencies:
4087+
builtin-modules "^3.0.0"
4088+
40374089
is-callable@^1.1.4, is-callable@^1.2.3:
40384090
version "1.2.4"
40394091
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.4.tgz#47301d58dd0259407865547853df6d61fe471945"
@@ -5162,6 +5214,11 @@ ms@^2.1.1:
51625214
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
51635215
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
51645216

5217+
multimap@^1.1.0:
5218+
version "1.1.0"
5219+
resolved "https://registry.yarnpkg.com/multimap/-/multimap-1.1.0.tgz#5263febc085a1791c33b59bb3afc6a76a2a10ca8"
5220+
integrity sha512-0ZIR9PasPxGXmRsEF8jsDzndzHDj7tIav+JUmvIFB/WHswliFnquxECT/De7GR4yg99ky/NlRKJT82G1y271bw==
5221+
51655222
natural-compare@^1.4.0:
51665223
version "1.4.0"
51675224
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
@@ -5563,6 +5620,11 @@ please-upgrade-node@^3.2.0:
55635620
dependencies:
55645621
semver-compare "^1.0.0"
55655622

5623+
pluralize@^8.0.0:
5624+
version "8.0.0"
5625+
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1"
5626+
integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==
5627+
55665628
preferred-pm@^3.0.0:
55675629
version "3.0.3"
55685630
resolved "https://registry.yarnpkg.com/preferred-pm/-/preferred-pm-3.0.3.tgz#1b6338000371e3edbce52ef2e4f65eb2e73586d6"
@@ -5741,6 +5803,11 @@ regenerator-transform@^0.14.2:
57415803
dependencies:
57425804
"@babel/runtime" "^7.8.4"
57435805

5806+
regexp-tree@^0.1.23, regexp-tree@~0.1.1:
5807+
version "0.1.23"
5808+
resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.23.tgz#8a8ce1cc5e971acef62213a7ecdb1f6e18a1f1b2"
5809+
integrity sha512-+7HWfb4Bvu8Rs2eQTUIpX9I/PlQkYOuTNbRpKLJlQpSgwSkzFYh+pUj0gtvglnOZLKB6YgnIgRuJ2/IlpL48qw==
5810+
57445811
regexpp@^3.0.0, regexpp@^3.1.0:
57455812
version "3.2.0"
57465813
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
@@ -5894,6 +5961,13 @@ safe-buffer@~5.1.1:
58945961
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
58955962
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==
58965963

5964+
safe-regex@^2.1.1:
5965+
version "2.1.1"
5966+
resolved "https://registry.yarnpkg.com/safe-regex/-/safe-regex-2.1.1.tgz#f7128f00d056e2fe5c11e81a1324dd974aadced2"
5967+
integrity sha512-rx+x8AMzKb5Q5lQ95Zoi6ZbJqwCLkqi3XuJXp5P3rT8OEc6sZCJG5AE5dU3lsgRr/F4Bs31jSlVN+j5KrsGu9A==
5968+
dependencies:
5969+
regexp-tree "~0.1.1"
5970+
58975971
"safer-buffer@>= 2.1.2 < 3":
58985972
version "2.1.2"
58995973
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"

0 commit comments

Comments
 (0)