Skip to content

Commit 47fcb09

Browse files
meili-bors[bot]flevi29Strift
authored
Merge #1795
1795: Fix and improve `eslint` config, other minor changes r=Strift a=flevi29 # Pull Request ## What does this PR do? - `eslint` config was set up in a confusing way, now it's simplified and works as it should - `typescript` didn't check test files, now it does ## 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]> Co-authored-by: Laurent Cazanove <[email protected]>
2 parents d8ef010 + 8353590 commit 47fcb09

File tree

8 files changed

+51
-57
lines changed

8 files changed

+51
-57
lines changed

eslint.config.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,31 @@ const vitest = require("@vitest/eslint-plugin");
55
const globals = require("globals");
66
const prettier = require("eslint-config-prettier");
77

8-
/** @type {import("eslint").Linter.Config[]} */
9-
module.exports = [
8+
module.exports = tseslint.config([
9+
{ ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"] },
10+
eslint.configs.recommended,
1011
{
11-
ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"],
12+
files: ["**/*.js"],
13+
languageOptions: { sourceType: "commonjs", globals: globals.node },
1214
},
13-
// Standard linting for js files
15+
// TSDoc
1416
{
15-
files: ["**/*.js"],
16-
languageOptions: { sourceType: "script", globals: globals.node },
17-
plugins: { eslint },
18-
rules: eslint.configs.recommended.rules,
17+
files: ["src/**/*.ts"],
18+
plugins: { tsdoc },
19+
rules: { "tsdoc/syntax": "error" },
1920
},
20-
// TypeScript linting for ts files
21-
...tseslint.configs.recommendedTypeChecked.map((config) => ({
22-
...config,
21+
// TypeScript
22+
{
2323
files: ["**/*.ts"],
24+
extends: [tseslint.configs.recommendedTypeChecked],
2425
languageOptions: {
25-
...config.languageOptions,
26-
globals: { ...config.languageOptions?.globals, ...globals.node },
2726
parserOptions: {
28-
...config.languageOptions?.parserOptions,
29-
project: "tsconfig.eslint.json",
27+
projectService: true,
28+
tsconfigRootDir: __dirname,
3029
},
3130
},
32-
plugins: { ...config.plugins, tsdoc },
3331
rules: {
34-
...config.rules,
35-
"tsdoc/syntax": "error",
36-
// @TODO: Remove the ones between "~~", adapt code
32+
// TODO: Remove the ones between "~~", adapt code
3733
// ~~
3834
"@typescript-eslint/prefer-as-const": "off",
3935
"@typescript-eslint/ban-ts-comment": "off",
@@ -45,7 +41,7 @@ module.exports = [
4541
"@typescript-eslint/no-floating-promises": "off",
4642
// ~~
4743
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
48-
// @TODO: Should be careful with this rule, should leave it be and disable
44+
// TODO: Should be careful with this rule, should leave it be and disable
4945
// it within files where necessary with explanations
5046
"@typescript-eslint/no-explicit-any": "off",
5147
"@typescript-eslint/no-unused-vars": [
@@ -54,16 +50,16 @@ module.exports = [
5450
// varsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#varsignorepattern
5551
{ args: "all", argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
5652
],
57-
// @TODO: Not recommended to disable rule, should instead disable locally
53+
// TODO: Not recommended to disable rule, should instead disable locally
5854
// with explanation
5955
"@typescript-eslint/ban-ts-ignore": "off",
6056
},
61-
})),
62-
// Vitest linting for test files
57+
},
58+
// Vitest
6359
{
64-
files: ["tests/*.ts"],
65-
plugins: { vitest },
66-
rules: vitest.configs.recommended.rules,
60+
files: ["tests/**/*.test.ts"],
61+
extends: [vitest.configs.recommended],
6762
},
63+
// Disable any style linting, as prettier takes care of that separately
6864
prettier,
69-
];
65+
]);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
"style:fix": "yarn fmt:fix && yarn lint:fix",
6767
"fmt": "prettier -c ./**/*.{js,ts}",
6868
"fmt:fix": "prettier -w ./**/*.{js,ts}",
69-
"lint": "eslint .",
70-
"lint:fix": "eslint --fix .",
69+
"lint": "eslint",
70+
"lint:fix": "eslint --fix",
7171
"typingsheader": "node scripts/build.js"
7272
},
7373
"files": [

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const PLUGINS = [
1818
typescript({
1919
useTsconfigDeclarationDir: true,
2020
tsconfigOverride: {
21-
compilerOptions: { allowJs: false },
21+
tsconfig: "tsconfig.build.json",
2222
include: ["src"],
2323
exclude: ["tests", "examples", "*.js", "scripts"],
2424
},

tests/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("Test on updates", () => {
2121
const client = new MeiliSearch({ host: "http://localhost:9345" });
2222
try {
2323
await client.health();
24-
} catch (error) {
24+
} catch (error: any) {
2525
expect(error.name).toEqual("MeiliSearchRequestError");
2626
}
2727
});

tests/search.test.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {
66
afterAll,
77
beforeAll,
88
} from "vitest";
9-
import { ErrorStatusCode, MatchingStrategies } from "../src/types";
9+
import {
10+
ErrorStatusCode,
11+
FederatedMultiSearchParams,
12+
MatchingStrategies,
13+
MultiSearchParams,
14+
} from "../src/types";
1015
import { EnqueuedTask } from "../src/enqueued-task";
1116
import {
1217
clearAllIndexes,
@@ -19,11 +24,6 @@ import {
1924
getKey,
2025
} from "./utils/meilisearch-test-utils";
2126

22-
if (typeof fetch === "undefined") {
23-
// eslint-disable-next-line @typescript-eslint/no-require-imports
24-
require("cross-fetch/polyfill");
25-
}
26-
2727
const index = {
2828
uid: "books",
2929
};
@@ -180,7 +180,10 @@ describe.each([
180180
id: 1;
181181
};
182182

183-
const response = await client.multiSearch<MyIndex & Books>({
183+
const response = await client.multiSearch<
184+
MultiSearchParams,
185+
MyIndex & Books
186+
>({
184187
queries: [{ indexUid: index.uid, q: "prince" }],
185188
});
186189

@@ -193,6 +196,7 @@ describe.each([
193196
const client = await getClient(permission);
194197

195198
const response1 = await client.multiSearch<
199+
FederatedMultiSearchParams,
196200
Books | { id: number; asd: string }
197201
>({
198202
federation: {},
@@ -251,7 +255,10 @@ describe.each([
251255
await masterClient.waitForTask(task2);
252256

253257
// Make a multi search on both indexes with facetsByIndex
254-
const response = await client.multiSearch<Books | Movies>({
258+
const response = await client.multiSearch<
259+
FederatedMultiSearchParams,
260+
Books | Movies
261+
>({
255262
federation: {
256263
limit: 20,
257264
offset: 0,
@@ -329,7 +336,10 @@ describe.each([
329336
await masterClient.waitForTask(task2);
330337

331338
// Make a multi search on both indexes with mergeFacets
332-
const response = await client.multiSearch<Books | Movies>({
339+
const response = await client.multiSearch<
340+
FederatedMultiSearchParams,
341+
Books | Movies
342+
>({
333343
federation: {
334344
limit: 20,
335345
offset: 0,

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": ["src/**/*.ts"]
4+
}

tsconfig.eslint.json

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

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@
2525
"lib": ["ESNext", "dom"],
2626
"strict": true,
2727
"noImplicitReturns": true
28-
},
29-
"include": ["src"]
28+
}
3029
}

0 commit comments

Comments
 (0)