mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
workspace: add eslint-config package (#510)
This commit is contained in:
1 parent
e7945a104f
commit
65311529bd
28 files changed
+230
-267
No files matched your search
@@ -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'] }],
|
||||
// 'template-curly-spacing': 'off',
|
||||
|
||||
// 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 },
|
||||
],
|
||||
|
||||
'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',
|
||||
},
|
||||
};
|
||||
@@ -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<string, any>;
|
||||
}
|
||||
|
||||
let UserContext: Record<string, any>;
|
||||
let UiContext: Record<string, any>;
|
||||
let UserContext: Record<string, any>; // eslint-disable-line
|
||||
let UiContext: Record<string, any>; // eslint-disable-line
|
||||
}
|
||||
|
||||
// Below are old version api compat
|
||||
/* eslint-disable import/order */
|
||||
import $ from 'jquery';
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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],
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface EventMap extends Record<string, any> {
|
||||
}
|
||||
|
||||
function getHooks<K extends keyof EventMap>(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',
|
||||
|
||||
@@ -122,7 +122,7 @@ const AutoComplete = forwardRef(function Impl<T>(props: AutoCompleteProps<T>, 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);
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
<Popover usePortal interactionKind="hover" isOpen={finish ? false : (focus ? true : undefined)}>
|
||||
<span className="icon icon-emoji"></span>
|
||||
<div>
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]];
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = {};
|
||||
|
||||
|
||||
Reference in new issue
Block a user