Skip to content

Commit 5c66efc

Browse files
authored
eslint fixes (dotansimha#8798)
* fixes * fixes * fixes * fixes * fixes * fixes * fixes * fixes * fixes * fixes * update yarn.lock * prettier * remove `node:` protocol (not available in node 12)
1 parent 2672c95 commit 5c66efc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+173
-310
lines changed

.eslintrc.cjs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,51 @@ module.exports = {
33
extends: ['@theguild'],
44
rules: {
55
'no-empty': 'off',
6-
'no-console': 'error',
76
'no-prototype-builtins': 'off',
87
'no-useless-constructor': 'off',
9-
'no-unused-vars': 'off',
10-
'object-shorthand': ['error', 'always'],
118
'@typescript-eslint/explicit-module-boundary-types': 'off',
129
'@typescript-eslint/no-unused-vars': 'off',
1310
'@typescript-eslint/no-use-before-define': 'off',
1411
'@typescript-eslint/no-namespace': 'off',
15-
'no-unreachable-loop': 'error',
1612
'@typescript-eslint/no-empty-interface': 'off',
17-
'prefer-arrow-callback': 'error',
1813
'@typescript-eslint/no-empty-function': 'off',
1914
'@typescript-eslint/no-var-requires': 'off',
2015
'@typescript-eslint/no-explicit-any': 'off',
2116
'@typescript-eslint/no-non-null-assertion': 'off',
2217
'@typescript-eslint/explicit-function-return-type': 'off',
2318
'@typescript-eslint/ban-ts-ignore': 'off',
2419
'@typescript-eslint/ban-types': 'off',
25-
'no-lonely-if': 'error',
2620
'import/no-extraneous-dependencies': [
2721
'error',
2822
{ devDependencies: ['**/*.test.ts', '**/*.spec.ts', '**/test/**/*.ts'] },
2923
],
3024

3125
// todo: enable
32-
'unicorn/prefer-node-protocol': 'off',
33-
'no-restricted-syntax': 'off',
3426
'unicorn/filename-case': 'off',
3527
'import/extensions': 'off',
36-
'no-implicit-coercion': 'off',
37-
'unicorn/numeric-separators-style': 'off',
3828
'import/no-default-export': 'off',
39-
'unicorn/no-lonely-if': 'off',
40-
'unicorn/no-useless-spread': 'off',
41-
'simple-import-sort/exports': 'off',
42-
'unicorn/no-array-push-push': 'off',
43-
'no-else-return': 'off',
44-
'no-undef': 'off',
45-
'import/first': 'off',
46-
'n/no-restricted-import': 'off',
47-
'import/no-duplicates': 'off',
29+
// todo: enable in v3
30+
'unicorn/prefer-node-protocol': 'off',
4831
},
4932
env: {
5033
es6: true,
5134
node: true,
5235
},
5336
overrides: [
5437
{
55-
files: ['**/tests/**/*.ts', '**/graphql-codegen-testing/**/*.ts', '*.spec.ts'],
38+
files: ['website/**'],
39+
extends: '@theguild/eslint-config/react',
40+
},
41+
{
42+
files: ['**/tests/**/*.{js,ts,tsx}', '**/graphql-codegen-testing/**/*.ts', '*.spec.ts'],
5643
env: {
5744
jest: true,
5845
},
5946
rules: {
60-
'no-unused-vars': 'off',
6147
'@typescript-eslint/no-unused-vars': 'off',
6248
'import/no-extraneous-dependencies': 'off',
6349
},
6450
},
6551
],
66-
ignorePatterns: ['dist', 'node_modules', 'dev-test', 'website', 'test-files', 'examples/front-end', '.bob'],
52+
ignorePatterns: ['dev-test', 'examples/front-end', 'website'],
6753
};

examples/programmatic-typescript/src/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import { promises } from 'fs';
2+
import { promises } from 'node:fs';
33
import { codegen } from '@graphql-codegen/core';
44
import { getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers';
55
import * as typedDocumentNode from '@graphql-codegen/typed-document-node';
@@ -76,9 +76,7 @@ const schema = makeExecutableSchema({
7676
...(await prettier.resolveConfig(process.cwd())),
7777
parser: 'typescript',
7878
}),
79-
{
80-
encoding: 'utf-8',
81-
}
79+
'utf8'
8280
);
8381
console.log('done generating.');
8482
})().catch(err => {

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const PROJECTS = false;
2-
const CI = !!process.env.CI;
2+
const CI = Boolean(process.env.CI);
33

44
module.exports =
55
!PROJECTS || CI

jest.project.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const { resolve } = require('path');
2+
// eslint-disable-next-line import/no-extraneous-dependencies -- false positive
23
const { pathsToModuleNameMapper } = require('ts-jest');
34

45
const ROOT_DIR = __dirname;
56
const TSCONFIG = resolve(ROOT_DIR, 'tsconfig.json');
67
const tsconfig = require(TSCONFIG);
7-
const CI = !!process.env.CI;
8+
const CI = Boolean(process.env.CI);
89

910
module.exports = ({ dirname, projectMode = true }) => {
1011
const pkg = require(resolve(dirname, 'package.json'));
@@ -21,7 +22,7 @@ module.exports = ({ dirname, projectMode = true }) => {
2122
cacheDirectory: resolve(ROOT_DIR, `${CI ? '' : 'node_modules/'}.cache/jest`),
2223
setupFiles: [`${ROOT_DIR}/dev-test/setup.js`],
2324
collectCoverage: false,
24-
testTimeout: 20000,
25+
testTimeout: 20_000,
2526
resolver: 'bob-the-bundler/jest-resolver.js',
2627
snapshotFormat: {
2728
escapeString: false,

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"build": "bob build",
99
"watch-build": "npx tsc-watch --project tsconfig.json --onSuccess \"bob build\"",
1010
"test": "jest --forceExit --no-watchman",
11-
"lint": "eslint --cache --ext .ts .",
11+
"lint": "eslint --cache --ignore-path .gitignore .",
1212
"prettier": "prettier --cache --write --list-different .",
1313
"prettier:check": "prettier --cache --check .",
1414
"types:check": "tsc --noEmit",
1515
"test-and-build": "yarn build && yarn test",
16-
"ci:lint": "eslint --ext .ts . --output-file eslint_report.json --format json",
16+
"ci:lint": "eslint --cache --ignore-path .gitignore --output-file eslint_report.json --format json .",
1717
"prerelease": "yarn build",
1818
"release": "changeset publish",
1919
"generate:examples:esm": "node packages/graphql-codegen-cli/dist/esm/bin.js --require dotenv/config --config ./dev-test/codegen.ts dotenv_config_path=dev-test/.env",

packages/graphql-codegen-cli/src/codegen.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
197197
task: (ctx, task) => {
198198
const generateTasks: ListrTask<Ctx>[] = Object.keys(generates).map(filename => {
199199
const outputConfig = generates[filename];
200-
const hasPreset = !!outputConfig.preset;
200+
const hasPreset = Boolean(outputConfig.preset);
201201

202202
const title = `Generate to ${filename}`;
203203

@@ -217,10 +217,8 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
217217
: outputConfig.preset
218218
: null;
219219

220-
if (preset) {
221-
if (preset.prepareDocuments) {
222-
outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
223-
}
220+
if (preset && preset.prepareDocuments) {
221+
outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
224222
}
225223

226224
return subTask.newListr(
@@ -352,10 +350,9 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
352350

353351
const process = async (outputArgs: Types.GenerateOptions) => {
354352
const output = await codegen({
355-
...{
356-
...outputArgs,
357-
emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config, outputArgs.filename),
358-
},
353+
...outputArgs,
354+
// @ts-expect-error todo: fix 'emitLegacyCommonJSImports' does not exist in type 'GenerateOptions'
355+
emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config, outputArgs.filename),
359356
cache,
360357
});
361358
result.push({
@@ -411,7 +408,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
411408

412409
if (executedContext.errors.length > 0) {
413410
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
414-
const newErr = new AggregateError(executedContext.errors, `${errors.join('\n\n')}`);
411+
const newErr = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
415412
// Best-effort to all stack traces for debugging
416413
newErr.stack = `${newErr.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;
417414
throw newErr;

packages/graphql-codegen-cli/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export function buildOptions() {
210210
if (typeof watch === 'string' || Array.isArray(watch)) {
211211
return watch;
212212
}
213-
return !!watch;
213+
return Boolean(watch);
214214
},
215215
},
216216
r: {
@@ -490,7 +490,7 @@ function addHashToDocumentFiles(documentFilesPromise: Promise<Types.DocumentFile
490490
}
491491

492492
export function shouldEmitLegacyCommonJSImports(config: Types.Config, outputPath: string): boolean {
493-
const globalValue = config.emitLegacyCommonJSImports === undefined ? true : !!config.emitLegacyCommonJSImports;
493+
const globalValue = config.emitLegacyCommonJSImports === undefined ? true : Boolean(config.emitLegacyCommonJSImports);
494494
// const outputConfig = config.generates[outputPath];
495495

496496
// if (!outputConfig) {

packages/graphql-codegen-cli/src/generate-and-save.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export async function generate(
144144
}
145145

146146
function shouldOverwrite(config: Types.Config, outputPath: string): boolean {
147-
const globalValue = config.overwrite === undefined ? true : !!config.overwrite;
147+
const globalValue = config.overwrite === undefined ? true : Boolean(config.overwrite);
148148
const outputConfig = config.generates[outputPath];
149149

150150
if (!outputConfig) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
export * from './cli.js';
12
export { executeCodegen } from './codegen.js';
2-
export { generate } from './generate-and-save.js';
33
export * from './config.js';
4+
export { CodegenConfig } from './config.js';
5+
export { generate } from './generate-and-save.js';
6+
export * from './graphql-config.js';
47
export * from './init/index.js';
58
export * from './utils/cli-error.js';
6-
export * from './cli.js';
7-
export * from './graphql-config.js';
8-
export { CodegenConfig } from './config.js';

packages/graphql-codegen-cli/src/init/helpers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ export default config;
6060
} else {
6161
content = ext === 'json' ? JSON.stringify(config) : YAML.stringify(config);
6262
}
63-
writeFileSync(fullPath, content, {
64-
encoding: 'utf-8',
65-
});
63+
writeFileSync(fullPath, content, 'utf8');
6664

6765
return {
6866
relativePath,
@@ -74,9 +72,7 @@ export default config;
7472
export async function writePackage(answers: Answers, configLocation: string) {
7573
// script
7674
const pkgPath = resolve(process.cwd(), 'package.json');
77-
const pkgContent = readFileSync(pkgPath, {
78-
encoding: 'utf-8',
79-
});
75+
const pkgContent = readFileSync(pkgPath, 'utf8');
8076
const pkg = JSON.parse(pkgContent);
8177
const { indent } = detectIndent(pkgContent);
8278

0 commit comments

Comments
 (0)