fix(client): fix lint issues in scripts (#8621)

This commit is contained in:
Andreas Nedbal 2022-05-07 07:19:15 +02:00 committed by GitHub
parent ad860905c6
commit a975a0971c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 75 additions and 85 deletions

View File

@ -1,11 +1,11 @@
export function byteify(data: string, encoding: 'ascii' | 'base64' | 'hex') { export function byteify(string: string, encoding: 'ascii' | 'base64' | 'hex') {
switch (encoding) { switch (encoding) {
case 'ascii': case 'ascii':
return Uint8Array.from(data, c => c.charCodeAt(0)); return Uint8Array.from(string, c => c.charCodeAt(0));
case 'base64': case 'base64':
return Uint8Array.from( return Uint8Array.from(
atob( atob(
data string
.replace(/-/g, '+') .replace(/-/g, '+')
.replace(/_/g, '/') .replace(/_/g, '/')
), ),
@ -13,7 +13,7 @@ export function byteify(data: string, encoding: 'ascii' | 'base64' | 'hex') {
); );
case 'hex': case 'hex':
return new Uint8Array( return new Uint8Array(
data string
.match(/.{1,2}/g) .match(/.{1,2}/g)
.map(byte => parseInt(byte, 16)) .map(byte => parseInt(byte, 16))
); );

View File

@ -74,21 +74,21 @@ export class Autocomplete {
emojiIndex, emojiIndex,
mfmTagIndex); mfmTagIndex);
if (max == -1) { if (max === -1) {
this.close(); this.close();
return; return;
} }
const isMention = mentionIndex != -1; const isMention = mentionIndex !== -1;
const isHashtag = hashtagIndex != -1; const isHashtag = hashtagIndex !== -1;
const isMfmTag = mfmTagIndex != -1; const isMfmTag = mfmTagIndex !== -1;
const isEmoji = emojiIndex != -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':'); const isEmoji = emojiIndex !== -1 && text.split(/:[a-z0-9_+\-]+:/).pop()!.includes(':');
let opened = false; let opened = false;
if (isMention) { if (isMention) {
const username = text.substr(mentionIndex + 1); const username = text.substr(mentionIndex + 1);
if (username != '' && username.match(/^[a-zA-Z0-9_]+$/)) { if (username !== '' && username.match(/^[a-zA-Z0-9_]+$/)) {
this.open('user', username); this.open('user', username);
opened = true; opened = true;
} else if (username === '') { } else if (username === '') {
@ -130,7 +130,7 @@ export class Autocomplete {
* *
*/ */
private async open(type: string, q: string | null) { private async open(type: string, q: string | null) {
if (type != this.currentType) { if (type !== this.currentType) {
this.close(); this.close();
} }
if (this.opening) return; if (this.opening) return;
@ -201,7 +201,7 @@ export class Autocomplete {
const caret = this.textarea.selectionStart; const caret = this.textarea.selectionStart;
if (type == 'user') { if (type === 'user') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substr(0, caret);
@ -219,7 +219,7 @@ export class Autocomplete {
const pos = trimmedBefore.length + (acct.length + 2); const pos = trimmedBefore.length + (acct.length + 2);
this.textarea.setSelectionRange(pos, pos); this.textarea.setSelectionRange(pos, pos);
}); });
} else if (type == 'hashtag') { } else if (type === 'hashtag') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substr(0, caret);
@ -235,7 +235,7 @@ export class Autocomplete {
const pos = trimmedBefore.length + (value.length + 2); const pos = trimmedBefore.length + (value.length + 2);
this.textarea.setSelectionRange(pos, pos); this.textarea.setSelectionRange(pos, pos);
}); });
} else if (type == 'emoji') { } else if (type === 'emoji') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substr(0, caret);
@ -251,7 +251,7 @@ export class Autocomplete {
const pos = trimmedBefore.length + value.length; const pos = trimmedBefore.length + value.length;
this.textarea.setSelectionRange(pos, pos); this.textarea.setSelectionRange(pos, pos);
}); });
} else if (type == 'mfmTag') { } else if (type === 'mfmTag') {
const source = this.text; const source = this.text;
const before = source.substr(0, caret); const before = source.substr(0, caret);

View File

@ -2,7 +2,7 @@ export default (parent, child, checkSame = true) => {
if (checkSame && parent === child) return true; if (checkSame && parent === child) return true;
let node = child.parentNode; let node = child.parentNode;
while (node) { while (node) {
if (node == parent) return true; if (node === parent) return true;
node = node.parentNode; node = node.parentNode;
} }
return false; return false;

View File

@ -1,5 +1,5 @@
export function extractAvgColorFromBlurhash(hash: string) { export function extractAvgColorFromBlurhash(hash: string) {
return typeof hash == 'string' return typeof hash === 'string'
? '#' + [...hash.slice(2, 6)] ? '#' + [...hash.slice(2, 6)]
.map(x => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~'.indexOf(x)) .map(x => '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~'.indexOf(x))
.reduce((a, c) => a * 83 + c, 0) .reduce((a, c) => a * 83 + c, 0)

View File

@ -3,5 +3,5 @@ import { get } from '@/scripts/idb-proxy';
export async function getAccountFromId(id: string) { export async function getAccountFromId(id: string) {
const accounts = await get('accounts') as { token: string; id: string; }[]; const accounts = await get('accounts') as { token: string; id: string; }[];
if (!accounts) console.log('Accounts are not recorded'); if (!accounts) console.log('Accounts are not recorded');
return accounts.find(e => e.id === id); return accounts.find(account => account.id === id);
} }

View File

@ -1,10 +0,0 @@
// スクリプトサイズがデカい
//import * as crypto from 'crypto';
export default (data: ArrayBuffer) => {
//const buf = new Buffer(data);
//const hash = crypto.createHash('md5');
//hash.update(buf);
//return hash.digest('hex');
return '';
};

View File

@ -83,8 +83,8 @@ export function getNoteMenu(props: {
function togglePin(pin: boolean): void { function togglePin(pin: boolean): void {
os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', { os.apiWithDialog(pin ? 'i/pin' : 'i/unpin', {
noteId: appearNote.id noteId: appearNote.id
}, undefined, null, e => { }, undefined, null, res => {
if (e.id === '72dab508-c64d-498f-8740-a8eec1ba385a') { if (res.id === '72dab508-c64d-498f-8740-a8eec1ba385a') {
os.alert({ os.alert({
type: 'error', type: 'error',
text: i18n.ts.pinLimitExceeded text: i18n.ts.pinLimitExceeded
@ -209,7 +209,7 @@ export function getNoteMenu(props: {
text: i18n.ts.clip, text: i18n.ts.clip,
action: () => clip() action: () => clip()
}, },
(appearNote.userId != $i.id) ? statePromise.then(state => state.isWatching ? { (appearNote.userId !== $i.id) ? statePromise.then(state => state.isWatching ? {
icon: 'fas fa-eye-slash', icon: 'fas fa-eye-slash',
text: i18n.ts.unwatch, text: i18n.ts.unwatch,
action: () => toggleWatch(false) action: () => toggleWatch(false)
@ -227,7 +227,7 @@ export function getNoteMenu(props: {
text: i18n.ts.muteThread, text: i18n.ts.muteThread,
action: () => toggleThreadMute(true) action: () => toggleThreadMute(true)
}), }),
appearNote.userId == $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? { appearNote.userId === $i.id ? ($i.pinnedNoteIds || []).includes(appearNote.id) ? {
icon: 'fas fa-thumbtack', icon: 'fas fa-thumbtack',
text: i18n.ts.unpin, text: i18n.ts.unpin,
action: () => togglePin(false) action: () => togglePin(false)
@ -246,7 +246,7 @@ export function getNoteMenu(props: {
}] }]
: [] : []
),*/ ),*/
...(appearNote.userId != $i.id ? [ ...(appearNote.userId !== $i.id ? [
null, null,
{ {
icon: 'fas fa-exclamation-circle', icon: 'fas fa-exclamation-circle',
@ -261,9 +261,9 @@ export function getNoteMenu(props: {
}] }]
: [] : []
), ),
...(appearNote.userId == $i.id || $i.isModerator || $i.isAdmin ? [ ...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin ? [
null, null,
appearNote.userId == $i.id ? { appearNote.userId === $i.id ? {
icon: 'fas fa-edit', icon: 'fas fa-edit',
text: i18n.ts.deleteAndEdit, text: i18n.ts.deleteAndEdit,
action: delEdit action: delEdit

View File

@ -24,7 +24,7 @@ export const getNoteSummary = (note: misskey.entities.Note): string => {
} }
// ファイルが添付されているとき // ファイルが添付されているとき
if ((note.files || []).length != 0) { if ((note.files || []).length !== 0) {
summary += ` (${i18n.t('withNFiles', { n: note.files.length })})`; summary += ` (${i18n.t('withNFiles', { n: note.files.length })})`;
} }

View File

@ -169,7 +169,7 @@ export function getUserMenu(user) {
action: () => { action: () => {
os.post({ specified: user }); os.post({ specified: user });
} }
}, meId != user.id ? { }, meId !== user.id ? {
type: 'link', type: 'link',
icon: 'fas fa-comments', icon: 'fas fa-comments',
text: i18n.ts.startMessaging, text: i18n.ts.startMessaging,
@ -178,13 +178,13 @@ export function getUserMenu(user) {
icon: 'fas fa-list-ul', icon: 'fas fa-list-ul',
text: i18n.ts.addToList, text: i18n.ts.addToList,
action: pushList action: pushList
}, meId != user.id ? { }, meId !== user.id ? {
icon: 'fas fa-users', icon: 'fas fa-users',
text: i18n.ts.inviteToGroup, text: i18n.ts.inviteToGroup,
action: inviteGroup action: inviteGroup
} : undefined] as any; } : undefined] as any;
if ($i && meId != user.id) { if ($i && meId !== user.id) {
menu = menu.concat([null, { menu = menu.concat([null, {
icon: user.isMuted ? 'fas fa-eye' : 'fas fa-eye-slash', icon: user.isMuted ? 'fas fa-eye' : 'fas fa-eye-slash',
text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute, text: user.isMuted ? i18n.ts.unmute : i18n.ts.mute,

View File

@ -53,34 +53,34 @@ const parseKeymap = (keymap: Keymap) => Object.entries(keymap).map(([patterns, c
const ignoreElemens = ['input', 'textarea']; const ignoreElemens = ['input', 'textarea'];
function match(e: KeyboardEvent, patterns: Action['patterns']): boolean { function match(ev: KeyboardEvent, patterns: Action['patterns']): boolean {
const key = e.code.toLowerCase(); const key = ev.code.toLowerCase();
return patterns.some(pattern => pattern.which.includes(key) && return patterns.some(pattern => pattern.which.includes(key) &&
pattern.ctrl === e.ctrlKey && pattern.ctrl === ev.ctrlKey &&
pattern.shift === e.shiftKey && pattern.shift === ev.shiftKey &&
pattern.alt === e.altKey && pattern.alt === ev.altKey &&
!e.metaKey !ev.metaKey
); );
} }
export const makeHotkey = (keymap: Keymap) => { export const makeHotkey = (keymap: Keymap) => {
const actions = parseKeymap(keymap); const actions = parseKeymap(keymap);
return (e: KeyboardEvent) => { return (ev: KeyboardEvent) => {
if (document.activeElement) { if (document.activeElement) {
if (ignoreElemens.some(el => document.activeElement!.matches(el))) return; if (ignoreElemens.some(el => document.activeElement!.matches(el))) return;
if (document.activeElement.attributes['contenteditable']) return; if (document.activeElement.attributes['contenteditable']) return;
} }
for (const action of actions) { for (const action of actions) {
const matched = match(e, action.patterns); const matched = match(ev, action.patterns);
if (matched) { if (matched) {
if (!action.allowRepeat && e.repeat) return; if (!action.allowRepeat && ev.repeat) return;
e.preventDefault(); ev.preventDefault();
e.stopPropagation(); ev.stopPropagation();
action.callback(e); action.callback(ev);
break; break;
} }
} }

View File

@ -85,7 +85,7 @@ export class Hpml {
public eval() { public eval() {
try { try {
this.vars.value = this.evaluateVars(); this.vars.value = this.evaluateVars();
} catch (e) { } catch (err) {
//this.onError(e); //this.onError(e);
} }
} }
@ -103,7 +103,7 @@ export class Hpml {
public callAiScript(fn: string) { public callAiScript(fn: string) {
try { try {
if (this.aiscript) this.aiscript.execFn(this.aiscript.scope.get(fn), []); if (this.aiscript) this.aiscript.execFn(this.aiscript.scope.get(fn), []);
} catch (e) {} } catch (err) {}
} }
@autobind @autobind
@ -185,7 +185,7 @@ export class Hpml {
if (this.aiscript) { if (this.aiscript) {
try { try {
return utils.valToJs(this.aiscript.scope.get(expr.value)); return utils.valToJs(this.aiscript.scope.get(expr.value));
} catch (e) { } catch (err) {
return null; return null;
} }
} else { } else {
@ -194,7 +194,7 @@ export class Hpml {
} }
// Define user function // Define user function
if (expr.type == 'fn') { if (expr.type === 'fn') {
return { return {
slots: expr.value.slots.map(x => x.name), slots: expr.value.slots.map(x => x.name),
exec: (slotArg: Record<string, any>) => { exec: (slotArg: Record<string, any>) => {

View File

@ -13,8 +13,8 @@ let idbAvailable = typeof window !== 'undefined' ? !!window.indexedDB : true;
if (idbAvailable) { if (idbAvailable) {
try { try {
await iset('idb-test', 'test'); await iset('idb-test', 'test');
} catch (e) { } catch (err) {
console.error('idb error', e); console.error('idb error', err);
idbAvailable = false; idbAvailable = false;
} }
} }

View File

@ -25,12 +25,12 @@ export async function lookupUser() {
_notFound = true; _notFound = true;
} }
}; };
usernamePromise.then(show).catch(e => { usernamePromise.then(show).catch(err => {
if (e.code === 'NO_SUCH_USER') { if (err.code === 'NO_SUCH_USER') {
notFound(); notFound();
} }
}); });
idPromise.then(show).catch(e => { idPromise.then(show).catch(err => {
notFound(); notFound();
}); });
} }

View File

@ -19,10 +19,10 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
Promise.all(promises).then(driveFiles => { Promise.all(promises).then(driveFiles => {
res(multiple ? driveFiles : driveFiles[0]); res(multiple ? driveFiles : driveFiles[0]);
}).catch(e => { }).catch(err => {
os.alert({ os.alert({
type: 'error', type: 'error',
text: e text: err
}); });
}); });
@ -54,9 +54,9 @@ function select(src: any, label: string | null, multiple: boolean): Promise<Driv
const marker = Math.random().toString(); // TODO: UUIDとか使う const marker = Math.random().toString(); // TODO: UUIDとか使う
const connection = stream.useChannel('main'); const connection = stream.useChannel('main');
connection.on('urlUploadFinished', data => { connection.on('urlUploadFinished', urlResponse => {
if (data.marker === marker) { if (urlResponse.marker === marker) {
res(multiple ? [data.file] : data.file); res(multiple ? [urlResponse.file] : urlResponse.file);
connection.dispose(); connection.dispose();
} }
}); });

View File

@ -33,13 +33,13 @@ export function uploadFile(
name?: string, name?: string,
keepOriginal: boolean = defaultStore.state.keepOriginalUploading keepOriginal: boolean = defaultStore.state.keepOriginalUploading
): Promise<Misskey.entities.DriveFile> { ): Promise<Misskey.entities.DriveFile> {
if (folder && typeof folder == 'object') folder = folder.id; if (folder && typeof folder === 'object') folder = folder.id;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const id = Math.random().toString(); const id = Math.random().toString();
const reader = new FileReader(); const reader = new FileReader();
reader.onload = async (e) => { reader.onload = async (ev) => {
const ctx = reactive<Uploading>({ const ctx = reactive<Uploading>({
id: id, id: id,
name: name || file.name || 'untitled', name: name || file.name || 'untitled',
@ -64,24 +64,24 @@ export function uploadFile(
try { try {
resizedImage = await readAndCompressImage(file, config); resizedImage = await readAndCompressImage(file, config);
ctx.name = file.type !== imgConfig.mimeType ? `${ctx.name}.${mimeTypeMap[compressTypeMap[file.type].mimeType]}` : ctx.name; ctx.name = file.type !== imgConfig.mimeType ? `${ctx.name}.${mimeTypeMap[compressTypeMap[file.type].mimeType]}` : ctx.name;
} catch (e) { } catch (err) {
console.error('Failed to resize image', e); console.error('Failed to resize image', err);
} }
} }
const data = new FormData(); const formData = new FormData();
data.append('i', $i.token); formData.append('i', $i.token);
data.append('force', 'true'); formData.append('force', 'true');
data.append('file', resizedImage || file); formData.append('file', resizedImage || file);
data.append('name', ctx.name); formData.append('name', ctx.name);
if (folder) data.append('folderId', folder); if (folder) formData.append('folderId', folder);
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.open('POST', apiUrl + '/drive/files/create', true); xhr.open('POST', apiUrl + '/drive/files/create', true);
xhr.onload = (ev) => { xhr.onload = (ev) => {
if (xhr.status !== 200 || ev.target == null || ev.target.response == null) { if (xhr.status !== 200 || ev.target == null || ev.target.response == null) {
// TODO: 消すのではなくて再送できるようにしたい // TODO: 消すのではなくて再送できるようにしたい
uploads.value = uploads.value.filter(x => x.id != id); uploads.value = uploads.value.filter(x => x.id !== id);
alert({ alert({
type: 'error', type: 'error',
@ -97,17 +97,17 @@ export function uploadFile(
resolve(driveFile); resolve(driveFile);
uploads.value = uploads.value.filter(x => x.id != id); uploads.value = uploads.value.filter(x => x.id !== id);
}; };
xhr.upload.onprogress = e => { xhr.upload.onprogress = ev => {
if (e.lengthComputable) { if (ev.lengthComputable) {
ctx.progressMax = e.total; ctx.progressMax = ev.total;
ctx.progressValue = e.loaded; ctx.progressValue = ev.loaded;
} }
}; };
xhr.send(data); xhr.send(formData);
}; };
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);
}); });

View File

@ -4,7 +4,7 @@ export function query(obj: {}): string {
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>); .reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>);
return Object.entries(params) return Object.entries(params)
.map((e) => `${e[0]}=${encodeURIComponent(e[1])}`) .map((p) => `${p[0]}=${encodeURIComponent(p[1])}`)
.join('&'); .join('&');
} }

View File

@ -11,8 +11,8 @@ export function useNoteCapture(props: {
const note = props.note; const note = props.note;
const connection = $i ? stream : null; const connection = $i ? stream : null;
function onStreamNoteUpdated(data): void { function onStreamNoteUpdated(noteData): void {
const { type, id, body } = data; const { type, id, body } = noteData;
if (id !== note.value.id) return; if (id !== note.value.id) return;