workspace: add eslint-config package (#510)

This commit is contained in:
undefined authored and GitHub committed 2023-02-09 23:06:03 +08:00
1 parent e7945a104f
commit 65311529bd
28 files changed
+229 -266

No files matched your search

+1 -123
View File
@@ -1,18 +1,6 @@
root: true root: true
extends: extends:
- airbnb-base - '@hydrooj/eslint-config'
- 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
ignorePatterns: ignorePatterns:
- public/**/*.js - public/**/*.js
- packages/ui-default - packages/ui-default
@@ -36,116 +24,7 @@ overrides:
LOCALES: true LOCALES: true
LANGS: true LANGS: true
rules: 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/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: simple-import-sort/imports:
- warn - warn
- groups: - groups:
@@ -156,7 +35,6 @@ rules:
- "^@?hydrooj" - "^@?hydrooj"
- "^" - "^"
- "^\\." - "^\\."
simple-import-sort/exports: 0
settings: settings:
import/parsers: import/parsers:
'@typescript-eslint/parser': '@typescript-eslint/parser':
-7
View File
@@ -49,15 +49,8 @@
"esbuild": "0.16.16", "esbuild": "0.16.16",
"esbuild-loader": "^2.21.0", "esbuild-loader": "^2.21.0",
"eslint": "^8.33.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-typescript": "^3.5.3",
"eslint-import-resolver-webpack": "^0.13.2", "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", "friendly-errors-webpack-plugin": "^1.7.0",
"fs-extra": "^11.1.0", "fs-extra": "^11.1.0",
"globby": "13.1.3", "globby": "13.1.3",
+154
View File
@@ -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)(/.*|$)"
- "^"
- "^\\."
+18
View File
@@ -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"
}
}
+27
View File
@@ -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'] }],
-1
View File
@@ -33,7 +33,6 @@ export class HydroError extends Error {
this.params = params; this.params = params;
} }
// eslint-disable-next-line class-methods-use-this
msg() { msg() {
return 'HydroError'; return 'HydroError';
} }
+2 -6
View File
@@ -771,13 +771,9 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
} }
} }
for (const entry of files) { for (const entry of files) {
if (entry.type === 'testdata') { const method = entry.type === 'testdata' ? 'addTestdata' : 'addAdditionalFile';
// eslint-disable-next-line no-await-in-loop // eslint-disable-next-line no-await-in-loop
await problem.addTestdata(domainId, this.pdoc.docId, entry.name, entry.data(), this.user._id); await problem[method](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);
}
} }
this.back(); this.back();
} }
-1
View File
@@ -26,7 +26,6 @@ class RatingCalculator {
} }
} }
// eslint-disable-next-line class-methods-use-this
calP(a: User, b: User) { calP(a: User, b: User) {
return 1 / (1 + 10 ** ((b.old - a.old) / 400)); return 1 / (1 + 10 ** ((b.old - a.old) / 400));
} }
+5 -89
View File
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
const path = require('path'); const path = require('path');
module.exports = { module.exports = {
root: true, root: true,
parser: '@typescript-eslint/parser', parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'react', 'simple-import-sort'],
env: { env: {
browser: true, browser: true,
es6: true, es6: true,
@@ -11,9 +11,7 @@ module.exports = {
commonjs: true, commonjs: true,
}, },
extends: [ extends: [
'airbnb', '@hydrooj/eslint-config',
'airbnb/hooks',
'airbnb-typescript',
], ],
parserOptions: { parserOptions: {
sourceType: 'module', sourceType: 'module',
@@ -53,100 +51,19 @@ module.exports = {
JQuery: true, JQuery: true,
}, },
rules: { 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 // FIXME A bug with eslint-parser
'template-curly-spacing': 'off', // '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 '@typescript-eslint/indent': [
'no-use-before-define': 'off', 'warn',
'@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 },
],
'lines-between-class-members': [
'error',
'always',
{ exceptAfterSingleLine: true },
],
'comma-dangle': [
'error',
'always-multiline',
],
indent: [
'error',
2, 2,
{ SwitchCase: 1 }, { 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', '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-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-await-in-loop': 'off',
'no-lonely-if': 'off', 'no-lonely-if': 'off',
'no-nested-ternary': 'off',
'no-param-reassign': 'off',
'no-script-url': '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': [ 'simple-import-sort/imports': [
'warn', 'warn',
@@ -157,6 +74,5 @@ module.exports = {
], ],
}, },
], ],
'simple-import-sort/exports': 'off',
}, },
}; };
+4 -3
View File
@@ -1,3 +1,5 @@
/* eslint-disable import/order */
/* eslint-disable import/first */
export * from './utils'; export * from './utils';
export { default as Notification } from './components/notification'; export { default as Notification } from './components/notification';
export * from './components/dialog'; export * from './components/dialog';
@@ -53,12 +55,11 @@ declare global {
lazyModuleResolver: Record<string, any>; lazyModuleResolver: Record<string, any>;
} }
let UserContext: Record<string, any>; let UserContext: Record<string, any>; // eslint-disable-line
let UiContext: Record<string, any>; let UiContext: Record<string, any>; // eslint-disable-line
} }
// Below are old version api compat // Below are old version api compat
/* eslint-disable import/order */
import $ from 'jquery'; import $ from 'jquery';
import _ from 'lodash'; import _ from 'lodash';
import React from 'react'; import React from 'react';
@@ -79,7 +79,6 @@ function resourceUrl(service: string, src: string, url: string, options) {
return src; return src;
} }
// eslint-disable-next-line import/prefer-default-export
export function Media(md: MarkdownIt) { export function Media(md: MarkdownIt) {
const options = { const options = {
url: resourceUrl, url: resourceUrl,
@@ -59,7 +59,6 @@ function renderInline(text) {
return md.renderInline(text); return md.renderInline(text);
} }
// eslint-disable-next-line no-multi-assign
global.Hydro.lib.markdown = module.exports = { global.Hydro.lib.markdown = module.exports = {
md, plugin, render, renderInline, md, plugin, render, renderInline,
}; };
+2 -10
View File
@@ -13,10 +13,9 @@ const { buildContent, avatar } = global.Hydro.lib;
let { template } = argv.options; let { template } = argv.options;
if (template && typeof template !== 'string') template = findFileSync('@hydrooj/ui-default/templates'); 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 { class Loader extends nunjucks.Loader {
// eslint-disable-next-line class-methods-use-this
getSource(name) { getSource(name) {
if (!template) { if (!template) {
if (!global.Hydro.ui.template[name]) throw new Error(`Cannot get template ${name}`); 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 || {})._original) obj = obj._original;
if (obj === undefined || obj === null) return undefined; if (obj === undefined || obj === null) return undefined;
if (typeof obj[val] === 'function') { if (typeof obj[val] === 'function') {
const fn = function () { const fn = function (...args) {
// 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
return obj[val].call(obj, ...args); return obj[val].call(obj, ...args);
}; };
fn._original = obj[val]; 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]); env.addGlobal('templateExists', (name) => !!global.Hydro.ui.template[name]);
async function render(name, state) { async function render(name, state) {
// eslint-disable-next-line no-return-await
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
env.render(name, { env.render(name, {
page_name: name.split('.')[0], page_name: name.split('.')[0],
+1 -1
View File
@@ -16,7 +16,7 @@ export interface EventMap extends Record<string, any> {
} }
function getHooks<K extends keyof EventMap>(name: K) { function getHooks<K extends keyof EventMap>(name: K) {
const hooks = _hooks[name] || (_hooks[name] = []); const hooks = (_hooks[name] ||= []);
if (hooks.length >= 2048) { if (hooks.length >= 2048) {
console.warn( console.warn(
'max listener count (2048) for event "%s" exceeded, which may be caused by a memory leak', 'max listener count (2048) for event "%s" exceeded, which may be caused by a memory leak',
@@ -122,7 +122,7 @@ const AutoComplete = forwardRef(function Impl<T>(props: AutoCompleteProps<T>, re
setCurrentItem(null); setCurrentItem(null);
return; return;
} }
if (!queryCache[query]) queryCache[query] = await queryItems(query); queryCache[query] ||= await queryItems(query);
for (const item of queryCache[query]) valueCache[itemKey(item)] = item; for (const item of queryCache[query]) valueCache[itemKey(item)] = item;
setItemList(queryCache[query]); setItemList(queryCache[query]);
setCurrentItem((!freeSolo && queryCache[query].length > 0) ? 0 : null); setCurrentItem((!freeSolo && queryCache[query].length > 0) ? 0 : null);
@@ -349,7 +349,7 @@ export default class Calendar {
}; };
banner.endAt = banner.event.maskFrom.clone().subtract(1, 'day'); banner.endAt = banner.event.maskFrom.clone().subtract(1, 'day');
banner.endSnap = true; 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); bannerSpans.splice(i + 1, 0, newBannerSpan);
i++; i++;
} }
@@ -38,7 +38,6 @@ function Reaction({ payload, ele }) {
const [finish, updateFinish] = React.useState(false); const [finish, updateFinish] = React.useState(false);
if (finish) setTimeout(() => updateFinish(false), 1000); if (finish) setTimeout(() => updateFinish(false), 1000);
return ( return (
// eslint-disable-next-line no-nested-ternary
<Popover usePortal interactionKind="hover" isOpen={finish ? false : (focus ? true : undefined)}> <Popover usePortal interactionKind="hover" isOpen={finish ? false : (focus ? true : undefined)}>
<span className="icon icon-emoji"></span> <span className="icon icon-emoji"></span>
<div> <div>
@@ -26,7 +26,6 @@ export const config = {
inlineDigit: true, inlineDigit: true,
}, },
theme: { theme: {
// eslint-disable-next-line no-template-curly-in-string
path: `${UiContext.cdn_prefix}vditor/dist/css/content-theme`, path: `${UiContext.cdn_prefix}vditor/dist/css/content-theme`,
current: 'light', current: 'light',
}, },
@@ -81,7 +80,6 @@ export default class Editor extends DOMAttachedObject {
$dom.hide(); $dom.hide();
origin.parentElement.appendChild(ele); origin.parentElement.appendChild(ele);
const value = this.options.value || $dom.val(); const value = this.options.value || $dom.val();
// eslint-disable-next-line no-nested-ternary
this.model = typeof model === 'string' this.model = typeof model === 'string'
? monaco.editor.getModel(monaco.Uri.parse(model)) ? monaco.editor.getModel(monaco.Uri.parse(model))
|| monaco.editor.createModel(value, language === 'auto' ? undefined : language, monaco.Uri.parse(model)) || monaco.editor.createModel(value, language === 'auto' ? undefined : language, monaco.Uri.parse(model))
@@ -31,7 +31,6 @@ loadLanguages();
languageMeta.forEach((meta) => { languageMeta.forEach((meta) => {
for (let i = 0; i < meta.ext.length; ++i) { for (let i = 0; i < meta.ext.length; ++i) {
if (Prism.languages[meta.ext[i]] !== undefined) { if (Prism.languages[meta.ext[i]] !== undefined) {
// eslint-disable-next-line no-param-reassign
meta.target = meta.ext[i]; meta.target = meta.ext[i];
break; break;
} }
@@ -44,7 +43,7 @@ languageMeta.forEach((meta) => {
// Copy to Clipboard // Copy to Clipboard
Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => { Prism.plugins.toolbar.registerButton('copy-to-clipboard', (env) => {
const linkCopy = document.createElement('a'); const linkCopy = document.createElement('a');
linkCopy.href = 'javascript:;'; // eslint-disable-line no-script-url linkCopy.href = 'javascript:;';
linkCopy.textContent = 'Copy'; linkCopy.textContent = 'Copy';
const clip = new Clipboard(linkCopy, { text: () => env.code }); const clip = new Clipboard(linkCopy, { text: () => env.code });
clip.on('success', () => { clip.on('success', () => {
@@ -89,8 +88,8 @@ function handlerInvisiblesToken(tokens, name) {
} else if (type === 'Array') { } else if (type === 'Array') {
for (let i = 0, l = value.length; i < l; i++) handlerInvisiblesToken(value, i); for (let i = 0, l = value.length; i < l; i++) handlerInvisiblesToken(value, i);
} else { } else {
const inside = value.inside || (value.inside = {}); value.inside ||= {};
addInvisibles(inside); addInvisibles(value.inside);
} }
} }
@@ -49,7 +49,7 @@ export default connect(mapStateToProps)(class MessagePadDialogueContentContainer
const data = JSON.parse(msg.content); const data = JSON.parse(msg.content);
const str = i18n(data.message).replace(/\{([^{}]+)\}/g, (match, key) => `%placeholder%${key}%placeholder%`); const str = i18n(data.message).replace(/\{([^{}]+)\}/g, (match, key) => `%placeholder%${key}%placeholder%`);
const arr = str.split('%placeholder%'); const arr = str.split('%placeholder%');
data.params = data.params || {}; data.params ||= {};
for (let i = 1; i < arr.length; i += 2) { for (let i = 1; i < arr.length; i += 2) {
if (arr[i].endsWith(':link')) { if (arr[i].endsWith(':link')) {
const link = data.params[arr[i].split(':link')[0]]; const link = data.params[arr[i].split(':link')[0]];
+1 -1
View File
@@ -16,7 +16,7 @@ function format(message, args) {
export const getConfiguredDefaultLocale = () => 'zh'; export const getConfiguredDefaultLocale = () => 'zh';
let CURRENT_LOCALE_DATA = {}; let CURRENT_LOCALE_DATA = {}; // eslint-disable-line @typescript-eslint/naming-convention
function find(path, message) { function find(path, message) {
for (const key of Object.keys(CURRENT_LOCALE_DATA)) { for (const key of Object.keys(CURRENT_LOCALE_DATA)) {
@@ -120,7 +120,7 @@ export async function previewFile(ev?, type = '') {
if (ev) { if (ev) {
const link = $(ev.currentTarget).find('a').attr('href'); const link = $(ev.currentTarget).find('a').attr('href');
if (!link) return null; if (!link) return null;
if (!type) type = ev.currentTarget.getAttribute('data-preview'); type ||= ev.currentTarget.getAttribute('data-preview');
const ext = filename.split('.').pop(); const ext = filename.split('.').pop();
if (['zip', 'rar', '7z'].includes(ext) || filesize > 8 * 1024 * 1024) { if (['zip', 'rar', '7z'].includes(ext) || filesize > 8 * 1024 * 1024) {
const action = await new ActionDialog({ const action = await new ActionDialog({
@@ -34,7 +34,7 @@ const votePage = new AutoloadPage('votePage', () => {
setVoteState($container, data.vote, data.user_vote); setVoteState($container, data.vote, data.user_vote);
}) })
.catch((e) => { .catch((e) => {
Notification.error(`Failed to vote: ${ e.message}`); Notification.error(`Failed to vote: ${e.message}`);
}); });
return false; return false;
}); });
-1
View File
@@ -135,7 +135,6 @@ class RichMediaHandler extends Handler {
} }
} }
// eslint-disable-next-line import/prefer-default-export
export function apply(ctx: Context) { export function apply(ctx: Context) {
if (process.env.HYDRO_CLI) return; if (process.env.HYDRO_CLI) return;
ctx.Route('wiki_help', '/wiki/help', WikiHelpHandler); ctx.Route('wiki_help', '/wiki/help', WikiHelpHandler);
@@ -86,7 +86,7 @@ export default new AutoloadPage('user_verify', () => {
const { authn, tfa } = info.uname || info.mail; const { authn, tfa } = info.uname || info.mail;
if (authn || tfa) { if (authn || tfa) {
let action = (authn && tfa) ? await chooseAction(true) : ''; let action = (authn && tfa) ? await chooseAction(true) : '';
if (!action) action = tfa ? await chooseAction(false) : 'webauthn'; action ||= tfa ? await chooseAction(false) : 'webauthn';
if (action === 'webauthn') { if (action === 'webauthn') {
const challenge = await verifywebauthn($form); const challenge = await verifywebauthn($form);
if (challenge) $form['authnChallenge'].value = challenge; if (challenge) $form['authnChallenge'].value = challenge;
+1 -2
View File
@@ -25,11 +25,10 @@ import 'vj/misc/section.styl';
import 'vj/misc/nothing.styl'; import 'vj/misc/nothing.styl';
import 'vj/components/editor/cmeditor.styl'; import 'vj/components/editor/cmeditor.styl';
import 'vj/components/datepicker/datepicker.styl'; import 'vj/components/datepicker/datepicker.styl';
import './dark.styl';
// load all page stylesheets // load all page stylesheets
const pageStyleReq = require.context('../', true, /\.page\.styl$/i); const pageStyleReq = require.context('../', true, /\.page\.styl$/i);
pageStyleReq.keys().map((key) => pageStyleReq(key)); pageStyleReq.keys().map((key) => pageStyleReq(key));
const pageStyleReqDefault = require.context('../', true, /\.page\.default\.styl$/i); const pageStyleReqDefault = require.context('../', true, /\.page\.default\.styl$/i);
pageStyleReqDefault.keys().map((key) => pageStyleReqDefault(key)); pageStyleReqDefault.keys().map((key) => pageStyleReqDefault(key));
import './dark.styl';
+4 -4
View File
@@ -11,7 +11,7 @@ const Base64 = {
let enc3; let enc3;
let enc4; let enc4;
let i = 0; let i = 0;
input = Base64._utf8_encode(input); input = Base64._utf8Encode(input);
while (i < input.length) { while (i < input.length) {
chr1 = input.charCodeAt(i++); chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++);
@@ -52,11 +52,11 @@ const Base64 = {
if (enc3 !== 64) output += String.fromCharCode(chr2); if (enc3 !== 64) output += String.fromCharCode(chr2);
if (enc4 !== 64) output += String.fromCharCode(chr3); if (enc4 !== 64) output += String.fromCharCode(chr3);
} }
output = Base64._utf8_decode(output); output = Base64._utf8Decode(output);
return output; return output;
}, },
_utf8_encode(string) { _utf8Encode(string) {
string = string.replace(/\r\n/g, '\n'); string = string.replace(/\r\n/g, '\n');
let utftext = ''; let utftext = '';
for (let n = 0; n < string.length; n++) { for (let n = 0; n < string.length; n++) {
@@ -75,7 +75,7 @@ const Base64 = {
return utftext; return utftext;
}, },
_utf8_decode(utftext) { _utf8Decode(utftext) {
let string = ''; let string = '';
let i = 0; let i = 0;
let c = 0; let c = 0;
-2
View File
@@ -67,7 +67,6 @@ export async function pipeStream(read, write, abort) {
} }
// https://github.com/andrasq/node-mongoid-js/blob/master/mongoid.js // https://github.com/andrasq/node-mongoid-js/blob/master/mongoid.js
/* eslint-disable */
export function mongoId(idstring: string) { export function mongoId(idstring: string) {
if (typeof idstring !== 'string') idstring = String(idstring); if (typeof idstring !== 'string') idstring = String(idstring);
return { return {
@@ -77,7 +76,6 @@ export function mongoId(idstring: string) {
sequence: parseInt(idstring.slice(18, 18 + 6), 16), sequence: parseInt(idstring.slice(18, 18 + 6), 16),
}; };
} }
/* eslint-enable */
const loaded = {}; const loaded = {};