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

Fix and improve eslint config, other minor changes #1795

Merged
merged 4 commits into from
Dec 27, 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
50 changes: 23 additions & 27 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,31 @@ const vitest = require("@vitest/eslint-plugin");
const globals = require("globals");
const prettier = require("eslint-config-prettier");

/** @type {import("eslint").Linter.Config[]} */
module.exports = [
module.exports = tseslint.config([
{ ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"] },
eslint.configs.recommended,
{
ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"],
files: ["**/*.js"],
languageOptions: { sourceType: "commonjs", globals: globals.node },
},
// Standard linting for js files
// TSDoc
{
files: ["**/*.js"],
languageOptions: { sourceType: "script", globals: globals.node },
plugins: { eslint },
rules: eslint.configs.recommended.rules,
files: ["src/**/*.ts"],
plugins: { tsdoc },
rules: { "tsdoc/syntax": "error" },
},
// TypeScript linting for ts files
...tseslint.configs.recommendedTypeChecked.map((config) => ({
...config,
// TypeScript
{
files: ["**/*.ts"],
extends: [tseslint.configs.recommendedTypeChecked],
languageOptions: {
...config.languageOptions,
globals: { ...config.languageOptions?.globals, ...globals.node },
parserOptions: {
...config.languageOptions?.parserOptions,
project: "tsconfig.eslint.json",
projectService: true,
tsconfigRootDir: __dirname,
},
},
plugins: { ...config.plugins, tsdoc },
rules: {
...config.rules,
"tsdoc/syntax": "error",
// @TODO: Remove the ones between "~~", adapt code
// TODO: Remove the ones between "~~", adapt code
// ~~
"@typescript-eslint/prefer-as-const": "off",
"@typescript-eslint/ban-ts-comment": "off",
Expand All @@ -45,7 +41,7 @@ module.exports = [
"@typescript-eslint/no-floating-promises": "off",
// ~~
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
// @TODO: Should be careful with this rule, should leave it be and disable
// TODO: Should be careful with this rule, should leave it be and disable
// it within files where necessary with explanations
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
Expand All @@ -54,16 +50,16 @@ module.exports = [
// varsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#varsignorepattern
{ args: "all", argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
// @TODO: Not recommended to disable rule, should instead disable locally
// TODO: Not recommended to disable rule, should instead disable locally
// with explanation
"@typescript-eslint/ban-ts-ignore": "off",
},
})),
// Vitest linting for test files
},
// Vitest
{
files: ["tests/*.ts"],
plugins: { vitest },
rules: vitest.configs.recommended.rules,
files: ["tests/**/*.test.ts"],
extends: [vitest.configs.recommended],
},
// Disable any style linting, as prettier takes care of that separately
prettier,
];
]);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
"style:fix": "yarn fmt:fix && yarn lint:fix",
"fmt": "prettier -c ./**/*.{js,ts}",
"fmt:fix": "prettier -w ./**/*.{js,ts}",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"lint": "eslint",
"lint:fix": "eslint --fix",
"typingsheader": "node scripts/build.js"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PLUGINS = [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: { allowJs: false },
tsconfig: "tsconfig.build.json",
include: ["src"],
exclude: ["tests", "examples", "*.js", "scripts"],
},
Expand Down
2 changes: 1 addition & 1 deletion tests/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Test on updates", () => {
const client = new MeiliSearch({ host: "http://localhost:9345" });
try {
await client.health();
} catch (error) {
} catch (error: any) {
expect(error.name).toEqual("MeiliSearchRequestError");
}
});
Expand Down
28 changes: 19 additions & 9 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
afterAll,
beforeAll,
} from "vitest";
import { ErrorStatusCode, MatchingStrategies } from "../src/types";
import {
ErrorStatusCode,
FederatedMultiSearchParams,
MatchingStrategies,
MultiSearchParams,
} from "../src/types";
import { EnqueuedTask } from "../src/enqueued-task";
import {
clearAllIndexes,
Expand All @@ -19,11 +24,6 @@ import {
getKey,
} from "./utils/meilisearch-test-utils";

if (typeof fetch === "undefined") {
flevi29 marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/no-require-imports
require("cross-fetch/polyfill");
}

const index = {
uid: "books",
};
Expand Down Expand Up @@ -180,7 +180,10 @@ describe.each([
id: 1;
};

const response = await client.multiSearch<MyIndex & Books>({
const response = await client.multiSearch<
MultiSearchParams,
MyIndex & Books
>({
queries: [{ indexUid: index.uid, q: "prince" }],
});

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

const response1 = await client.multiSearch<
FederatedMultiSearchParams,
Books | { id: number; asd: string }
>({
federation: {},
Expand Down Expand Up @@ -251,7 +255,10 @@ describe.each([
await masterClient.waitForTask(task2);

// Make a multi search on both indexes with facetsByIndex
const response = await client.multiSearch<Books | Movies>({
const response = await client.multiSearch<
FederatedMultiSearchParams,
Books | Movies
>({
federation: {
limit: 20,
offset: 0,
Expand Down Expand Up @@ -329,7 +336,10 @@ describe.each([
await masterClient.waitForTask(task2);

// Make a multi search on both indexes with mergeFacets
const response = await client.multiSearch<Books | Movies>({
const response = await client.multiSearch<
FederatedMultiSearchParams,
Books | Movies
>({
federation: {
limit: 20,
offset: 0,
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src/**/*.ts"]
}
15 changes: 0 additions & 15 deletions tsconfig.eslint.json

This file was deleted.

3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@
"lib": ["ESNext", "dom"],
"strict": true,
"noImplicitReturns": true
},
"include": ["src"]
}
}
Loading