Skip to content

Commit

Permalink
Merge #1697
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and flevi29 authored Oct 2, 2024
2 parents 3b7e7e4 + aab1044 commit efbaa33
Show file tree
Hide file tree
Showing 9 changed files with 446 additions and 331 deletions.
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

84 changes: 84 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const eslint = require("@eslint/js");
const tseslint = require("typescript-eslint");
const tsdoc = require("eslint-plugin-tsdoc");
const jest = require("eslint-plugin-jest");
const globals = require("globals");
const prettier = require("eslint-config-prettier");

/** @type {import("eslint").Linter.Config[]} */
module.exports = [
{
ignores: ["dist/", "tests/env/", "coverage/", "playgrounds/", "docs/"],
},
// Standard linting for js files
{
files: ["**/*.js"],
languageOptions: { sourceType: "script", globals: globals.node },
plugins: { eslint },
rules: eslint.configs.recommended.rules,
},
// TypeScript linting for ts files
...tseslint.configs.recommendedTypeChecked.map((config) => ({
...config,
files: ["**/*.ts"],
languageOptions: {
...config.languageOptions,
globals: { ...config.languageOptions?.globals, ...globals.node },
parserOptions: {
...config.languageOptions?.parserOptions,
project: "tsconfig.eslint.json",
},
},
plugins: { ...config.plugins, tsdoc },
rules: {
...config.rules,
"tsdoc/syntax": "error",
// @TODO: Remove the ones between "~~", adapt code
// ~~
"@typescript-eslint/prefer-as-const": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@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
// it within files where necessary with explanations
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": [
"error",
// argsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#argsignorepattern
// 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
// with explanation
"@typescript-eslint/ban-ts-ignore": "off",
},
})),
// Jest linting for test files
{
files: ["tests/*.ts"],
...jest.configs["flat/recommended"],
// languageOptions: {
// ...jest.configs['flat/recommended'].languageOptions,
// globals: globals.jest,
// },
rules: {
...jest.configs["flat/recommended"].rules,
// @TODO: Remove all of these rules and adapt code!
"jest/no-disabled-tests": "off",
"jest/expect-expect": "off",
"jest/no-conditional-expect": "off",
"jest/valid-title": "off",
"jest/no-jasmine-globals": "off",
"jest/valid-expect-in-promise": "off",
"jest/valid-expect": "off",
"jest/no-alias-methods": "off",
},
},
prettier,
];
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"style:fix": "yarn fmt:fix && yarn lint:fix",
"fmt": "prettier -c ./**/*.{js,ts}",
"fmt:fix": "prettier -w ./**/*.{js,ts}",
"lint": "eslint --ext .js,.ts,.tsx .",
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"typingsheader": "node scripts/build.js"
},
"files": [
Expand All @@ -75,18 +75,19 @@
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.4",
"@eslint/js": "^9.11.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "28.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "15.3.0",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.11",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"brotli-size": "^4.0.0",
"eslint": "^8.56.0",
"eslint": "^9.11.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-tsdoc": "^0.2.17",
"eslint-plugin-jest": "^28.8.0",
"eslint-plugin-tsdoc": "^0.3.0",
"globals": "^15.9.0",
"gzip-size": "^6.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Expand All @@ -104,7 +105,8 @@
"shx": "^0.3.2",
"ts-jest": "^29.2.5",
"typedoc": "^0.26.7",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"typescript-eslint": "^8.8.0"
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion src/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ class Client {
const url = `health`;
await this.httpRequest.get(url);
return true;
} catch (e: any) {
} catch {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/http-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function constructHostURL(host: string): string {
host = addProtocolIfNotPresent(host);
host = addTrailingSlash(host);
return host;
} catch (e) {
} catch {
throw new MeiliSearchError("The provided host is not valid.");
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ class HttpRequests {
try {
const host = constructHostURL(config.host);
this.url = new URL(host);
} catch (e) {
} catch {
throw new MeiliSearchError("The provided host is not valid.");
}
}
Expand Down
16 changes: 2 additions & 14 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export type Pagination = {
limit?: number;
};

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

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

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

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

/*
Expand Down Expand Up @@ -529,11 +523,9 @@ export type TasksQuery = {
limit?: number;
from?: number;
};
// TODO fix
// eslint-disable-next-line @typescript-eslint/ban-types

export type CancelTasksQuery = Omit<TasksQuery, "limit" | "from"> & {};
// TODO fix
// eslint-disable-next-line @typescript-eslint/ban-types

export type DeleteTasksQuery = Omit<TasksQuery, "limit" | "from"> & {};

export type EnqueuedTaskObject = {
Expand Down Expand Up @@ -684,12 +676,8 @@ export type KeyUpdate = {
description?: string;
};

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

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

/*
Expand Down
1 change: 1 addition & 0 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "./utils/meilisearch-test-utils";

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

Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"compilerOptions": {
// We don't want to check node_modules
"skipLibCheck": true,
// @TODO: perhaps "emitDeclarationOnly" should be used here (build fails with it), need to
// investigate further https://www.typescriptlang.org/tsconfig#emitDeclarationOnly
// probably need to update rollup and its config
Expand All @@ -22,7 +24,7 @@
"target": "es2022",
"lib": ["ESNext", "dom"],
"strict": true,
"noImplicitReturns": true,
"noImplicitReturns": true
},
"include": ["src"],
"include": ["src"]
}
Loading

0 comments on commit efbaa33

Please sign in to comment.