Skip to content

Commit efbaa33

Browse files
Merge #1697
1697: Update ESLint and related packages r=curquiza a=flevi29 # Pull Request ## Why? ESLint received major upgrade from 8 -> 9. With this comes a new flat config. Also rules have been changed a little bit. This PR updates ESLint, related packages, and adapts config. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: F. Levi <[email protected]>
2 parents 3b7e7e4 + aab1044 commit efbaa33

File tree

9 files changed

+446
-331
lines changed

9 files changed

+446
-331
lines changed

.eslintignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

eslint.config.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const eslint = require("@eslint/js");
2+
const tseslint = require("typescript-eslint");
3+
const tsdoc = require("eslint-plugin-tsdoc");
4+
const jest = require("eslint-plugin-jest");
5+
const globals = require("globals");
6+
const prettier = require("eslint-config-prettier");
7+
8+
/** @type {import("eslint").Linter.Config[]} */
9+
module.exports = [
10+
{
11+
ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"],
12+
},
13+
// Standard linting for js files
14+
{
15+
files: ["**/*.js"],
16+
languageOptions: { sourceType: "script", globals: globals.node },
17+
plugins: { eslint },
18+
rules: eslint.configs.recommended.rules,
19+
},
20+
// TypeScript linting for ts files
21+
...tseslint.configs.recommendedTypeChecked.map((config) => ({
22+
...config,
23+
files: ["**/*.ts"],
24+
languageOptions: {
25+
...config.languageOptions,
26+
globals: { ...config.languageOptions?.globals, ...globals.node },
27+
parserOptions: {
28+
...config.languageOptions?.parserOptions,
29+
project: "tsconfig.eslint.json",
30+
},
31+
},
32+
plugins: { ...config.plugins, tsdoc },
33+
rules: {
34+
...config.rules,
35+
"tsdoc/syntax": "error",
36+
// @TODO: Remove the ones between "~~", adapt code
37+
// ~~
38+
"@typescript-eslint/prefer-as-const": "off",
39+
"@typescript-eslint/ban-ts-comment": "off",
40+
"@typescript-eslint/no-unsafe-call": "off",
41+
"@typescript-eslint/no-unsafe-member-access": "off",
42+
"@typescript-eslint/no-unsafe-return": "off",
43+
"@typescript-eslint/no-unsafe-assignment": "off",
44+
"@typescript-eslint/no-unsafe-argument": "off",
45+
"@typescript-eslint/no-floating-promises": "off",
46+
// ~~
47+
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
48+
// @TODO: Should be careful with this rule, should leave it be and disable
49+
// it within files where necessary with explanations
50+
"@typescript-eslint/no-explicit-any": "off",
51+
"@typescript-eslint/no-unused-vars": [
52+
"error",
53+
// argsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#argsignorepattern
54+
// varsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#varsignorepattern
55+
{ args: "all", argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
56+
],
57+
// @TODO: Not recommended to disable rule, should instead disable locally
58+
// with explanation
59+
"@typescript-eslint/ban-ts-ignore": "off",
60+
},
61+
})),
62+
// Jest linting for test files
63+
{
64+
files: ["tests/*.ts"],
65+
...jest.configs["flat/recommended"],
66+
// languageOptions: {
67+
// ...jest.configs['flat/recommended'].languageOptions,
68+
// globals: globals.jest,
69+
// },
70+
rules: {
71+
...jest.configs["flat/recommended"].rules,
72+
// @TODO: Remove all of these rules and adapt code!
73+
"jest/no-disabled-tests": "off",
74+
"jest/expect-expect": "off",
75+
"jest/no-conditional-expect": "off",
76+
"jest/valid-title": "off",
77+
"jest/no-jasmine-globals": "off",
78+
"jest/valid-expect-in-promise": "off",
79+
"jest/valid-expect": "off",
80+
"jest/no-alias-methods": "off",
81+
},
82+
},
83+
prettier,
84+
];

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"style:fix": "yarn fmt:fix && yarn lint:fix",
5454
"fmt": "prettier -c ./**/*.{js,ts}",
5555
"fmt:fix": "prettier -w ./**/*.{js,ts}",
56-
"lint": "eslint --ext .js,.ts,.tsx .",
57-
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
56+
"lint": "eslint .",
57+
"lint:fix": "eslint --fix .",
5858
"typingsheader": "node scripts/build.js"
5959
},
6060
"files": [
@@ -75,18 +75,19 @@
7575
"devDependencies": {
7676
"@babel/core": "^7.25.2",
7777
"@babel/preset-env": "^7.25.4",
78+
"@eslint/js": "^9.11.1",
7879
"@rollup/plugin-babel": "^6.0.4",
7980
"@rollup/plugin-commonjs": "28.0.0",
8081
"@rollup/plugin-json": "^6.1.0",
8182
"@rollup/plugin-node-resolve": "15.3.0",
83+
"@types/eslint__js": "^8.42.3",
8284
"@types/jest": "^29.5.11",
83-
"@typescript-eslint/eslint-plugin": "^6.19.0",
84-
"@typescript-eslint/parser": "^6.19.0",
8585
"brotli-size": "^4.0.0",
86-
"eslint": "^8.56.0",
86+
"eslint": "^9.11.1",
8787
"eslint-config-prettier": "^9.1.0",
88-
"eslint-plugin-jest": "^27.6.3",
89-
"eslint-plugin-tsdoc": "^0.2.17",
88+
"eslint-plugin-jest": "^28.8.0",
89+
"eslint-plugin-tsdoc": "^0.3.0",
90+
"globals": "^15.9.0",
9091
"gzip-size": "^6.0.0",
9192
"jest": "^29.7.0",
9293
"jest-environment-jsdom": "^29.7.0",
@@ -104,7 +105,8 @@
104105
"shx": "^0.3.2",
105106
"ts-jest": "^29.2.5",
106107
"typedoc": "^0.26.7",
107-
"typescript": "^5.4.5"
108+
"typescript": "^5.4.5",
109+
"typescript-eslint": "^8.8.0"
108110
},
109111
"packageManager": "[email protected]"
110112
}

