Skip to content

Commit b904515

Browse files
authored
remove truthy helper function (#2797)
* yoyo * yoyo * yoyo * yoyo * yoyo * yoyo * fix * fix * a * modify test
1 parent a27128f commit b904515

File tree

16 files changed

+122
-131
lines changed

16 files changed

+122
-131
lines changed

.changeset/thick-candles-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
remove `truthy` helper function

.eslintrc.cjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ module.exports = {
4141
},
4242
{
4343
files: ['**/*.{spec,test}.ts'],
44-
env: {
45-
jest: true,
46-
},
4744
extends: ['plugin:eslint-plugin/tests-recommended'],
4845
rules: {
4946
'eslint-plugin/test-case-shorthand-strings': 'error',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"tsup": "^8.3.5",
4848
"tsx": "4.19.2",
4949
"turbo": "2.3.3",
50-
"typescript": "5.6.3",
50+
"typescript": "5.7.2",
5151
"vitest": "2.1.8"
5252
},
5353
"pnpm": {

packages/plugin/__tests__/examples.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function parseESLintOutput({
6060
/\(node:\d+\) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https:\/\/eslint.org\/docs\/latest\/use\/configure\/migration-guide for details./,
6161
'',
6262
)
63+
.replace(
64+
'An eslintrc configuration file is used because you have the ESLINT_USE_FLAT_CONFIG environment variable set to false. If you want to use an eslint.config.js file, remove the environment variable. If you want to find the location of the eslintrc configuration file, use the --debug flag.',
65+
'',
66+
)
6367
.replace('(Use `node --trace-deprecation ...` to show where the warning was created)', '')
6468
.replace('(Use `node --trace-warnings ...` to show where the warning was created)', '')
6569
.trimEnd();
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
query {
1+
{
22
hello
33
}

packages/plugin/__tests__/schema.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ describe('schema', async () => {
114114

115115
it('should load the graphql-config rc file relative to the linted file', () => {
116116
const gqlConfig = loadGraphQLConfig({
117-
graphQLConfig: {
118-
schema: path.resolve(__dirname, 'mocks/using-config/schema-in-config.graphql'),
119-
},
120-
filePath: path.resolve(__dirname, 'mocks/using-config/test.graphql'),
117+
filePath: path.resolve(__dirname, 'mocks/using-config/nested/test.graphql'),
121118
});
122119

123120
const graphQLSchema = getSchema(gqlConfig.getDefault()) as GraphQLSchema;

packages/plugin/src/processor.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { asArray } from '@graphql-tools/utils';
99
import { loadOnDiskGraphQLConfig } from './graphql-config.js';
1010
import { version } from './meta.js';
11-
import { CWD, REPORT_ON_FIRST_CHARACTER, truthy } from './utils.js';
11+
import { CWD, REPORT_ON_FIRST_CHARACTER } from './utils.js';
1212

1313
export type Block = Linter.ProcessorFile & {
1414
lineOffset: number;
@@ -50,15 +50,10 @@ export const processor = {
5050
gqlMagicComment = 'GraphQL',
5151
} = pluckConfig;
5252

53-
keywords = [
54-
...new Set(
55-
[
56-
...modules.map(({ identifier }) => identifier),
57-
...asArray(globalGqlIdentifierName),
58-
gqlMagicComment,
59-
].filter(truthy),
60-
),
61-
];
53+
const mods = modules.map(({ identifier }) => identifier).filter((v): v is string => !!v);
54+
55+
const result = [...mods, ...asArray(globalGqlIdentifierName), gqlMagicComment];
56+
keywords = [...new Set(result)];
6257
}
6358

6459
if (keywords.every(keyword => !code.includes(keyword))) {

packages/plugin/src/rules/alphabetize/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { FromSchema } from 'json-schema-to-ts';
2222
import lowerCase from 'lodash.lowercase';
2323
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
2424
import { GraphQLESLintRule, GraphQLESLintRuleListener } from '../../types.js';
25-
import { ARRAY_DEFAULT_OPTIONS, displayNodeName, truthy } from '../../utils.js';
25+
import { ARRAY_DEFAULT_OPTIONS, displayNodeName } from '../../utils.js';
2626

2727
const RULE_ID = 'alphabetize';
2828

@@ -348,7 +348,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
348348
Kind.INPUT_OBJECT_TYPE_EXTENSION,
349349
],
350350
]
351-
.filter(truthy)
351+
.filter(v => !!v)
352352
.flat();
353353

354354
const fieldsSelector = kinds.join(',');

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
convertCase,
88
displayNodeName,
99
englishJoinWords,
10-
truthy,
1110
TYPES_KINDS,
1211
} from '../../utils.js';
1312

@@ -511,7 +510,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
511510
}
512511

513512
const selectors = new Set(
514-
[types && TYPES_KINDS, Object.keys(restOptions)].flat().filter(truthy),
513+
[types && TYPES_KINDS, Object.keys(restOptions)].filter(v => !!v).flat(),
515514
);
516515

517516
for (const selector of selectors) {

packages/plugin/src/rules/no-root-type/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NameNode } from 'graphql';
22
import { FromSchema } from 'json-schema-to-ts';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule } from '../../types.js';
5-
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchema, truthy } from '../../utils.js';
5+
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchema } from '../../utils.js';
66

77
const schema = {
88
type: 'array',
@@ -66,7 +66,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
6666
disallow.has('mutation') && schema.getMutationType(),
6767
disallow.has('subscription') && schema.getSubscriptionType(),
6868
]
69-
.filter(truthy)
69+
.filter(v => !!v)
7070
.map(type => type.name)
7171
.join('|');
7272

0 commit comments

Comments
 (0)