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

chore: upgrade eslint to flat config #258

Merged
merged 2 commits into from
Sep 16, 2024
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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

43 changes: 0 additions & 43 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: yarn install --offline

- name: Format and Lint check
run: yarn check-format && yarn check-tsc && yarn lint && yarn build && yarn check-exports
run: yarn check-tsc && yarn lint && yarn build && yarn check-exports

- name: Tests and Coverage
run: yarn test --coverage
43 changes: 43 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import prettierPlugin from "eslint-plugin-prettier/recommended";

export default tseslint.config(
{
ignores: [
".stryker-tmp/",
".tsup/",
".vscode",
"dist/",
"examples/",
"node_modules/",
"scripts/"
]
},
eslint.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
"no-console": "error",
"no-throw-literal": "error",
"no-new-func": "error",
"no-self-compare": "error",
"no-useless-call": "error",
"no-sequences": "error",
"no-template-curly-in-string": "error",
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-non-null-assertion": "error",

"@typescript-eslint/no-unused-vars": "warn",

"@typescript-eslint/no-explicit-any": "off"
}
},
{
files: ["**/__benchmarks__/**", "**/__tests__/**"],
rules: {
"no-console": "off"
}
},
prettierPlugin
);
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
"benchmark": "NODE_ENV=production ./src/__benchmarks__/benchmarks.ts",
"build": "yarn tsup-node",
"check-exports": "attw --pack .",
"check-format": "prettier -l 'src/**/*.ts'",
"check-tsc": "tsc --noEmit",
"codecov": "codecov",
"eslint": "eslint --ext .ts .",
"format": "prettier --write 'src/**/*.ts'",
"lint-fix": "yarn eslint --fix",
"lint": "yarn eslint",
"lint-fix": "yarn lint --fix",
"lint": "eslint .",
"mutation-test": "stryker run",
"precommit": "lint-staged",
"prepublishOnly": "yarn && yarn build",
Expand Down Expand Up @@ -85,6 +83,7 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.16.2",
"@eslint/js": "^9.10.0",
"@graphql-tools/schema": "^10.0.0",
"@stryker-mutator/core": "^7.1.1",
"@stryker-mutator/jest-runner": "^7.1.1",
Expand All @@ -99,19 +98,20 @@
"@types/lodash.merge": "^4.6.7",
"@types/lodash.mergewith": "^4.6.7",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "6.7.0",
"@typescript-eslint/parser": "6.7.0",
"benchmark": "^2.1.4",
"codecov": "^3.8.2",
"compare-versions": "^6.1.1",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.9.0",
"graphql": "^16.8.0",
"jest": "^29.7.0",
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"tsup": "^8.2.4",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"typescript-eslint": "^8.5.0"
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
Expand Down
8 changes: 1 addition & 7 deletions src/__benchmarks__/benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ async function runBenchmarks() {
debug: true
} as any);
if (!isCompiledQuery(compiledQuery)) {
// eslint-disable-next-line no-console
console.error(`${bench} failed to compile`);
return null;
}
// eslint-disable-next-line no-console

