From 65311529bd1c83b52d699e68fce71db7f9e52927 Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 9 Feb 2023 23:06:03 +0800 Subject: [PATCH] workspace: add eslint-config package (#510) --- .eslintrc.yaml | 124 +------------- package.json | 7 - packages/eslint-config/base.yaml | 154 ++++++++++++++++++ packages/eslint-config/package.json | 18 ++ packages/eslint-config/react.yaml | 27 +++ packages/hydrooj/src/error.ts | 1 - packages/hydrooj/src/handler/problem.ts | 10 +- packages/hydrooj/src/lib/rating.ts | 1 - packages/ui-default/.eslintrc.js | 94 +---------- packages/ui-default/api.ts | 7 +- .../backendlib/markdown-it-media.ts | 1 - packages/ui-default/backendlib/markdown.js | 1 - packages/ui-default/backendlib/template.js | 12 +- packages/ui-default/bus.ts | 2 +- .../autocomplete/components/AutoComplete.tsx | 2 +- .../ui-default/components/calendar/index.js | 2 +- .../components/discussion/reaction.page.tsx | 1 - .../ui-default/components/editor/index.ts | 2 - .../components/highlighter/prismjs.js | 7 +- .../MessagePadDialogueContentContainer.jsx | 2 +- packages/ui-default/components/monaco/nls.js | 2 +- .../components/preview/preview.page.ts | 2 +- .../ui-default/components/vote/vote.page.js | 2 +- packages/ui-default/index.ts | 1 - packages/ui-default/pages/user_verify.page.ts | 2 +- packages/ui-default/theme/default.js | 3 +- packages/ui-default/utils/base64.js | 8 +- packages/ui-default/utils/index.ts | 2 - 28 files changed, 230 insertions(+), 267 deletions(-) create mode 100644 packages/eslint-config/base.yaml create mode 100644 packages/eslint-config/package.json create mode 100644 packages/eslint-config/react.yaml diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 6fbbffc1..6f175be0 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,18 +1,6 @@ root: true extends: - - airbnb-base - - airbnb-typescript/base -env: - es6: true -globals: - Atomics: readonly - SharedArrayBuffer: readonly - BigInt: readonly -parser: '@typescript-eslint/parser' -plugins: - - '@typescript-eslint' - - simple-import-sort - - eslint-plugin-import + - '@hydrooj/eslint-config' ignorePatterns: - public/**/*.js - packages/ui-default @@ -36,116 +24,7 @@ overrides: LOCALES: true LANGS: true rules: - '@typescript-eslint/no-shadow': 1 - - function-call-argument-newline: 0 - react/function-component-definition: 0 - '@typescript-eslint/dot-notation': 0 - '@typescript-eslint/no-implied-eval': 0 - '@typescript-eslint/no-throw-literal': 0 - '@typescript-eslint/return-await': 0 - - no-implicit-coercion: - - warn - - allow: ["!!", "+"] - no-extra-boolean-cast: - - warn - - enforceForLogicalOperands: true - no-multi-str: 0 '@typescript-eslint/no-invalid-this': 1 - '@typescript-eslint/type-annotation-spacing': 1 - '@typescript-eslint/indent': - - warn - - 4 - '@typescript-eslint/lines-between-class-members': - - error - - always - - exceptAfterSingleLine: true - '@typescript-eslint/naming-convention': - - warn - - selector: default - format: [camelCase] - leadingUnderscore: allowSingleOrDouble - - selector: default - filter: - regex: '^([A-Z]|_+id|__call__)$' - match: true - format: null - - selector: variable - modifiers: [destructured] - filter: - regex: '^_id$' - match: false - format: [camelCase, PascalCase, UPPER_CASE, snake_case] - - selector: variable - format: [camelCase, PascalCase, UPPER_CASE] - modifiers: [const] - leadingUnderscore: allowSingleOrDouble - - selector: property - format: [camelCase, PascalCase, UPPER_CASE, snake_case] - leadingUnderscore: allowSingleOrDouble - - selector: [function, parameter, parameterProperty, objectLiteralMethod] - filter: - regex: __call__ - match: false - format: [camelCase, PascalCase] - leadingUnderscore: allowSingleOrDouble - - selector: [objectLiteralProperty] - filter: - regex: '^[\d]+$' - match: true - format: null - - selector: [typeProperty, objectLiteralProperty] - modifiers: [requiresQuotes] - format: null - - selector: enum - format: [PascalCase] - - selector: [class, interface, typeAlias, enumMember] - format: [PascalCase, camelCase, UPPER_CASE] - - selector: typeParameter - format: [camelCase, PascalCase, UPPER_CASE] - - '@typescript-eslint/no-redeclare': 0 - '@typescript-eslint/default-param-last': 0 - - - class-methods-use-this: 0 - global-require: 0 - guard-for-in: 0 - implicit-arrow-linebreak: 0 - import/extensions: 0 - import/newline-after-import: 0 - import/no-cycle: 0 - import/no-extraneous-dependencies: 0 - import/no-named-as-default: 0 - import/prefer-default-export: 0 - logical-assignment-operators: - - warn - - always - - enforceForIfStatements: true - max-classes-per-file: 0 - max-len: - - warn - - 150 - newline-per-chained-call: 0 - no-bitwise: 0 - no-console: 0 - no-continue: 0 - no-extend-native: 0 - no-empty: - - warn - - allowEmptyCatch: true - no-multi-assign: 0 - no-nested-ternary: 0 - no-param-reassign: 0 - no-plusplus: 0 - no-restricted-syntax: 0 - no-return-await: 0 - no-shadow: 0 - no-underscore-dangle: 0 - no-unmodified-loop-condition: 1 - prefer-destructuring: 0 - function-paren-newline: 0 simple-import-sort/imports: - warn - groups: @@ -156,7 +35,6 @@ rules: - "^@?hydrooj" - "^" - "^\\." - simple-import-sort/exports: 0 settings: import/parsers: '@typescript-eslint/parser': diff --git a/package.json b/package.json index 2fbf32fa..b08b47a0 100644 --- a/package.json +++ b/package.json @@ -49,15 +49,8 @@ "esbuild": "0.16.16", "esbuild-loader": "^2.21.0", "eslint": "^8.33.0", - "eslint-config-airbnb": "^19.0.4", - "eslint-config-airbnb-typescript": "^17.0.0", "eslint-import-resolver-typescript": "^3.5.3", "eslint-import-resolver-webpack": "^0.13.2", - "eslint-plugin-import": "2.27.5", - "eslint-plugin-jsx-a11y": "^6.7.1", - "eslint-plugin-react": "^7.32.2", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-simple-import-sort": "10.0.0", "friendly-errors-webpack-plugin": "^1.7.0", "fs-extra": "^11.1.0", "globby": "13.1.3", diff --git a/packages/eslint-config/base.yaml b/packages/eslint-config/base.yaml new file mode 100644 index 00000000..2b62e728 --- /dev/null +++ b/packages/eslint-config/base.yaml @@ -0,0 +1,154 @@ +extends: + - airbnb-base + - airbnb-typescript/base +env: + es6: true +globals: + Atomics: readonly + SharedArrayBuffer: readonly + BigInt: readonly +parser: '@typescript-eslint/parser' +plugins: + - '@typescript-eslint' + - simple-import-sort + - eslint-plugin-import +rules: + '@typescript-eslint/no-shadow': 1 + + function-call-argument-newline: 0 + '@typescript-eslint/dot-notation': 0 + '@typescript-eslint/no-implied-eval': 0 + '@typescript-eslint/no-throw-literal': 0 + '@typescript-eslint/return-await': 0 + + comma-dangle: + - 1 + - always-multiline + + no-implicit-coercion: + - warn + - allow: ["!!", "+"] + no-extra-boolean-cast: + - warn + - enforceForLogicalOperands: true + no-multi-str: 0 + '@typescript-eslint/no-invalid-this': 0 + '@typescript-eslint/type-annotation-spacing': 1 + '@typescript-eslint/indent': + - warn + - 4 + '@typescript-eslint/lines-between-class-members': + - error + - always + - exceptAfterSingleLine: true + '@typescript-eslint/naming-convention': + - warn + - selector: default + format: [camelCase] + leadingUnderscore: allowSingleOrDouble + - selector: default + filter: + regex: '^([A-Z]|_+id|__call__)$' + match: true + format: null + - selector: variable + modifiers: [destructured] + filter: + regex: '^_id$' + match: false + format: [camelCase, PascalCase, UPPER_CASE, snake_case] + - selector: variable + format: [camelCase, PascalCase, UPPER_CASE] + modifiers: [const] + leadingUnderscore: allowSingleOrDouble + - selector: property + format: [camelCase, PascalCase, UPPER_CASE, snake_case] + leadingUnderscore: allowSingleOrDouble + - selector: [function, parameter, parameterProperty, objectLiteralMethod] + filter: + regex: __call__ + match: false + format: [camelCase, PascalCase] + leadingUnderscore: allowSingleOrDouble + - selector: [objectLiteralProperty] + filter: + regex: '^[\d]+$' + match: true + format: null + - selector: [typeProperty, objectLiteralProperty] + modifiers: [requiresQuotes] + format: null + - selector: enum + format: [PascalCase] + - selector: [class, interface, typeAlias, enumMember] + format: [PascalCase, camelCase, UPPER_CASE] + - selector: typeParameter + format: [camelCase, PascalCase, UPPER_CASE] + + '@typescript-eslint/no-redeclare': 0 + '@typescript-eslint/default-param-last': 0 + default-param-last: 0 + '@typescript-eslint/quotes': ['warn', 'single', { avoidEscape: true }] + + class-methods-use-this: 0 + global-require: 0 + guard-for-in: 0 + implicit-arrow-linebreak: 0 + import/extensions: 0 + consistent-return: 1 + func-names: 0 + import/newline-after-import: 0 + import/no-cycle: 0 + import/no-extraneous-dependencies: 0 + import/no-named-as-default: 0 + import/prefer-default-export: 0 + + logical-assignment-operators: + - warn + - always + - enforceForIfStatements: true + max-classes-per-file: 0 + max-len: + - warn + - 150 + newline-per-chained-call: 0 + no-bitwise: 0 + no-console: 0 + no-continue: 0 + no-extend-native: 0 + no-empty: + - warn + - allowEmptyCatch: true + no-multi-assign: 0 + no-nested-ternary: 0 + no-param-reassign: 0 + no-plusplus: 0 + no-return-await: 0 + no-shadow: 0 + no-underscore-dangle: 0 + no-unmodified-loop-condition: 1 + prefer-destructuring: 0 + function-paren-newline: 0 + simple-import-sort/exports: 0 + + # Note: must disable the base rule as it can report incorrect errors + no-use-before-define: 0 + '@typescript-eslint/no-use-before-define': 1 + no-unused-vars: 0 + '@typescript-eslint/no-unused-vars': 1 + + no-restricted-syntax: + - error + - selector: LabeledStatement + message: Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand. + - selector: WithStatement + message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.' + + simple-import-sort/imports: + - warn + - groups: + - ["^\\u0000"] + - + - "^(node:)?(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)" + - "^" + - "^\\." diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json new file mode 100644 index 00000000..dcad4587 --- /dev/null +++ b/packages/eslint-config/package.json @@ -0,0 +1,18 @@ +{ + "name": "@hydrooj/eslint-config", + "version": "1.0.0", + "license": "MIT", + "main": "react.yaml", + "dependencies": { + "eslint-config-airbnb": "^19.0.4", + "eslint-config-airbnb-typescript": "^17.0.0", + "eslint-plugin-import": "2.27.5", + "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-react": "^7.32.2", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-simple-import-sort": "10.0.0" + }, + "peerDependencies": { + "eslint": ">= 8" + } +} diff --git a/packages/eslint-config/react.yaml b/packages/eslint-config/react.yaml new file mode 100644 index 00000000..4fce1c78 --- /dev/null +++ b/packages/eslint-config/react.yaml @@ -0,0 +1,27 @@ +extends: +- ./base.yaml +- airbnb/hooks +plugins: +- react +- jsx-a11y +rules: + react-hooks/exhaustive-deps: 0 + react/prefer-stateless-function: 0 + react/function-component-definition: 0 + react/static-property-placement: 0 + react/self-closing-comp: 0 + react/prop-types: 0 + react/jsx-filename-extension: 0 + react/jsx-one-expression-per-line: 0 + react/jsx-props-no-spreading: 0 + react/no-string-refs: 0 + react/require-default-props: 0 + react/react-in-jsx-scope: 0 + react/destructuring-assignment: 0 + react/button-has-type: 0 + react/forbid-prop-types: 0 + jsx-a11y/no-static-element-interactions: 0 + jsx-a11y/anchor-is-valid: 0 + jsx-a11y/click-events-have-key-events: 0 + jsx-a11y/label-has-associated-control: 0 + # 'react/no-unknown-property': ['error', { ignore: ['key'] }], \ No newline at end of file diff --git a/packages/hydrooj/src/error.ts b/packages/hydrooj/src/error.ts index bb7133bb..96945e63 100644 --- a/packages/hydrooj/src/error.ts +++ b/packages/hydrooj/src/error.ts @@ -33,7 +33,6 @@ export class HydroError extends Error { this.params = params; } - // eslint-disable-next-line class-methods-use-this msg() { return 'HydroError'; } diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index c0f7d3a4..f7eb06ad 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -771,13 +771,9 @@ export class ProblemFilesHandler extends ProblemDetailHandler { } } for (const entry of files) { - if (entry.type === 'testdata') { - // eslint-disable-next-line no-await-in-loop - await problem.addTestdata(domainId, this.pdoc.docId, entry.name, entry.data(), this.user._id); - } else { - // eslint-disable-next-line no-await-in-loop - await problem.addAdditionalFile(domainId, this.pdoc.docId, entry.name, entry.data(), this.user._id); - } + const method = entry.type === 'testdata' ? 'addTestdata' : 'addAdditionalFile'; + // eslint-disable-next-line no-await-in-loop + await problem[method](domainId, this.pdoc.docId, entry.name, entry.data(), this.user._id); } this.back(); } diff --git a/packages/hydrooj/src/lib/rating.ts b/packages/hydrooj/src/lib/rating.ts index f4f0f792..029cf803 100644 --- a/packages/hydrooj/src/lib/rating.ts +++ b/packages/hydrooj/src/lib/rating.ts @@ -26,7 +26,6 @@ class RatingCalculator { } } - // eslint-disable-next-line class-methods-use-this calP(a: User, b: User) { return 1 / (1 + 10 ** ((b.old - a.old) / 400)); } diff --git a/packages/ui-default/.eslintrc.js b/packages/ui-default/.eslintrc.js index b4b233bb..a0a0e143 100644 --- a/packages/ui-default/.eslintrc.js +++ b/packages/ui-default/.eslintrc.js @@ -1,9 +1,9 @@ +/* eslint-disable @typescript-eslint/naming-convention */ const path = require('path'); module.exports = { root: true, parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint', 'react', 'simple-import-sort'], env: { browser: true, es6: true, @@ -11,9 +11,7 @@ module.exports = { commonjs: true, }, extends: [ - 'airbnb', - 'airbnb/hooks', - 'airbnb-typescript', + '@hydrooj/eslint-config', ], parserOptions: { sourceType: 'module', @@ -53,100 +51,19 @@ module.exports = { JQuery: true, }, rules: { - 'react-hooks/exhaustive-deps': 'off', - '@typescript-eslint/dot-notation': 'off', - '@typescript-eslint/no-implied-eval': 'off', - '@typescript-eslint/no-throw-literal': 'off', - '@typescript-eslint/return-await': 'off', - '@typescript-eslint/no-shadow': 'warn', - 'no-shadow': 'off', - 'guard-for-in': 'off', - '@typescript-eslint/quotes': ['warn', 'single', { avoidEscape: true }], - // FIXME A bug with eslint-parser - 'template-curly-spacing': 'off', - // FIXME A bug with eslint-plugin-react - 'react/no-unknown-property': ['error', { ignore: ['key'] }], - - // Note: must disable the base rule as it can report incorrect errors - 'no-use-before-define': 'off', - '@typescript-eslint/no-use-before-define': ['error'], - 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': 'warn', - - '@typescript-eslint/lines-between-class-members': [ - 'error', - 'always', - { exceptAfterSingleLine: true }, - ], + // 'template-curly-spacing': 'off', - 'lines-between-class-members': [ - 'error', - 'always', - { exceptAfterSingleLine: true }, - ], - 'comma-dangle': [ - 'error', - 'always-multiline', - ], - indent: [ - 'error', + '@typescript-eslint/indent': [ + 'warn', 2, { SwitchCase: 1 }, ], - 'max-len': ['error', 150], - quotes: ['warn', 'single', { avoidEscape: true }], - 'class-methods-use-this': 'off', - 'consistent-return': 'warn', - 'func-names': 'off', 'function-paren-newline': 'off', - 'default-param-last': 'off', - 'import/first': 'off', - 'import/extensions': 'off', - 'import/no-extraneous-dependencies': 'off', - 'max-classes-per-file': 'off', - 'newline-per-chained-call': 'off', - 'no-empty': ['warn', { allowEmptyCatch: true }], - 'no-console': 'off', - 'no-continue': 'off', 'no-mixed-operators': 'off', - 'no-multi-assign': 'off', - 'no-plusplus': 'off', - 'no-restricted-syntax': [ - 'error', - { - selector: 'LabeledStatement', - message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', - }, - { - selector: 'WithStatement', - message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', - }, - ], - 'no-underscore-dangle': 'off', 'no-await-in-loop': 'off', 'no-lonely-if': 'off', - 'no-nested-ternary': 'off', - 'no-param-reassign': 'off', 'no-script-url': 'off', - 'no-bitwise': 'off', - 'react/prefer-stateless-function': 'off', - 'react/static-property-placement': 'off', - 'react/self-closing-comp': 'off', - 'react/prop-types': 'off', - 'react/jsx-filename-extension': 'off', - 'react/jsx-one-expression-per-line': 'off', - 'react/jsx-props-no-spreading': 'off', - 'react/no-string-refs': 'off', - 'react/require-default-props': 'off', - 'react/react-in-jsx-scope': 'off', - 'react/destructuring-assignment': 'off', - 'react/button-has-type': 'off', - 'react/forbid-prop-types': 'off', - 'jsx-a11y/no-static-element-interactions': 'off', - 'jsx-a11y/anchor-is-valid': 'off', - 'jsx-a11y/click-events-have-key-events': 'off', - 'jsx-a11y/label-has-associated-control': 'off', 'simple-import-sort/imports': [ 'warn', @@ -157,6 +74,5 @@ module.exports = { ], }, ], - 'simple-import-sort/exports': 'off', }, }; diff --git a/packages/ui-default/api.ts b/packages/ui-default/api.ts index b445aab2..4abe24b2 100644 --- a/packages/ui-default/api.ts +++ b/packages/ui-default/api.ts @@ -1,3 +1,5 @@ +/* eslint-disable import/order */ +/* eslint-disable import/first */ export * from './utils'; export { default as Notification } from './components/notification'; export * from './components/dialog'; @@ -53,12 +55,11 @@ declare global { lazyModuleResolver: Record; } - let UserContext: Record; - let UiContext: Record; + let UserContext: Record; // eslint-disable-line + let UiContext: Record; // eslint-disable-line } // Below are old version api compat -/* eslint-disable import/order */ import $ from 'jquery'; import _ from 'lodash'; import React from 'react'; diff --git a/packages/ui-default/backendlib/markdown-it-media.ts b/packages/ui-default/backendlib/markdown-it-media.ts index e9b68526..adcc4682 100644 --- a/packages/ui-default/backendlib/markdown-it-media.ts +++ b/packages/ui-default/backendlib/markdown-it-media.ts @@ -79,7 +79,6 @@ function resourceUrl(service: string, src: string, url: string, options) { return src; } -// eslint-disable-next-line import/prefer-default-export export function Media(md: MarkdownIt) { const options = { url: resourceUrl, diff --git a/packages/ui-default/backendlib/markdown.js b/packages/ui-default/backendlib/markdown.js index e9098ef4..8d03c4b0 100644 --- a/packages/ui-default/backendlib/markdown.js +++ b/packages/ui-default/backendlib/markdown.js @@ -59,7 +59,6 @@ function renderInline(text) { return md.renderInline(text); } -// eslint-disable-next-line no-multi-assign global.Hydro.lib.markdown = module.exports = { md, plugin, render, renderInline, }; diff --git a/packages/ui-default/backendlib/template.js b/packages/ui-default/backendlib/template.js index 38541b90..ddad8b80 100644 --- a/packages/ui-default/backendlib/template.js +++ b/packages/ui-default/backendlib/template.js @@ -13,10 +13,9 @@ const { buildContent, avatar } = global.Hydro.lib; let { template } = argv.options; if (template && typeof template !== 'string') template = findFileSync('@hydrooj/ui-default/templates'); -else if (template) template = findFileSync(template); +else template &&= findFileSync(template); class Loader extends nunjucks.Loader { - // eslint-disable-next-line class-methods-use-this getSource(name) { if (!template) { if (!global.Hydro.ui.template[name]) throw new Error(`Cannot get template ${name}`); @@ -116,13 +115,7 @@ nunjucks.runtime.memberLookup = function memberLookup(obj, val) { if ((obj || {})._original) obj = obj._original; if (obj === undefined || obj === null) return undefined; if (typeof obj[val] === 'function') { - const fn = function () { - // eslint-disable-next-line - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - // eslint-disable-next-line prefer-rest-params - args[_key2] = arguments[_key2]; - } - // eslint-disable-next-line block-scoped-var + const fn = function (...args) { return obj[val].call(obj, ...args); }; fn._original = obj[val]; @@ -169,7 +162,6 @@ env.addGlobal('findSubModule', (prefix) => Object.keys(global.Hydro.ui.template) env.addGlobal('templateExists', (name) => !!global.Hydro.ui.template[name]); async function render(name, state) { - // eslint-disable-next-line no-return-await return await new Promise((resolve, reject) => { env.render(name, { page_name: name.split('.')[0], diff --git a/packages/ui-default/bus.ts b/packages/ui-default/bus.ts index cd2b73e9..66879daa 100644 --- a/packages/ui-default/bus.ts +++ b/packages/ui-default/bus.ts @@ -16,7 +16,7 @@ export interface EventMap extends Record { } function getHooks(name: K) { - const hooks = _hooks[name] || (_hooks[name] = []); + const hooks = (_hooks[name] ||= []); if (hooks.length >= 2048) { console.warn( 'max listener count (2048) for event "%s" exceeded, which may be caused by a memory leak', diff --git a/packages/ui-default/components/autocomplete/components/AutoComplete.tsx b/packages/ui-default/components/autocomplete/components/AutoComplete.tsx index aca88161..d1696ccd 100644 --- a/packages/ui-default/components/autocomplete/components/AutoComplete.tsx +++ b/packages/ui-default/components/autocomplete/components/AutoComplete.tsx @@ -122,7 +122,7 @@ const AutoComplete = forwardRef(function Impl(props: AutoCompleteProps, re setCurrentItem(null); return; } - if (!queryCache[query]) queryCache[query] = await queryItems(query); + queryCache[query] ||= await queryItems(query); for (const item of queryCache[query]) valueCache[itemKey(item)] = item; setItemList(queryCache[query]); setCurrentItem((!freeSolo && queryCache[query].length > 0) ? 0 : null); diff --git a/packages/ui-default/components/calendar/index.js b/packages/ui-default/components/calendar/index.js index 180b5202..0b00ee95 100644 --- a/packages/ui-default/components/calendar/index.js +++ b/packages/ui-default/components/calendar/index.js @@ -349,7 +349,7 @@ export default class Calendar { }; banner.endAt = banner.event.maskFrom.clone().subtract(1, 'day'); banner.endSnap = true; - bannerSpans[i].span -= newBannerSpan.span; // eslint-disable-line no-param-reassign + bannerSpans[i].span -= newBannerSpan.span; bannerSpans.splice(i + 1, 0, newBannerSpan); i++; } diff --git a/packages/ui-default/components/discussion/reaction.page.tsx b/packages/ui-default/components/discussion/reaction.page.tsx index 98bb1827..25e0ea39 100644 --- a/packages/ui-default/components/discussion/reaction.page.tsx +++ b/packages/ui-default/components/discussion/reaction.page.tsx @@ -38,7 +38,6 @@ function Reaction({ payload, ele }) { const [finish, updateFinish] = React.useState(false); if (finish) setTimeout(() => updateFinish(false), 1000); return ( - // eslint-disable-next-line no-nested-ternary
diff --git a/packages/ui-default/components/editor/index.ts b/packages/ui-default/components/editor/index.ts index 655cba32..5fbe7d66 100644 --- a/packages/ui-default/components/editor/index.ts +++ b/packages/ui-default/components/editor/index.ts @@ -26,7 +26,6 @@ export const config = { inlineDigit: true, }, theme: { - // eslint-disable-next-line no-template-curly-in-string path: `${UiContext.cdn_prefix}vditor/dist/css/content-theme`, current: 'light', }, @@ -81,7 +80,6 @@ export default class Editor extends DOMAttachedObject { $dom.hide(); origin.parentElement.appendChild(ele); const value = this.options.value || $dom.val(); - // eslint-disable-next-line no-nested-ternary this.model = typeof model === 'string' ? monaco.editor.getModel(monaco.Uri.parse(model)) || monaco.editor.createModel(value, language === 'auto' ? undefined : language, monaco.Uri.parse(model)) diff --git a/packages/ui-default/components/highlighter/prismjs.js b/packages/ui-default/components/highlighter/prismjs.js index 13c1a3d7..4e5f2377 100644 --- a/packages/ui-default/components/highlighter/prismjs.js +++ b/packages/ui-default/components/highlighter/prismjs.js @@ -31,7 +31,6 @@ loadLanguages(); languageMeta.forEach((meta) => { for (let i = 0; i < meta.ext.length; ++i) { if (Prism.languages[meta.ext[i]] !== undefined) { - // eslint-disable-next-line no-param-reassign meta.target = meta.ext[i]; break; } @@ -44,7 +43,7 @@ languageMeta.forEach((meta) => { // Copy to Clipboard Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => { const linkCopy = document.createElement('a'); - linkCopy.href = 'javascript:;'; // eslint-disable-line no-script-url + linkCopy.href = 'javascript:;'; linkCopy.textContent = 'Copy'; const clip = new Clipboard(linkCopy, { text: () => env.code }); clip.on('success', () => { @@ -89,8 +88,8 @@ function handlerInvisiblesToken(tokens, name) { } else if (type === 'Array') { for (let i = 0, l = value.length; i < l; i++) handlerInvisiblesToken(value, i); } else { - const inside = value.inside || (value.inside = {}); - addInvisibles(inside); + value.inside ||= {}; + addInvisibles(value.inside); } } diff --git a/packages/ui-default/components/messagepad/MessagePadDialogueContentContainer.jsx b/packages/ui-default/components/messagepad/MessagePadDialogueContentContainer.jsx index ddd7b1c9..9dad8fb3 100644 --- a/packages/ui-default/components/messagepad/MessagePadDialogueContentContainer.jsx +++ b/packages/ui-default/components/messagepad/MessagePadDialogueContentContainer.jsx @@ -49,7 +49,7 @@ export default connect(mapStateToProps)(class MessagePadDialogueContentContainer const data = JSON.parse(msg.content); const str = i18n(data.message).replace(/\{([^{}]+)\}/g, (match, key) => `%placeholder%${key}%placeholder%`); const arr = str.split('%placeholder%'); - data.params = data.params || {}; + data.params ||= {}; for (let i = 1; i < arr.length; i += 2) { if (arr[i].endsWith(':link')) { const link = data.params[arr[i].split(':link')[0]]; diff --git a/packages/ui-default/components/monaco/nls.js b/packages/ui-default/components/monaco/nls.js index 88ed55f3..4cd5d63e 100644 --- a/packages/ui-default/components/monaco/nls.js +++ b/packages/ui-default/components/monaco/nls.js @@ -16,7 +16,7 @@ function format(message, args) { export const getConfiguredDefaultLocale = () => 'zh'; -let CURRENT_LOCALE_DATA = {}; +let CURRENT_LOCALE_DATA = {}; // eslint-disable-line @typescript-eslint/naming-convention function find(path, message) { for (const key of Object.keys(CURRENT_LOCALE_DATA)) { diff --git a/packages/ui-default/components/preview/preview.page.ts b/packages/ui-default/components/preview/preview.page.ts index e01bc045..16d20b06 100644 --- a/packages/ui-default/components/preview/preview.page.ts +++ b/packages/ui-default/components/preview/preview.page.ts @@ -120,7 +120,7 @@ export async function previewFile(ev?, type = '') { if (ev) { const link = $(ev.currentTarget).find('a').attr('href'); if (!link) return null; - if (!type) type = ev.currentTarget.getAttribute('data-preview'); + type ||= ev.currentTarget.getAttribute('data-preview'); const ext = filename.split('.').pop(); if (['zip', 'rar', '7z'].includes(ext) || filesize > 8 * 1024 * 1024) { const action = await new ActionDialog({ diff --git a/packages/ui-default/components/vote/vote.page.js b/packages/ui-default/components/vote/vote.page.js index 701503f5..e73f6a47 100644 --- a/packages/ui-default/components/vote/vote.page.js +++ b/packages/ui-default/components/vote/vote.page.js @@ -34,7 +34,7 @@ const votePage = new AutoloadPage('votePage', () => { setVoteState($container, data.vote, data.user_vote); }) .catch((e) => { - Notification.error(`Failed to vote: ${ e.message}`); + Notification.error(`Failed to vote: ${e.message}`); }); return false; }); diff --git a/packages/ui-default/index.ts b/packages/ui-default/index.ts index 89c006f6..c4d115a9 100644 --- a/packages/ui-default/index.ts +++ b/packages/ui-default/index.ts @@ -135,7 +135,6 @@ class RichMediaHandler extends Handler { } } -// eslint-disable-next-line import/prefer-default-export export function apply(ctx: Context) { if (process.env.HYDRO_CLI) return; ctx.Route('wiki_help', '/wiki/help', WikiHelpHandler); diff --git a/packages/ui-default/pages/user_verify.page.ts b/packages/ui-default/pages/user_verify.page.ts index 5df712cc..0141b473 100644 --- a/packages/ui-default/pages/user_verify.page.ts +++ b/packages/ui-default/pages/user_verify.page.ts @@ -86,7 +86,7 @@ export default new AutoloadPage('user_verify', () => { const { authn, tfa } = info.uname || info.mail; if (authn || tfa) { let action = (authn && tfa) ? await chooseAction(true) : ''; - if (!action) action = tfa ? await chooseAction(false) : 'webauthn'; + action ||= tfa ? await chooseAction(false) : 'webauthn'; if (action === 'webauthn') { const challenge = await verifywebauthn($form); if (challenge) $form['authnChallenge'].value = challenge; diff --git a/packages/ui-default/theme/default.js b/packages/ui-default/theme/default.js index 92848f1d..426c2739 100644 --- a/packages/ui-default/theme/default.js +++ b/packages/ui-default/theme/default.js @@ -25,11 +25,10 @@ import 'vj/misc/section.styl'; import 'vj/misc/nothing.styl'; import 'vj/components/editor/cmeditor.styl'; import 'vj/components/datepicker/datepicker.styl'; +import './dark.styl'; // load all page stylesheets const pageStyleReq = require.context('../', true, /\.page\.styl$/i); pageStyleReq.keys().map((key) => pageStyleReq(key)); const pageStyleReqDefault = require.context('../', true, /\.page\.default\.styl$/i); pageStyleReqDefault.keys().map((key) => pageStyleReqDefault(key)); - -import './dark.styl'; diff --git a/packages/ui-default/utils/base64.js b/packages/ui-default/utils/base64.js index 30229170..0b53eb71 100644 --- a/packages/ui-default/utils/base64.js +++ b/packages/ui-default/utils/base64.js @@ -11,7 +11,7 @@ const Base64 = { let enc3; let enc4; let i = 0; - input = Base64._utf8_encode(input); + input = Base64._utf8Encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); @@ -52,11 +52,11 @@ const Base64 = { if (enc3 !== 64) output += String.fromCharCode(chr2); if (enc4 !== 64) output += String.fromCharCode(chr3); } - output = Base64._utf8_decode(output); + output = Base64._utf8Decode(output); return output; }, - _utf8_encode(string) { + _utf8Encode(string) { string = string.replace(/\r\n/g, '\n'); let utftext = ''; for (let n = 0; n < string.length; n++) { @@ -75,7 +75,7 @@ const Base64 = { return utftext; }, - _utf8_decode(utftext) { + _utf8Decode(utftext) { let string = ''; let i = 0; let c = 0; diff --git a/packages/ui-default/utils/index.ts b/packages/ui-default/utils/index.ts index 0b28effa..baf0e88e 100644 --- a/packages/ui-default/utils/index.ts +++ b/packages/ui-default/utils/index.ts @@ -67,7 +67,6 @@ export async function pipeStream(read, write, abort) { } // https://github.com/andrasq/node-mongoid-js/blob/master/mongoid.js -/* eslint-disable */ export function mongoId(idstring: string) { if (typeof idstring !== 'string') idstring = String(idstring); return { @@ -77,7 +76,6 @@ export function mongoId(idstring: string) { sequence: parseInt(idstring.slice(18, 18 + 6), 16), }; } -/* eslint-enable */ const loaded = {};