Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared eslint setup #1902

Merged
merged 5 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/generated/**
60 changes: 50 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
module.exports = {
root: true,
env: {
es2020: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-else-return': ['error', { allowElseIf: false }],
'object-shorthand': ['error', 'always'],
},
extends: ['@theguild'],
overrides: [
{
files: ['packages/graphql-yoga/src/plugins/**/*.ts'],
rules: {
'unicorn/filename-case': 'off',
},
},
{
files: ['website/**'],
rules: { 'import/no-default-export': 'off' },
},
{
files: ['examples/**'],
rules: {
'import/extensions': 'off',
'unicorn/filename-case': 'off',
'no-console': 'off',
'import/no-default-export': 'off',
},
},
{
files: [
'**/__tests__/**',
'**/*.spec.ts',
'**/*.test.ts',
'e2e/**',
'**/__integration-tests__/**',
],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'import/extensions': 'off',
'unicorn/filename-case': 'off',
},
},
{
files: ['e2e/**'],
rules: {
'no-console': 'off',
},
},
{
files: ['packages/graphiql/**', 'packages/render-graphiql/**'],
rules: {
'unicorn/filename-case': 'off',
'import/extensions': 'off',
'import/no-default-export': 'off',
},
},
],
}
3 changes: 3 additions & 0 deletions benchmark/hello-world/check-server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-undef */
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-var-requires */
require('@whatwg-node/fetch')
.fetch(
`http://localhost:4000/graphql?query=${encodeURIComponent(
Expand Down
1 change: 1 addition & 0 deletions benchmark/hello-world/k6.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import { check } from 'k6'
import http from 'k6/http'
import { textSummary } from 'https://jslib.k6.io/k6-summary/0.0.1/index.js'
Expand Down
1 change: 1 addition & 0 deletions benchmark/hello-world/start-server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { createServer } = require('http')
const { createYoga, createSchema } = require('graphql-yoga')

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/aws-lambda.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Stack } from '@pulumi/pulumi/automation'
import { DeploymentConfiguration } from '../types'
import type { DeploymentConfiguration } from '../types'
import { assertGraphiQL, assertQuery, env, execPromise } from '../utils'
import * as pulumi from '@pulumi/pulumi'
import * as aws from '@pulumi/aws'
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../utils'
import * as docker from '@pulumi/docker'
import { interpolate } from '@pulumi/pulumi'
import { join, resolve } from 'path'
import { resolve } from 'path'

export const dockerDeployment = (
image: string,
Expand Down
1 change: 1 addition & 0 deletions e2e/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Output } from '@pulumi/pulumi'
import { OutputValue, Stack } from '@pulumi/pulumi/automation'

// eslint-disable-next-line @typescript-eslint/ban-types
export type DeploymentConfiguration<TProgramOutput = {}> = {
prerequisites?: (stack: Stack) => Promise<void>
config?: (stack: Stack) => Promise<void>
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function getCommitId() {
export async function waitForEndpoint(
endpoint: string,
retries: number,
timeout: number = 10000,
timeout = 10000,
): Promise<boolean> {
for (let attempt = 1; attempt <= retries; attempt++) {
console.info(
Expand Down
1 change: 1 addition & 0 deletions examples/apollo-federation/gateway/gateway.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can still lint examples, to avoid future errors, some things we can explicitly ignores like eslint-disable-next-line or eslint-disable-line but not full file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these node examples it was complaining a lot about require not defined and do not use require so I decide to disable linting on full example

Copy link
Collaborator

@dimaMachina dimaMachina Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to replace require with importing examples? Since node 12 is deprecated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn’t we need to be on node 16+ for that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 16 is good!

const { createYoga } = require('graphql-yoga')
const { ApolloGateway, RemoteGraphQLDataSource } = require('@apollo/gateway')
const { useApolloFederation } = require('@envelop/apollo-federation')
Expand Down
1 change: 1 addition & 0 deletions examples/apollo-federation/gateway/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { createServer } = require('http')
const { gateway, DataSource } = require('./gateway')

Expand Down
1 change: 1 addition & 0 deletions examples/apollo-federation/service/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { createServer } = require('http')
const { yoga } = require('./yoga')

Expand Down
1 change: 1 addition & 0 deletions examples/apollo-federation/service/yoga.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { parse } = require('graphql')
const { buildSubgraphSchema } = require('@apollo/subgraph')
const { createYoga } = require('graphql-yoga')
Expand Down
1 change: 1 addition & 0 deletions examples/aws-lambda/scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { build } = require('esbuild')

async function main() {
Expand Down
1 change: 1 addition & 0 deletions examples/azure-function/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { build } = require('esbuild')
const { writeFileSync } = require('fs')

Expand Down
1 change: 0 additions & 1 deletion examples/deno/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assertEquals } from 'https://deno.land/std@0.158.0/testing/asserts.ts'
import { yoga } from './yoga.ts'

Deno.test('Deno example test', async () => {
// @ts-ignore for weird reason TS types not working well here?
const response = await yoga.fetch('http://yoga/graphql?query={hello}', {})
const { data } = await response.json()
assertEquals(data.hello, 'Hello Deno!')
Expand Down
1 change: 0 additions & 1 deletion examples/fastify/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createYoga, createSchema } from 'graphql-yoga'
import fastify, { FastifyReply, FastifyRequest } from 'fastify'
import { Readable } from 'stream'

export function buildApp(logging = true) {
const app = fastify({
Expand Down
2 changes: 1 addition & 1 deletion examples/generic-auth/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const users: Record<string, User> = {
},
}

export const yoga = createYoga<{}, { currentUser: User }>({
export const yoga = createYoga<unknown, { currentUser: User }>({
plugins: [
useGenericAuth({
mode: 'protect-granular',
Expand Down
1 change: 0 additions & 1 deletion examples/graphql-armor/src/yoga.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createSchema, createYoga } from 'graphql-yoga'
import { EnvelopArmor } from '@escape.tech/graphql-armor'
import { createServer } from 'http'

const armor = new EnvelopArmor()
const enhancements = armor.protect()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
declare module '@prisma/migrate' {
// https://github.com/prisma/prisma/blob/main/packages/internals/src/cli/types.ts
class Command {
Expand Down
2 changes: 1 addition & 1 deletion examples/hackernews/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const resolvers = {
id: (parent: Link) => parent.id,
description: (parent: Link) => parent.description,
url: (parent: Link) => parent.url,
comments: (parent: Link, args: {}, context: GraphQLContext) => {
comments: (parent: Link, _: unknown, context: GraphQLContext) => {
return context.prisma.comment.findMany({
where: {
linkId: parent.id,
Expand Down
4 changes: 4 additions & 0 deletions examples/hello-world/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// eslint-disable-next-line no-undef
const { createServer } = require('node:http')
// eslint-disable-next-line no-undef
const { createYoga, createSchema } = require('graphql-yoga')

const yoga = createYoga({
Expand Down Expand Up @@ -26,5 +29,6 @@ const yoga = createYoga({

const server = createServer(yoga)
server.listen(4000, () => {
// eslint-disable-next-line no-undef
console.log('Server listening on http://localhost:4000/graphql')
})
1 change: 0 additions & 1 deletion examples/koa/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createYoga, createSchema } from 'graphql-yoga'
import Koa from 'koa'
import { Readable } from 'stream'

export function buildApp() {
const app = new Koa()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import yoga from '../src'
import { createServer, Server } from 'http'
import { AddressInfo } from 'net'
import { fetch } from '@whatwg-node/fetch'

describe('netlify-edge example integration', () => {
it('should execute query', async () => {
Expand Down
1 change: 1 addition & 0 deletions examples/netlify-edge/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { build } = require('esbuild')

async function main() {
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs/scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { build } = require('esbuild')

async function main() {
Expand Down
1 change: 1 addition & 0 deletions examples/node-ts/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const { build } = require('esbuild')
const { writeFileSync } = require('fs')

Expand Down
2 changes: 2 additions & 0 deletions examples/node-ts/src/yoga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createYoga, Plugin, createSchema } from 'graphql-yoga'
import { GraphQLError } from 'graphql'

// available when handling requests, needs to be provided by the implementor
// eslint-disable-next-line @typescript-eslint/ban-types
type ServerContext = {}

// available in GraphQL, during execution/subscription
Expand Down Expand Up @@ -40,6 +41,7 @@ export const yoga = createYoga<ServerContext, UserContext>({
})

// context only relevant to the plugin
// eslint-disable-next-line @typescript-eslint/ban-types
type DisableSubscriptionPluginContext = {}

function useDisableSubscription(): Plugin<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ describe('Service worker', () => {

expect(response.status).toBe(200)
expect(response.headers.get('content-type')).toBe('text/event-stream')
// eslint-disable-next-line no-unreachable-loop, @typescript-eslint/no-explicit-any
for await (const chunk of response.body as any) {
expect(Buffer.from(chunk).toString('utf-8')).toMatch(/data: {/)
break
Expand Down
2 changes: 1 addition & 1 deletion examples/service-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createYoga, createSchema, Repeater } from 'graphql-yoga'

// We can define GraphQL Route dynamically using env vars.
declare var GRAPHQL_ROUTE: string
declare let GRAPHQL_ROUTE: string

const yoga = createYoga({
graphqlEndpoint: GRAPHQL_ROUTE || '/graphql',
Expand Down
2 changes: 1 addition & 1 deletion examples/subscriptions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const resolvers: Resolvers<Context> = {
console.log('push')
}
increment()
let interval = setInterval(increment, 1000)
const interval = setInterval(increment, 1000)
stop.then(() => {
clearInterval(interval)
console.log('stop')
Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { resolve } = require('path')
const { pathsToModuleNameMapper } = require('ts-jest')
const CI = !!process.env.CI
Expand All @@ -18,8 +19,7 @@ if (process.env.INTEGRATION_TEST === 'true') {
'<rootDir>/**/__integration-tests__/**/?(*.)+(spec|test).[jt]s?(x)',
)
if (parseInt(process.versions.node.split('.')[0]) <= 14) {
testMatch.push('!**/examples/sveltekit/**')
testMatch.push('!**/examples/fastify*/**')
testMatch.push('!**/examples/sveltekit/**', '!**/examples/fastify*/**')
}
testMatch.push('!**/examples/bun*/**')
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"release": "yarn build && changeset publish",
"start:docs": "yarn workspace website dev",
"postinstall": "patch-package && husky install",
"fix-bin": "node scripts/fix-bin.js",
"lint": "eslint --ignore-path .gitignore --ext ts,js,tsx,jsx .",
"prettier": "prettier --ignore-path .prettierignore --write --list-different .",
"prettier:check": "prettier --ignore-path .prettierignore --check .",
Expand Down Expand Up @@ -66,6 +65,7 @@
"@babel/preset-typescript": "7.18.6",
"@changesets/changelog-github": "0.4.7",
"@changesets/cli": "2.24.4",
"@theguild/eslint-config": "0.2.0",
"@types/babel__core": "^7",
"@types/babel__preset-env": "^7",
"@types/jest": "^29.0.0",
Expand Down
8 changes: 3 additions & 5 deletions packages/client/apollo-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ function createYogaApolloRequestHandler(
observer.next(result)
}
observer.complete()
} else {
if (!observer.closed) {
observer.next(results)
observer.complete()
}
} else if (!observer.closed) {
observer.next(results)
observer.complete()
}
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Client, createClient, OperationResult } from '@urql/core'
import { Client, createClient } from '@urql/core'
import { yogaExchange } from '@graphql-yoga/urql-exchange'
import { observableToAsyncIterable } from '@graphql-tools/utils'
import { pipe, toObservable } from 'wonka'
import { createYoga, createSchema } from 'graphql-yoga'
import { File } from '@whatwg-node/fetch'
Expand Down
5 changes: 3 additions & 2 deletions packages/client/urql-exchange/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
Operation,
OperationResult,
getOperationName,
Client,
OperationContext,
ExchangeIO,
AnyVariables,
Expand All @@ -36,10 +35,12 @@ export type YogaExchangeOptions = LoadFromUrlOptions

export function yogaExchange(options?: YogaExchangeOptions): Exchange {
const urlLoader = new UrlLoader()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function makeYogaSource<TData extends Record<string, any>>(
operation: Operation<TData>,
): Source<OperationResult<TData>> {
const operationName = getOperationName(operation.query)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const executionRequest: ExecutionRequest<any, OperationContext> = {
document: operation.query,
operationName,
Expand Down Expand Up @@ -108,7 +109,7 @@ export function yogaExchange(options?: YogaExchangeOptions): Exchange {
}
})
}
return function yogaExchangeFn({ forward, client }): ExchangeIO {
return function yogaExchangeFn({ forward }): ExchangeIO {
return function yogaExchangeIO<TData, TVariables extends AnyVariables>(
ops$: Source<Operation<TData, TVariables>>,
): Source<OperationResult<TData>> {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/warning.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
console.warn(
`@graphql-yoga/common package has been deprecated and will no longer receive updates in the next major.`,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/event-target/redis-event-target/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createRedisEventTarget<TEvent extends CustomEvent>(
}

function removeCallback(topic: string, callback: (event: TEvent) => void) {
let callbacks = callbacksForTopic.get(topic)
const callbacks = callbacksForTopic.get(topic)
if (callbacks === undefined) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql/src/bundle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { YogaGraphiQL, YogaGraphiQLProps } from './YogaGraphiQL'
import { YogaGraphiQL, YogaGraphiQLProps } from './YogaGraphiQL.js'

export function renderYogaGraphiQL(element: Element, opts?: YogaGraphiQLProps) {
ReactDOM.render(<YogaGraphiQL {...opts} />, element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('subscription', () => {
const port = (server.address() as AddressInfo).port

// Start and Close a HTTP SSE subscription
// eslint-disable-next-line no-async-promise-executor
await new Promise<void>(async (res) => {
const response = await fetch(
`http://localhost:${port}/graphql?query=subscription{foo}`,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql-yoga/__tests__/context.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-empty-function */
import { createSchema } from '../src/schema'
import { createYoga } from '../src/server'
import { YogaInitialContext } from '../src/types'
Expand Down
Loading