Skip to content

Commit 84ede17

Browse files
authored
refactor: enable some eslint rules (#12231)
1 parent e0c73a7 commit 84ede17

File tree

28 files changed

+88
-74
lines changed

28 files changed

+88
-74
lines changed

eslint.config.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ const avoidMistakeRules = {
4343
'@tanstack/query/no-unstable-deps': 'error', // avoid unstable results from the hook being deps
4444
'@tanstack/query/no-void-query-fn': 'error', // query function should always return something
4545
'@lingui/no-single-tag-to-translate': 'error',
46-
// '@lingui/no-single-variables-to-translate': 'error', // we're mixing two i18n frameworks, a lot of false positive reports
47-
// https://github.com/lingui/eslint-plugin/issues/46
48-
// '@lingui/no-unlocalized-strings': 'error',
46+
// https://github.com/lingui/eslint-plugin/issues/104
47+
// '@lingui/no-single-variables-to-translate': 'error',
4948
'@lingui/no-trans-inside-trans': 'error',
5049
'@lingui/t-call-in-function': 'error',
5150

@@ -108,7 +107,7 @@ const avoidMistakeRules = {
108107
/// Unicode support
109108
'no-misleading-character-class': 'error', // RegEx
110109
'require-unicode-regexp': 'error', // RegEx modern RegEx with Unicode support
111-
// 'unicorn/prefer-code-point': 'error',
110+
'unicorn/prefer-code-point': 'error',
112111
// '@masknet/no-builtin-base64': 'warn', // Note: it fixes to Node's Buffer
113112
/// type safety
114113
// '@typescript-eslint/method-signature-style': 'warn', // method signature is bivariant
@@ -249,8 +248,7 @@ const codeStyleRules = {
249248
'react/no-class-component': 'error',
250249
'react/no-context-provider': 'error',
251250
'react/no-forward-ref': 'error',
252-
// Let's wait for https://github.com/typescript-eslint/typescript-eslint/issues/6572
253-
// '@typescript-eslint/no-namespace': 'error', // namespace T {}
251+
// '@typescript-eslint/no-namespace': 'error', // namespace T {}, they won't support type only namespace
254252
'@typescript-eslint/prefer-namespace-keyword': 'error', // but if you really need to, don't use `module T {}`
255253

256254
// Useless code
@@ -431,12 +429,12 @@ const codeStyleRules = {
431429

432430
// Bad practice
433431
'no-ex-assign': 'warn', // reassign err in catch
434-
// 'no-multi-assign': 'warn', // a = b = c
432+
'no-multi-assign': 'warn', // a = b = c
435433
// 'no-param-reassign': 'warn',
436-
// 'no-return-assign': 'warn', // return x = expr
437-
// 'unicorn/no-object-as-default-parameter': 'warn',
438-
// '@typescript-eslint/default-param-last': 'warn', // (a, b = 1, c)
439-
// '@typescript-eslint/no-dynamic-delete': 'error', // this usually means you should use Map/Set
434+
'no-return-assign': 'warn', // return x = expr
435+
'unicorn/no-object-as-default-parameter': 'warn',
436+
'@typescript-eslint/default-param-last': 'warn', // (a, b = 1, c)
437+
'@typescript-eslint/no-dynamic-delete': 'error', // this usually means you should use Map/Set
440438
/// Async functions / Promise bad practice
441439
'no-async-promise-executor': 'error', // new Promise(async (resolve) => )
442440
'no-promise-executor-return': 'error', // new Promise(() => result)
@@ -577,6 +575,7 @@ const plugins = {
577575
'react-hooks': ReactHooksPlugin,
578576
'react-compiler': ReactCompilerPlugin,
579577
'@tanstack/query': ReactQueryPlugin,
578+
// @ts-ignore
580579
'@lingui': fixupPluginRules(LinguiPlugin),
581580
}
582581
export default tseslint.config(

packages/backup-format/tests/encryption.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ const testData = new Uint8Array([
1616
])
1717

1818
test('Old data can be still decrypted', async () => {
19-
const password = Uint8Array.from('password'.split('').map((x) => x.charCodeAt(0)))
19+
const password = Uint8Array.from('password'.split('').map((x) => x.codePointAt(0)))
2020
const decrypted = await decryptBackup(password, testData)
2121
expect(new Uint8Array(decrypted)).toEqual(rawData)
2222
})
2323

2424
test('decrypt(password, encrypt(password, data)) === data', async () => {
25-
const password = Uint8Array.from('password'.split('').map((x) => x.charCodeAt(0)))
25+
const password = Uint8Array.from('password'.split('').map((x) => x.codePointAt(0)))
2626
const data = new Uint8Array([4, 5, 6])
2727

2828
const result = await encryptBackup(password, data)

packages/base/src/Identifier/identifier.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ export class PostIVIdentifier extends Identifier {
169169
console.warn('[@masknet/shared-base] For compatibility, x.com is converted to twitter.com')
170170
}
171171

172-
const networkCache = (PostIVIdentifier.#cache[network] ??= {})
172+
PostIVIdentifier.#cache[network] ??= {}
173+
const networkCache = PostIVIdentifier.#cache[network]
173174
// return the cache to keep the object identity
174175
// eslint-disable-next-line no-constructor-return
175176
if (networkCache[postIV]) return networkCache[postIV]
@@ -286,7 +287,8 @@ export class ProfileIdentifier extends Identifier {
286287
}
287288
if (!userID) throw new TypeError('[@masknet/base] userID cannot be empty.')
288289

289-
const networkCache = (ProfileIdentifier.#cache[network] ??= {})
290+
ProfileIdentifier.#cache[network] ??= {}
291+
const networkCache = ProfileIdentifier.#cache[network]
290292
// return the cache to keep the object identity
291293
// eslint-disable-next-line no-constructor-return
292294
if (networkCache[userID]) return networkCache[userID]

packages/gun-utils/src/instance.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ function createGun() {
1313
class WebSocket extends globalThis.WebSocket {
1414
constructor(url: string | URL) {
1515
super(url)
16-
const abort = (this.abort = () => {
16+
this.abort = () => {
1717
gun?.off()
1818
gun = undefined
1919
this.close()
2020
for (const each of OnCloseEvent) each()
2121
console.log('[Network/gun] WebSocket of the Gun instance is killed due to inactive.')
22-
})
23-
const keepAlive = (this.keepAlive = () => {
22+
}
23+
const abort = this.abort
24+
this.keepAlive = () => {
2425
if (this.timer) clearTimeout(this.timer)
2526
this.timer = setTimeout(abort, 3 * 60 * 1000)
26-
})
27+
}
28+
const keepAlive = this.keepAlive
2729
this.addEventListener(
2830
'message',
2931
(e) => {

packages/injected-script/main/Patches/Event.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export class __Event extends $unsafe.NewObject implements Event {
149149
event.#stopPropagation = false
150150
event.#stopImmediatePropagation = false
151151
if (clearTargets) {
152-
event.#target = event.#relatedTarget = null
152+
event.#relatedTarget = null
153+
event.#target = null
153154
event.#touchTargetList = $safe.Array_of()
154155
}
155156
if (activationTarget !== null) {

packages/injected-script/main/intrinsic_blessed.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ const ArrayIteratorPrototype: IterableIterator<any> = create(
3939
const entries = takeThisF(MapPrototype.entries)<T>
4040
const keys = takeThisF(MapPrototype.keys)<T>
4141
const values = takeThisF(MapPrototype.values)<T>
42-
MapPrototype.entries = MapPrototype[Symbol.iterator] = function (this: T) {
42+
MapPrototype[Symbol.iterator] = function (this: T) {
4343
const iter = entries(this)
4444
setPrototypeOf(iter, MapIteratorPrototype)
4545
return iter
4646
}
47+
MapPrototype.entries = MapPrototype[Symbol.iterator]
4748
MapPrototype.keys = function (this: T) {
4849
const iter = keys(this)
4950
setPrototypeOf(iter, MapIteratorPrototype)
@@ -66,14 +67,13 @@ const ArrayIteratorPrototype: IterableIterator<any> = create(
6667
setPrototypeOf(iter, SetIteratorPrototype)
6768
return iter
6869
}
69-
SetPrototype.values =
70-
SetPrototype.keys =
71-
SetPrototype[Symbol.iterator] =
72-
function (this: T) {
73-
const iter = values(this)
74-
setPrototypeOf(iter, SetIteratorPrototype)
75-
return iter
76-
}
70+
SetPrototype[Symbol.iterator] = function (this: T) {
71+
const iter = values(this)
72+
setPrototypeOf(iter, SetIteratorPrototype)
73+
return iter
74+
}
75+
SetPrototype.keys = SetPrototype[Symbol.iterator]
76+
SetPrototype.values = SetPrototype[Symbol.iterator]
7777
}
7878

7979
// Array
@@ -92,11 +92,12 @@ const ArrayIteratorPrototype: IterableIterator<any> = create(
9292
setPrototypeOf(iter, ArrayIteratorPrototype)
9393
return iter
9494
}
95-
ArrayPrototype.values = ArrayPrototype[Symbol.iterator] = function (this: T) {
95+
ArrayPrototype[Symbol.iterator] = function (this: T) {
9696
const iter = values(this)
9797
setPrototypeOf(iter, ArrayIteratorPrototype)
9898
return iter
9999
}
100+
ArrayPrototype.values = ArrayPrototype[Symbol.iterator]
100101
}
101102

102103
export function Map<K, V>(): Map<K, V> {

packages/mask/background/database/persona/web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export async function updatePersonaDB(
304304
const keys = Object.keys(nextRecord) as Array<keyof typeof nextRecord>
305305
for (const key of keys) {
306306
if (nextRecord[key] === undefined) {
307+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
307308
delete nextRecord[key]
308309
}
309310
}

packages/mask/background/database/utils/openDB.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export function createDBAccessWithAsyncUpgrade<DBSchema, AsyncUpgradePreparedDat
8888

8989
// Share a Promise to prevent async upgrade for multiple times
9090
if (pendingOpen) return pendingOpen
91-
const promise = (pendingOpen = open())
91+
pendingOpen = open()
92+
const promise = pendingOpen
9293
promise.catch(() => (pendingOpen = undefined))
9394
return promise
9495
}

packages/mask/background/network/queryPostKey.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ async function GUN_SEA_work(data: Uint8Array | string, salt: Uint8Array | string
205205
const key = await crypto.subtle.importKey('raw', data, { name: 'PBKDF2' }, false, ['deriveBits'])
206206
const params: Pbkdf2Params = { name: 'PBKDF2', iterations: 100000, salt, hash: { name: 'SHA-256' } }
207207
const derived = await crypto.subtle.deriveBits(params, key, 512)
208+
// eslint-disable-next-line unicorn/prefer-code-point
208209
return btoa(String.fromCharCode(...new Uint8Array(derived)))
209210
}
210211

packages/mask/background/tasks/Cancellable/StartSandboxedPluginHost.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ let hot:
2020
| undefined
2121
if (process.env.NODE_ENV === 'development') {
2222
const sym = Symbol.for('sandboxed plugin bridge hot map')
23-
hot = (globalThis as any)[sym] ??= new Map()
23+
;(globalThis as any)[sym] ??= new Map()
24+
hot = (globalThis as any)[sym]
2425
}
2526

2627
if (Flags.sandboxedPluginRuntime) {

0 commit comments

Comments
 (0)