Skip to content

Commit 4e323ca

Browse files
authored
eslint - no-unused-variables, prefer-optional-chain, object-has-own (dotansimha#8800)
* no-unused-variables, prefer-optional-chain, object-has-own * commit (dotansimha#8801) * enable `prefer-object-has-own` in v3, disable for now
1 parent 5c66efc commit 4e323ca

Some content is hidden

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

47 files changed

+151
-315
lines changed

.eslintrc.cjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ module.exports = {
33
extends: ['@theguild'],
44
rules: {
55
'no-empty': 'off',
6-
'no-prototype-builtins': 'off',
7-
'no-useless-constructor': 'off',
86
'@typescript-eslint/explicit-module-boundary-types': 'off',
9-
'@typescript-eslint/no-unused-vars': 'off',
107
'@typescript-eslint/no-use-before-define': 'off',
118
'@typescript-eslint/no-namespace': 'off',
129
'@typescript-eslint/no-empty-interface': 'off',
@@ -28,9 +25,9 @@ module.exports = {
2825
'import/no-default-export': 'off',
2926
// todo: enable in v3
3027
'unicorn/prefer-node-protocol': 'off',
28+
'prefer-object-has-own': 'off',
3129
},
3230
env: {
33-
es6: true,
3431
node: true,
3532
},
3633
overrides: [
@@ -44,10 +41,15 @@ module.exports = {
4441
jest: true,
4542
},
4643
rules: {
47-
'@typescript-eslint/no-unused-vars': 'off',
4844
'import/no-extraneous-dependencies': 'off',
4945
},
5046
},
47+
{
48+
files: '**/tests/fixtures/*.ts',
49+
rules: {
50+
'@typescript-eslint/no-unused-vars': 'off',
51+
},
52+
},
5153
],
5254
ignorePatterns: ['dev-test', 'examples/front-end', 'website'],
5355
};

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
coverage
66
*.log
77
node_modules/
8-
temp
8+
temp/
99
junit.xml
1010
dist/
1111
.bob/
1212
out.txt
1313
.cache
1414
tsconfig.tsbuildinfo
15-
.yarn
15+
.yarn/
1616
recompile.sh
1717

1818
.next/
19-
out
19+
out/
2020
website/public/sitemap.xml
2121
website/public/_redirects
2222
.eslintcache

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ website/src/pages/plugins/presets/near-operation-file-preset.mdx
2222
examples/**/gql/**
2323

2424
website/algolia-lockfile.json
25+
temp/

package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@
3939
"@graphql-typed-document-node/core": "3.1.1",
4040
"@reduxjs/toolkit": "1.8.5",
4141
"@tanstack/react-query": "4.2.3",
42-
"@theguild/eslint-config": "0.4.2",
42+
"@theguild/eslint-config": "0.5.0",
4343
"@theguild/prettier-config": "0.1.1",
4444
"@types/common-tags": "1.8.1",
4545
"@types/jest": "28.1.8",
4646
"@types/mkdirp": "1.0.2",
4747
"@types/node": "18.11.18",
4848
"@types/react": "18.0.18",
4949
"@types/webpack-env": "1.18.0",
50-
"@typescript-eslint/eslint-plugin": "5.36.2",
51-
"@typescript-eslint/parser": "5.36.2",
5250
"@urql/exchange-graphcache": "5.0.5",
5351
"@vue/apollo-composable": "4.0.0-alpha.19",
5452
"@vue/composition-api": "1.7.0",
@@ -59,13 +57,7 @@
5957
"bob-the-bundler": "4.0.0",
6058
"chalk": "4.1.2",
6159
"dotenv": "16.0.2",
62-
"eslint": "8.23.0",
63-
"eslint-config-prettier": "8.5.0",
64-
"eslint-config-standard": "17.0.0",
65-
"eslint-plugin-import": "2.26.0",
66-
"eslint-plugin-n": "15.2.5",
67-
"eslint-plugin-promise": "6.0.1",
68-
"eslint-plugin-react-hooks": "4.6.0",
60+
"eslint": "8.31.0",
6961
"flow-bin": "0.186.0",
7062
"flow-parser": "0.186.0",
7163
"fs-extra": "10.1.0",

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
8282
const cache = createCache();
8383

8484
function wrapTask(task: () => void | Promise<void>, source: string, taskName: string, ctx: Ctx) {
85-
return () => {
86-
return context.profiler.run(async () => {
85+
return () =>
86+
context.profiler.run(async () => {
8787
try {
8888
await Promise.resolve().then(() => task());
8989
} catch (error) {
@@ -95,7 +95,6 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
9595
throw error;
9696
}
9797
}, taskName);
98-
};
9998
}
10099

101100
async function normalize() {
@@ -203,7 +202,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
203202

204203
return {
205204
title,
206-
task: async (_, subTask) => {
205+
async task(_, subTask) {
207206
let outputSchemaAst: GraphQLSchema;
208207
let outputSchema: DocumentNode;
209208
const outputFileTemplateConfig = outputConfig.config || {};
@@ -217,7 +216,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
217216
: outputConfig.preset
218217
: null;
219218

220-
if (preset && preset.prepareDocuments) {
219+
if (preset?.prepareDocuments) {
221220
outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
222221
}
223222

@@ -314,7 +313,7 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
314313
...(typeof outputFileTemplateConfig === 'string'
315314
? { value: outputFileTemplateConfig }
316315
: outputFileTemplateConfig),
317-
emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config, filename),
316+
emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config),
318317
};
319318

320319
const outputs: Types.GenerateOptions[] = preset
@@ -400,7 +399,6 @@ export async function executeCodegen(input: CodegenContext | Types.Config): Prom
400399
// All the errors throw in `listr2` are collected in context
401400
// Running tasks doesn't throw anything
402401
const executedContext = await tasks.run();
403-
404402
if (config.debug) {
405403
// if we have debug logs, make sure to print them before throwing the errors
406404
printLogs();

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ export async function loadCodegenConfig({
121121
packageProp,
122122
loaders: customLoaders,
123123
}: LoadCodegenConfigOptions): Promise<LoadCodegenConfigResult> {
124-
configFilePath = configFilePath || process.cwd();
125-
moduleName = moduleName || 'codegen';
126-
packageProp = packageProp || moduleName;
124+
configFilePath ||= process.cwd();
125+
moduleName ||= 'codegen';
126+
packageProp ||= moduleName;
127127
const cosmi = cosmiconfig(moduleName, {
128128
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
129129
packageProp,
@@ -145,9 +145,7 @@ export async function loadContext(configFilePath?: string): Promise<CodegenConte
145145
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
146146

147147
if (graphqlConfig) {
148-
return new CodegenContext({
149-
graphqlConfig,
150-
});
148+
return new CodegenContext({ graphqlConfig });
151149
}
152150

153151
const result = await loadCodegenConfig({ configFilePath });
@@ -203,7 +201,7 @@ export function buildOptions() {
203201
alias: 'watch',
204202
describe:
205203
'Watch for changes and execute generation automatically. You can also specify a glob expression for custom watch list.',
206-
coerce: (watch: any) => {
204+
coerce(watch: any) {
207205
if (watch === 'false') {
208206
return false;
209207
}
@@ -489,7 +487,7 @@ function addHashToDocumentFiles(documentFilesPromise: Promise<Types.DocumentFile
489487
);
490488
}
491489

492-
export function shouldEmitLegacyCommonJSImports(config: Types.Config, outputPath: string): boolean {
490+
export function shouldEmitLegacyCommonJSImports(config: Types.Config): boolean {
493491
const globalValue = config.emitLegacyCommonJSImports === undefined ? true : Boolean(config.emitLegacyCommonJSImports);
494492
// const outputConfig = config.generates[outputPath];
495493

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function isGraphQLConfig(config: GraphQLConfig): config is GraphQLConfig {
6161

6262
try {
6363
for (const projectName in config.projects) {
64-
if (config.projects.hasOwnProperty(projectName)) {
64+
if (Object.prototype.hasOwnProperty.call(config.projects, projectName)) {
6565
const project = config.projects[projectName];
6666

6767
if (project.hasExtension('codegen')) {

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,12 @@ export async function writePackage(answers: Answers, configLocation: string) {
7676
const pkg = JSON.parse(pkgContent);
7777
const { indent } = detectIndent(pkgContent);
7878

79-
if (!pkg.scripts) {
80-
pkg.scripts = {};
81-
}
79+
pkg.scripts ||= {};
8280

8381
pkg.scripts[answers.script] = `graphql-codegen --config ${configLocation}`;
8482

8583
// plugin
86-
if (!pkg.devDependencies) {
87-
pkg.devDependencies = {};
88-
}
84+
pkg.devDependencies ||= {};
8985

9086
await Promise.all(
9187
(answers.plugins || []).map(async plugin => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export async function getPresetByName(
1616
try {
1717
const loaded = await loader(moduleName);
1818

19-
if (loaded && loaded.preset) {
19+
if (loaded?.preset) {
2020
return loaded.preset;
2121
}
22-
if (loaded && loaded.default) {
22+
if (loaded?.default) {
2323
return loaded.default;
2424
}
2525

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function setSilentLogger() {
1717
}
1818

1919
export function useWinstonLogger() {
20-
if (logger && logger.levels) {
20+
if (logger?.levels) {
2121
return;
2222
}
2323

0 commit comments

Comments
 (0)