Skip to content

Commit 39a874f

Browse files
authored
Merge pull request #1616 from flevi29/improve-eslint-prettier-tsconfig
Update ESLint, Prettier, TypeScript and fix/improve their configuration files
2 parents d891f15 + 9759c35 commit 39a874f

File tree

14 files changed

+775
-1027
lines changed

14 files changed

+775
-1027
lines changed

.eslintignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
node_modules
22
dist
3-
examples
4-
scripts
5-
tests/env
6-
coverage
7-
/jest-disable-built-in-fetch.js
3+
/tests/env
4+
/coverage
5+
# @TODO: I'm not sure what's going on here, we're importing
6+
# in JS file from TS files, better left ignored for now
7+
/playgrounds

.eslintrc.js

Lines changed: 119 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,130 @@
1+
// https://eslint.org/docs/latest/use/configure/
2+
13
module.exports = {
4+
root: true,
25
env: {
6+
// @TODO: Can be removed, ES versions are cumulative:
7+
// https://stackoverflow.com/a/61688878
8+
// es6: true,
9+
// This seems to be what Node.js 18, 20 fully supports, but online documentation
10+
// isn't exactly crystal clear about what should be put here
11+
es2022: true,
312
browser: true,
4-
es6: true,
5-
es2020: true,
6-
'jest/globals': true,
713
node: true,
8-
jasmine: true,
914
},
15+
// Standard linting for pure javascript files
16+
parserOptions: {
17+
// @TODO: Can be removed, as env ES version sets this too:
18+
// https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
19+
// ecmaVersion: 2019,
20+
// @TODO: Remove because in JS files we use commonjs
21+
// sourceType: 'module',
22+
},
23+
// prettier must always be put last, so it overrides anything before it
1024
extends: [
1125
'eslint:recommended',
12-
'plugin:@typescript-eslint/recommended',
13-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
14-
'plugin:prettier/recommended',
26+
// Disables all style rules
27+
// https://prettier.io/docs/en/integrating-with-linters.html
28+
// https://github.com/prettier/eslint-config-prettier
29+
'prettier',
1530
],
16-
parser: '@typescript-eslint/parser',
17-
parserOptions: {
18-
ecmaVersion: 2019,
19-
project: ['tsconfig.eslint.json'],
20-
sourceType: 'module',
21-
projectFolderIgnoreList: ['dist'],
22-
},
23-
plugins: ['tsdoc', '@typescript-eslint', 'prettier', 'jest'],
2431
rules: {
25-
'no-dupe-class-members': 'off', // Off due to conflict with typescript overload functions
26-
'prettier/prettier': ['error', {}, { usePrettierrc: true }],
27-
'@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
28-
'@typescript-eslint/return-await': 'off',
29-
'tsdoc/syntax': 'error',
30-
'@typescript-eslint/space-before-function-paren': 0,
31-
'@typescript-eslint/no-explicit-any': 'off',
32-
'@typescript-eslint/explicit-function-return-type': 'off',
33-
'@typescript-eslint/no-throw-literal': 'off',
34-
'@typescript-eslint/no-unused-vars': [
35-
'error',
36-
// argsIgnorePattern: arguments whose names match a regexp pattern
37-
// varsIgnorePattern: variables whose names match a regexp pattern
38-
{ args: 'all', argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
39-
],
40-
'@typescript-eslint/member-delimiter-style': [
41-
'error',
42-
{
43-
multiline: {
44-
delimiter: 'none', // 'none' or 'semi' or 'comma'
45-
requireLast: true,
46-
},
47-
singleline: {
48-
delimiter: 'semi', // 'semi' or 'comma'
49-
requireLast: false,
50-
},
51-
},
52-
],
53-
'comma-dangle': 'off',
54-
'@typescript-eslint/ban-ts-ignore': 'off',
32+
// @TODO: Remove this rule, as it's a style rule covered by prettier and
33+
// it's deprecated https://eslint.org/docs/latest/rules/comma-dangle
34+
// 'comma-dangle': 'off',
5535
},
36+
overrides: [
37+
// TypeScript linting for TypeScript files
38+
{
39+
files: '*.ts',
40+
plugins: [
41+
'@typescript-eslint',
42+
// TSDoc is only meant for TS files https://tsdoc.org/
43+
'eslint-plugin-tsdoc',
44+
],
45+
parser: '@typescript-eslint/parser',
46+
parserOptions: { project: 'tsconfig.eslint.json' },
47+
// prettier must always be put last, so it overrides anything before it
48+
extends: [
49+
'plugin:@typescript-eslint/recommended-type-checked',
50+
'prettier',
51+
],
52+
rules: {
53+
// @TODO: Remove as it doesn't seem to cause issues anymore with fn overloads
54+
// 'no-dupe-class-members': 'off', // Off due to conflict with typescript overload functions
55+
'tsdoc/syntax': 'error',
56+
// new TS rules begin @TODO: Remove these and adapt code
57+
'@typescript-eslint/prefer-as-const': 'off',
58+
'@typescript-eslint/ban-ts-comment': 'off',
59+
'@typescript-eslint/no-unsafe-call': 'off',
60+
'@typescript-eslint/no-unsafe-member-access': 'off',
61+
'@typescript-eslint/no-unsafe-return': 'off',
62+
'@typescript-eslint/no-unsafe-assignment': 'off',
63+
'@typescript-eslint/no-unsafe-argument': 'off',
64+
'@typescript-eslint/no-floating-promises': 'off',
65+
// new TS rules end
66+
'@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
67+
// @TODO: Remove, as it's already off
68+
// '@typescript-eslint/return-await': 'off',
69+
// @TODO: Remove this rule, deprecated:
70+
// https://typescript-eslint.io/rules/space-before-function-paren/
71+
// '@typescript-eslint/space-before-function-paren': 0,
72+
// @TODO: Should be careful with this rule, should leave it be and disable
73+
// it within files where necessary with explanations
74+
'@typescript-eslint/no-explicit-any': 'off',
75+
// @TODO: Remove, as it's already off
76+
// '@typescript-eslint/explicit-function-return-type': 'off',
77+
// @TODO: Remove, as it's already off
78+
// '@typescript-eslint/no-throw-literal': 'off',
79+
'@typescript-eslint/no-unused-vars': [
80+
'error',
81+
// argsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#argsignorepattern
82+
// varsIgnorePattern: https://eslint.org/docs/latest/rules/no-unused-vars#varsignorepattern
83+
{ args: 'all', argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
84+
],
85+
// @TODO: Remove this rule, as it's a style rule covered by prettier
86+
// '@typescript-eslint/member-delimiter-style': [
87+
// 'error',
88+
// {
89+
// multiline: {
90+
// delimiter: 'none', // 'none' or 'semi' or 'comma'
91+
// requireLast: true,
92+
// },
93+
// singleline: {
94+
// delimiter: 'semi', // 'semi' or 'comma'
95+
// requireLast: false,
96+
// },
97+
// },
98+
// ],
99+
// @TODO: Not recommended to disable rule, should instead disable locally
100+
// with explanation
101+
'@typescript-eslint/ban-ts-ignore': 'off',
102+
},
103+
},
104+
// Jest linting for test files
105+
{
106+
files: 'tests/*.ts',
107+
plugins: ['jest'],
108+
env: {
109+
// @TODO: Jasmine is not meant to be used in Jest tests,
110+
// there's even a rule for it in plugin:jest/recommended
111+
jasmine: true,
112+
jest: true,
113+
'jest/globals': true,
114+
},
115+
// prettier must always be put last, so it overrides anything before it
116+
extends: ['plugin:jest/recommended', 'prettier'],
117+
// @TODO: Remove these rules and adapt code!
118+
rules: {
119+
'jest/no-disabled-tests': 'off',
120+
'jest/expect-expect': 'off',
121+
'jest/no-conditional-expect': 'off',
122+
'jest/valid-title': 'off',
123+
'jest/no-jasmine-globals': 'off',
124+
'jest/valid-expect-in-promise': 'off',
125+
'jest/valid-expect': 'off',
126+
'jest/no-alias-methods': 'off',
127+
},
128+
},
129+
],
56130
}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
dist
3+
/tests/env
4+
/coverage
35
*.md

.prettierrc

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

.prettierrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://prettier.io/docs/en/options.html
2+
3+
module.exports = {
4+
singleQuote: true,
5+
// @TODO Remove as it's default
6+
// arrowParens: 'always',
7+
semi: false,
8+
// @TODO Remove as it's default
9+
// bracketSpacing: true,
10+
trailingComma: 'es5',
11+
// @TODO Remove as it's default
12+
// printWidth: 80,
13+
plugins: ['./node_modules/prettier-plugin-jsdoc/dist/index.js'],
14+
// https://github.com/hosseinmd/prettier-plugin-jsdoc#tsdoc
15+
tsdoc: true,
16+
}

jest.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @TODO Remove this once merged with eslint updates
2-
// eslint-disable-next-line tsdoc/syntax
31
/** @type {import('jest').Config} */
42
const config = {
53
rootDir: '.',

package.json

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
"test:env:esm": "yarn --cwd tests/env/esm && yarn --cwd tests/env/esm start",
4949
"test:env:nitro-app": "yarn build && yarn --cwd tests/env/nitro-app test",
5050
"size": "node scripts/file-size ./dist/bundles/meilisearch.esm.min.js ./dist/bundles/meilisearch.umd.min.js",
51-
"style": "yarn lint",
52-
"style:fix": "yarn lint:fix",
51+
"style": "yarn fmt && yarn lint",
52+
"style:fix": "yarn fmt:fix && yarn lint:fix",
53+
"fmt": "prettier -c ./**/*.{js,ts,tsx}",
54+
"fmt:fix": "prettier -w ./**/*.{js,ts,tsx}",
5355
"lint": "eslint --ext .js,.ts,.tsx .",
5456
"lint:fix": "eslint --ext .js,.ts,.tsx --fix .",
5557
"typingsheader": "node scripts/build.js"
@@ -73,26 +75,20 @@
7375
"cross-fetch": "^3.1.6"
7476
},
7577
"devDependencies": {
78+
"@babel/core": "^7.23.6",
7679
"@babel/preset-env": "^7.22.5",
7780
"@rollup/plugin-babel": "^6.0.3",
7881
"@rollup/plugin-commonjs": "25.0.2",
7982
"@rollup/plugin-json": "^6.0.0",
8083
"@rollup/plugin-node-resolve": "15.1.0",
8184
"@types/jest": "^29.5.11",
82-
"@types/prettier": "^2.2.3",
83-
"@typescript-eslint/eslint-plugin": "2.34.0",
84-
"@typescript-eslint/parser": "2.34.0",
85+
"@typescript-eslint/eslint-plugin": "^6.19.0",
86+
"@typescript-eslint/parser": "^6.19.0",
8587
"abort-controller": "^3.0.0",
8688
"brotli-size": "^4.0.0",
87-
"eslint": "^7.21.0",
88-
"eslint-config-prettier": "^8.1.0",
89-
"eslint-config-standard-with-typescript": "^17.0.0",
90-
"eslint-plugin-import": "2",
91-
"eslint-plugin-jest": "^27.6.1",
92-
"eslint-plugin-node": "11",
93-
"eslint-plugin-prettier": "^3.1.4",
94-
"eslint-plugin-promise": "4",
95-
"eslint-plugin-standard": "5",
89+
"eslint": "^8.56.0",
90+
"eslint-config-prettier": "^9.1.0",
91+
"eslint-plugin-jest": "^27.6.3",
9692
"eslint-plugin-tsdoc": "^0.2.17",
9793
"gzip-size": "^6.0.0",
9894
"jest": "^29.7.0",
@@ -102,14 +98,14 @@
10298
"kleur": "^4.1.5",
10399
"lint-staged": "11.1.2",
104100
"nodemon": "^2.0.16",
105-
"prettier": "^2.2.1",
106-
"prettier-plugin-jsdoc": "^0.4.2",
101+
"prettier": "^3.2.3",
102+
"prettier-plugin-jsdoc": "^1.3.0",
107103
"pretty-bytes": "^5.6.0",
108104
"rollup": "^2.79.1",
109105
"rollup-plugin-terser": "^7.0.0",
110106
"rollup-plugin-typescript2": "^0.35.0",
111107
"shx": "^0.3.2",
112108
"ts-jest": "^29.1.1",
113-
"typescript": "^4.9.5"
109+
"typescript": "^5.3.3"
114110
}
115111
}

rollup.config.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import nodeResolve from '@rollup/plugin-node-resolve'
2-
import { resolve } from 'path'
3-
import commonjs from '@rollup/plugin-commonjs'
4-
import json from '@rollup/plugin-json'
5-
import typescript from 'rollup-plugin-typescript2'
6-
import pkg from './package.json'
7-
import { terser } from 'rollup-plugin-terser'
8-
import { babel } from '@rollup/plugin-babel'
1+
const nodeResolve = require('@rollup/plugin-node-resolve')
2+
const { resolve } = require('path')
3+
const commonjs = require('@rollup/plugin-commonjs')
4+
const json = require('@rollup/plugin-json')
5+
const typescript = require('rollup-plugin-typescript2')
6+
const pkg = require('./package.json')
7+
const { terser } = require('rollup-plugin-terser')
8+
const { babel } = require('@rollup/plugin-babel')
99

1010
function getOutputFileName(fileName, isProd = false) {
1111
return isProd ? fileName.replace(/\.js$/, '.min.js') : fileName

src/token.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Config, TokenSearchRules, TokenOptions } from './types'
2-
import crypto from 'crypto'
2+
import { createHmac } from 'crypto'
33
import { MeiliSearchError } from './errors'
44
import { validateUuid4 } from './utils'
55

@@ -16,8 +16,7 @@ function encode64(data: any) {
1616
* @returns The signature of the token in base64.
1717
*/
1818
function sign(apiKey: string, encodedHeader: string, encodedPayload: string) {
19-
return crypto
20-
.createHmac('sha256', apiKey)
19+
return createHmac('sha256', apiKey)
2120
.update(`${encodedHeader}.${encodedPayload}`)
2221
.digest('base64')
2322
.replace(/\+/g, '-')

src/types/types.ts

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

27+
// TODO fix
28+
// eslint-disable-next-line @typescript-eslint/ban-types
2729
export type ResourceQuery = Pagination & {}
2830

2931
export type ResourceResults<T> = Pagination & {
@@ -46,8 +48,12 @@ export type IndexObject = {
4648
updatedAt: Date
4749
}
4850

51+
// TODO fix
52+
// eslint-disable-next-line @typescript-eslint/ban-types
4953
export type IndexesQuery = ResourceQuery & {}
5054

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

5359
/*
@@ -430,7 +436,11 @@ export type TasksQuery = {
430436
limit?: number
431437
from?: number
432438
}
439+
// TODO fix
440+
// eslint-disable-next-line @typescript-eslint/ban-types
433441
export type CancelTasksQuery = Omit<TasksQuery, 'limit' | 'from'> & {}
442+
// TODO fix
443+
// eslint-disable-next-line @typescript-eslint/ban-types
434444
export type DeleteTasksQuery = Omit<TasksQuery, 'limit' | 'from'> & {}
435445

436446
export type EnqueuedTaskObject = {
@@ -581,8 +591,12 @@ export type KeyUpdate = {
581591
description?: string
582592
}
583593

594+
// TODO fix
595+
// eslint-disable-next-line @typescript-eslint/ban-types
584596
export type KeysQuery = ResourceQuery & {}
585597

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

588602
/*

0 commit comments

Comments
 (0)