console.log(
`size of function for ${bench}: ${
(compiledQuery as any)
Expand All @@ -84,7 +83,6 @@ async function runBenchmarks() {
if (
JSON.stringify(graphqlJitResult) !== JSON.stringify(graphqlJsResult)
) {
// eslint-disable-next-line no-console
console.error(
JSON.stringify(graphqlJitResult),
"is different of",
Expand Down Expand Up @@ -138,11 +136,9 @@ async function runBenchmarks() {
})
// add listeners
.on("cycle", (event: any) => {
// eslint-disable-next-line no-console
console.log(String(event.target));
})
.on("start", () => {
// eslint-disable-next-line no-console
console.log("Starting", bench);
});
return suite;
Expand All @@ -162,12 +158,10 @@ async function runBenchmarks() {
if (benchsToRun.length > 0) {
benchsToRun[0].run();
} else {
// eslint-disable-next-line
console.log("No benchmarks to run");
}
}

// eslint-disable-next-line
runBenchmarks().catch(console.error);

function isNotNull<T>(a: T | null | undefined): a is T {
Expand Down
1 change: 0 additions & 1 deletion src/__benchmarks__/profillable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ if (isCompiledQuery(compiled)) {
const now = Date.now();
let operations = 0;
const timelimit = getTimelimit();
// eslint-disable-next-line no-inner-declarations
function benchmark() {
if (Date.now() - now > timelimit) {
console.log(`Ran ${operations} operations in ${timelimit / 1000}s`);
Expand Down
8 changes: 0 additions & 8 deletions src/__tests__/abstract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function graphql(schema: GraphQLSchema, query: string) {
}

class Dog {
// eslint-disable-next-line no-useless-constructor
constructor(
public name: string,
public woofs: boolean,
Expand All @@ -34,22 +33,19 @@ class Dog {
}

class Cat {
// eslint-disable-next-line no-useless-constructor
constructor(
public name: string,
public meows: boolean
) {}
}

class Human {
// eslint-disable-next-line no-useless-constructor
constructor(
public name: string,
public pets?: any
) {}
}

// eslint-disable-next-line
describe("Execute: Handles execution of abstract types", () => {
test("isTypeOf used to resolve runtime type for Interface", () => {
const PetType = new GraphQLInterfaceType({
Expand Down Expand Up @@ -319,7 +315,6 @@ describe("Execute: Handles execution of abstract types", () => {

const PetType = new GraphQLUnionType({
name: "Pet",
// eslint-disable-next-line
resolveType(obj) {
return obj instanceof Dog
? DogType.toString()
Expand All @@ -338,7 +333,6 @@ describe("Execute: Handles execution of abstract types", () => {
fields: {
pets: {
type: new GraphQLList(PetType),
// eslint-disable-next-line
resolve() {
return [
new Dog("Odie", true),
Expand Down Expand Up @@ -545,7 +539,6 @@ describe("Execute: Handles execution of abstract types", () => {
friend: {
type: new GraphQLUnionType({
name: "DogFriend",
// eslint-disable-next-line
resolveType(obj) {
return obj instanceof Dog
? DogType.toString()
Expand All @@ -569,7 +562,6 @@ describe("Execute: Handles execution of abstract types", () => {

const PetType = new GraphQLUnionType({
name: "Pet",
// eslint-disable-next-line
resolveType(obj) {
return obj instanceof Dog
? DogType.toString()
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/alias.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-lines-per-function */
import {
DocumentNode,
GraphQLBoolean,
Expand Down
4 changes: 0 additions & 4 deletions src/__tests__/directives.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function executeTestQuery(
return compiled.query(data, undefined, variables);
}

// eslint-disable-next-line
describe("Execute: handles directives", () => {
describe("works without directives", () => {
test("basic query works", () => {
Expand All @@ -66,7 +65,6 @@ describe("Execute: handles directives", () => {
});

describe("works on scalars", () => {
// eslint-disable-next-line
test("if true includes scalar", () => {
const result = executeTestQuery("{ a, b @include(if: true) }");

Expand All @@ -83,7 +81,6 @@ describe("Execute: handles directives", () => {
});
});

// eslint-disable-next-line
test("unless false includes scalar", () => {
const result = executeTestQuery("{ a, b @skip(if: false) }");

Expand All @@ -92,7 +89,6 @@ describe("Execute: handles directives", () => {
});
});

// eslint-disable-next-line
test("unless true omits scalar", () => {
const result = executeTestQuery("{ a, b @skip(if: true) }");

Expand Down
10 changes: 1 addition & 9 deletions src/__tests__/execution.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prefer-promise-reject-errors */
/**
* Based on https://github.com/graphql/graphql-js/blob/master/src/execution/__tests__/execution-test.js
*/
Expand Down Expand Up @@ -371,7 +370,7 @@ describe("Execute: Handles basic execution tasks", () => {
},
syncRawError() {
// eslint-disable-next-line no-throw-literal
throw new Error("Error getting syncRawError");
throw "Error getting syncRawError";
},
syncReturnError() {
return new Error("Error getting syncReturnError");
Expand Down Expand Up @@ -401,12 +400,9 @@ describe("Execute: Handles basic execution tasks", () => {
throw new Error("Error getting asyncError");
});
},
// eslint-disable-next-line
asyncRawError() {
return new Promise(() => {
/* eslint-disable */
throw new Error("Error getting asyncRawError");
/* eslint-enable */
});
},
asyncReturnError() {
Expand Down Expand Up @@ -727,7 +723,6 @@ describe("Execute: Handles basic execution tasks", () => {
expect(result).toEqual({ data: { a: "b" } });
});

// eslint-disable-next-line
test("uses the only operation if no operation name is provided", async () => {
const doc = "query Example { a }";
const data = { a: "b" };
Expand Down Expand Up @@ -789,7 +784,6 @@ describe("Execute: Handles basic execution tasks", () => {
});
});

// eslint-disable-next-line
test("errors if no op name is provided with multiple operations", async () => {
const doc = "query Example { a } query OtherExample { a }";
const data = { a: "b" };
Expand Down Expand Up @@ -1090,12 +1084,10 @@ describe("Execute: Handles basic execution tasks", () => {

it("fails when an isTypeOf check is not met", async () => {
class Special {
// eslint-disable-next-line no-useless-constructor
constructor(public value: any) {}
}

class NotSpecial {
// eslint-disable-next-line no-useless-constructor
constructor(public value: any) {}
}

Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/lists.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prefer-promise-reject-errors */
/**
* Based on https://github.com/graphql/graphql-js/blob/master/src/execution/__tests__/lists-test.js
*/
Expand Down Expand Up @@ -118,7 +117,6 @@ describe("Execute: Accepts any iterable as list value", () => {
const containsValues = "Contains values";
const containsNull = "Contains null";

// eslint-disable-next-line
describe("Execute: Handles list nullability", () => {
describe("[T]", () => {
const type = new GraphQLList(GraphQLInt);
Expand Down Expand Up @@ -277,7 +275,6 @@ describe("Execute: Handles list nullability", () => {
);
});

// eslint-disable-next-line
describe("Array<Promise<T>>", () => {
test(
containsValues,
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/nonnull.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ function patch(data: any) {
);
}

// eslint-disable-next-line
async function executeSyncAndAsync(query: string, rootValue: any) {
const syncResult = await executeQuery(query, rootValue);
const asyncResult = await executeQuery(patch(query), rootValue);
Expand All @@ -186,7 +185,6 @@ async function executeSyncAndAsync(query: string, rootValue: any) {
return syncResult;
}

// eslint-disable-next-line
describe("Execute: handles non-nullable types", () => {
describe("nulls a nullable field", () => {
const query = `
Expand Down
Loading
Loading