src/clients/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class Client {
403403
const url = `health`;
404404
await this.httpRequest.get(url);
405405
return true;
406-
} catch (e: any) {
406+
} catch {
407407
return false;
408408
}
409409
}

src/http-requests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function constructHostURL(host: string): string {
3333
host = addProtocolIfNotPresent(host);
3434
host = addTrailingSlash(host);
3535
return host;
36-
} catch (e) {
36+
} catch {
3737
throw new MeiliSearchError("The provided host is not valid.");
3838
}
3939
}
@@ -105,7 +105,7 @@ class HttpRequests {
105105
try {
106106
const host = constructHostURL(config.host);
107107
this.url = new URL(host);
108-
} catch (e) {
108+
} catch {
109109
throw new MeiliSearchError("The provided host is not valid.");
110110
}
111111
}

src/types/types.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export type Pagination = {
2424
limit?: number;
2525
};
2626

27-
// TODO fix
28-
// eslint-disable-next-line @typescript-eslint/ban-types
2927
export type ResourceQuery = Pagination & {};
3028

3129
export type ResourceResults<T> = Pagination & {
@@ -48,12 +46,8 @@ export type IndexObject = {
4846
updatedAt: Date;
4947
};
5048

51-
// TODO fix
52-
// eslint-disable-next-line @typescript-eslint/ban-types
5349
export type IndexesQuery = ResourceQuery & {};
5450

55-
// TODO fix
56-
// eslint-disable-next-line @typescript-eslint/ban-types
5751
export type IndexesResults<T> = ResourceResults<T> & {};
5852

5953
/*
@@ -529,11 +523,9 @@ export type TasksQuery = {
529523
limit?: number;
530524
from?: number;
531525
};
532-
// TODO fix
533-
// eslint-disable-next-line @typescript-eslint/ban-types
526+
534527
export type CancelTasksQuery = Omit<TasksQuery, "limit" | "from"> & {};
535-
// TODO fix
536-
// eslint-disable-next-line @typescript-eslint/ban-types
528+
537529
export type DeleteTasksQuery = Omit<TasksQuery, "limit" | "from"> & {};
538530

539531
export type EnqueuedTaskObject = {
@@ -684,12 +676,8 @@ export type KeyUpdate = {
684676
description?: string;
685677
};
686678

687-
// TODO fix
688-
// eslint-disable-next-line @typescript-eslint/ban-types
689679
export type KeysQuery = ResourceQuery & {};
690680

691-
// TODO fix
692-
// eslint-disable-next-line @typescript-eslint/ban-types
693681
export type KeysResults = ResourceResults<Key[]> & {};
694682

695683
/*

tests/search.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "./utils/meilisearch-test-utils";
1313

1414
if (typeof fetch === "undefined") {
15+
// eslint-disable-next-line @typescript-eslint/no-require-imports
1516
require("cross-fetch/polyfill");
1617
}
1718

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"compilerOptions": {
3+
// We don't want to check node_modules
4+
"skipLibCheck": true,
35
// @TODO: perhaps "emitDeclarationOnly" should be used here (build fails with it), need to
46
// investigate further https://www.typescriptlang.org/tsconfig#emitDeclarationOnly
57
// probably need to update rollup and its config
@@ -22,7 +24,7 @@
2224
"target": "es2022",
2325
"lib": ["ESNext", "dom"],
2426
"strict": true,
25-
"noImplicitReturns": true,
27+
"noImplicitReturns": true
2628
},
27-
"include": ["src"],
29+
"include": ["src"]
2830
}

0 commit comments

Comments
 (0)