Skip to content

Commit

Permalink
ESLint 9 from the scratch (#1767)
Browse files Browse the repository at this point in the history
Alternative to #1631
  • Loading branch information
RobinTail authored May 23, 2024
1 parent 964fca0 commit 78a2de5
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 865 deletions.
43 changes: 0 additions & 43 deletions .eslintrc.json

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

62 changes: 62 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import globals from "globals";
import jsPlugin from "@eslint/js";
import tsPlugin from "typescript-eslint";
import prettierOverrides from "eslint-config-prettier";
import prettierRules from "eslint-plugin-prettier/recommended";
import unicornPlugin from "eslint-plugin-unicorn";
import importPlugin from "eslint-plugin-import-x";

export default [
{
languageOptions: { globals: globals.node },
plugins: {
unicorn: unicornPlugin,
"import-x": importPlugin,
},
},
jsPlugin.configs.recommended,
...tsPlugin.configs.recommended,
prettierOverrides,
prettierRules,
// Things to turn off
{ ignores: ["dist/", "coverage/"] },
{
rules: {
"no-empty": ["error", { allowEmptyCatch: true }],
"no-empty-pattern": ["error", { allowObjectPatternsAsParameters: true }],
"@typescript-eslint/no-empty-object-type": "off", // @todo remove
"@typescript-eslint/no-explicit-any": "off", // @todo remove
},
},
// Things to turn on globally
{
rules: {
"unicorn/prefer-node-protocol": "error",
"import-x/named": "error",
"import-x/export": "error",
"import-x/no-duplicates": "warn",
},
},
// For the sources
{
files: ["src/*.ts"],
rules: {
"import-x/no-extraneous-dependencies": "error",
},
},
// Special needs of plugin
{
files: ["src/zod-plugin.ts"],
rules: {
"@typescript-eslint/no-unused-vars": "off",
},
},
// Special needs of the generated code
{
files: ["tests/*/quick-start.ts"],
rules: {
"prettier/prettier": "off",
"import-x/no-duplicates": "off",
},
},
];
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test:952": "yarn --cwd tests/issue952 && yarn --cwd tests/issue952 test",
"test:compat": "yarn --cwd tests/compat && yarn --cwd tests/compat test",
"bench": "vitest bench --run tests/bench",
"lint": "eslint src example tests tools && yarn prettier *.md --check",
"lint": "eslint && yarn prettier *.md --check",
"mdfix": "prettier *.md --write",
"cleanup": "rm -rf tests/**/node_modules coverage",
"precommit": "yarn lint && yarn test && yarn build && git add example/example.* LICENSE coverage.svg",
Expand Down Expand Up @@ -124,6 +124,7 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.0",
"@eslint/js": "^9.3.0",
"@tsconfig/node18": "^18.2.1",
"@types/compression": "^1.7.5",
"@types/cors": "^2.8.14",
Expand All @@ -134,20 +135,17 @@
"@types/ramda": "^0.30.0",
"@types/swagger-ui-express": "^4.1.6",
"@types/triple-beam": "^1.3.2",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@vitest/coverage-istanbul": "^1.5.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"eslint": "^8.48.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint": "^9.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import-x": "^0.5.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^53.0.0",
"express": "^4.19.2",
"express-fileupload": "^1.5.0",
"globals": "^15.3.0",
"http-errors": "^2.0.0",
"husky": "^9.0.5",
"make-coverage-badge": "^1.2.0",
Expand All @@ -158,9 +156,13 @@
"tsup": "^8.0.0",
"tsx": "^4.6.2",
"typescript": "^5.2.2",
"typescript-eslint": "^8.0.0-alpha.14",
"vitest": "^1.5.0",
"zod": "^3.23.0"
},
"resolutions": {
"**/@typescript-eslint/utils": "^8.0.0-alpha.14"
},
"keywords": [
"nodejs",
"api",
Expand Down
2 changes: 1 addition & 1 deletion src/common-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const tryToTransform = <T>(
) => {
try {
return typeof schema.parse(sample);
} catch (e) {
} catch {
return undefined;
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/documentation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ import { HandlingRules, SchemaHandler, walkSchema } from "./schema-walker";
import { Security } from "./security";
import { UploadSchema, ezUploadBrand } from "./upload-schema";

/* eslint-disable @typescript-eslint/no-use-before-define */

export interface OpenAPIContext extends FlatObject {
isResponse: boolean;
serializer: (schema: z.ZodTypeAny) => string;
Expand Down
2 changes: 0 additions & 2 deletions src/zod-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* @desc Enables .label() on ZodDefault
* @desc Stores the argument supplied to .brand() on all schema (runtime distinguishable branded types)
* */
/* eslint-disable @typescript-eslint/no-unused-vars */

import { clone } from "ramda";
import { z } from "zod";
import { Metadata, cloneSchema, metaSymbol } from "./metadata";
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const givePort = (test?: keyof typeof reservedPorts) => {
export const waitFor = async (cb: () => boolean) =>
new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
clearInterval(timer); // eslint-disable-line @typescript-eslint/no-use-before-define
clearInterval(timer);
reject();
}, 10000);
const timer = setInterval(() => {
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/endpoints-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { z } from "zod";
import { describe, expect, test, vi } from "vitest";

describe("EndpointsFactory", () => {
/* eslint-disable @typescript-eslint/dot-notation */

describe(".constructor()", () => {
test("Should create the empty factory with result handler", () => {
const resultHandlerMock = createResultHandler({
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/result-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import createHttpError from "http-errors";
import { expectType } from "tsd";
import { z } from "zod";
import {
ApiResponse,
InputValidationError,
arrayResultHandler,
createResultHandler,
defaultResultHandler,
} from "../../src";
import { ApiResponse } from "../../src";
import { metaSymbol } from "../../src/metadata";
import { describe, expect, test, vi } from "vitest";
import {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/routing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
import { z } from "zod";
import {
DependsOnMethod,
CommonConfig,
EndpointsFactory,
Routing,
ServeStatic,
createLogger,
defaultEndpointsFactory,
defaultResultHandler,
} from "../../src";
import { CommonConfig } from "../../src";
import {
makeLoggerMock,
makeRequestMock,
Expand Down
Loading

0 comments on commit 78a2de5

Please sign in to comment.