From 7e975dd1165e78acc9cff5fb56a6f128536a68c1 Mon Sep 17 00:00:00 2001 From: rinsuki <428rinsuki+git@gmail.com> Date: Wed, 4 Mar 2020 11:45:33 +0900 Subject: [PATCH] =?UTF-8?q?lint=E3=82=92GitHub=20Actions=20=E3=81=A7?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(#6101)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * package.json の lint スクリプトを修正 * lint アクションを追加 * yarn lint --fix * 手動修正 --- .github/workflows/nodejs.yml | 10 ++++++++++ package.json | 2 +- src/@types/jsrsasign.d.ts | 9 +++------ src/client/directives/size.ts | 2 +- src/client/init.ts | 4 ++-- src/client/mios.ts | 2 +- src/misc/check-hit-antenna.ts | 4 ++-- src/models/entities/clip-note.ts | 2 +- src/models/repositories/user.ts | 4 ++-- src/server/api/endpoints/antennas/create.ts | 4 ++-- src/server/api/endpoints/antennas/update.ts | 4 ++-- src/server/api/stream/channels/main.ts | 3 ++- src/services/add-note-to-antenna.ts | 2 +- src/services/note/create.ts | 2 +- tslint.json | 4 +++- 15 files changed, 34 insertions(+), 24 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index d8c29abc3..91668786e 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -41,3 +41,13 @@ jobs: run: yarn build - name: Test run: yarn test + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: yarn install + - run: yarn lint diff --git a/package.json b/package.json index 4fc350cc2..fa66bdcf6 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "gulp": "gulp build", "clean": "gulp clean", "cleanall": "gulp cleanall", - "lint": "gulp lint", + "lint": "tslint 'src/**/*.ts'", "test": "cross-env TS_NODE_FILES=true gulp test", "format": "gulp format" }, diff --git a/src/@types/jsrsasign.d.ts b/src/@types/jsrsasign.d.ts index 55bebd9bf..bc9d746f7 100644 --- a/src/@types/jsrsasign.d.ts +++ b/src/@types/jsrsasign.d.ts @@ -171,6 +171,7 @@ declare module 'jsrsasign' { public static getTLVbyList(h: ASN1S, currentIndex: Idx, nthList: Mutable, checkingTag?: string): ASN1TLV; + // tslint:disable-next-line:bool-param-default public static getVbyList(h: ASN1S, currentIndex: Idx, nthList: Mutable, checkingTag?: string, removeUnusedbits?: boolean): ASN1V; public static hextooidstr(hex: ASN1OIDV): OID; @@ -620,9 +621,7 @@ declare module 'jsrsasign' { public encrypt(text: string): HexString | null; - public encryptOAEP(text: string, hash?: string, hashLen?: number): HexString | null; - - public encryptOAEP(text: string, hash?: (s: string) => string, hashLen?: number): HexString | null; + public encryptOAEP(text: string, hash?: string | ((s: string) => string), hashLen?: number): HexString | null; //// RSA PRIVATE @@ -638,9 +637,7 @@ declare module 'jsrsasign' { public decrypt(ctext: HexString): string; - public decryptOAEP(ctext: HexString, hash?: string, hashLen?: number): string | null; - - public encryptOAEP(ctext: HexString, hash?: (s: string) => string, hashLen?: number): string | null; + public decryptOAEP(ctext: HexString, hash?: string | ((s: string) => string), hashLen?: number): string | null; //// RSA PEM diff --git a/src/client/directives/size.ts b/src/client/directives/size.ts index c4dd7b145..541f38fd7 100644 --- a/src/client/directives/size.ts +++ b/src/client/directives/size.ts @@ -59,7 +59,7 @@ export default { const ro = new ResizeObserver((entries, observer) => { calc(); }); - + ro.observe(el); el._ro_ = ro; diff --git a/src/client/init.ts b/src/client/init.ts index 2f2f9f5d5..29eabfee4 100644 --- a/src/client/init.ts +++ b/src/client/init.ts @@ -81,14 +81,14 @@ if (lang == null) { // Detect the user agent const ua = navigator.userAgent.toLowerCase(); -let isMobile = /mobile|iphone|ipad|android/.test(ua); +const isMobile = /mobile|iphone|ipad|android/.test(ua); // Get the element const head = document.getElementsByTagName('head')[0]; // If mobile, insert the viewport meta tag if (isMobile || window.innerWidth <= 1024) { - const viewport = document.getElementsByName("viewport").item(0); + const viewport = document.getElementsByName('viewport').item(0); viewport.setAttribute('content', `${viewport.getAttribute('content')},minimum-scale=1,maximum-scale=1,user-scalable=no`); head.appendChild(viewport); diff --git a/src/client/mios.ts b/src/client/mios.ts index a29dcd855..c2ba8ac5c 100644 --- a/src/client/mios.ts +++ b/src/client/mios.ts @@ -124,7 +124,7 @@ export default class MiOS extends EventEmitter { } else { // Get token from localStorage const i = localStorage.getItem('i'); - + fetchme(i, me => { if (me) { this.store.dispatch('login', me); diff --git a/src/misc/check-hit-antenna.ts b/src/misc/check-hit-antenna.ts index 0d72c3f34..fa2479498 100644 --- a/src/misc/check-hit-antenna.ts +++ b/src/misc/check-hit-antenna.ts @@ -48,7 +48,7 @@ export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: Us ? note.text!.includes(keyword) : note.text!.toLowerCase().includes(keyword.toLowerCase()) )); - + if (!matched) return false; } @@ -61,7 +61,7 @@ export async function checkHitAntenna(antenna: Antenna, note: Note, noteUser: Us ? note.text!.includes(keyword) : note.text!.toLowerCase().includes(keyword.toLowerCase()) )); - + if (matched) return false; } diff --git a/src/models/entities/clip-note.ts b/src/models/entities/clip-note.ts index 19e4750fc..7d96b2ef7 100644 --- a/src/models/entities/clip-note.ts +++ b/src/models/entities/clip-note.ts @@ -8,7 +8,7 @@ import { id } from '../id'; export class ClipNote { @PrimaryColumn(id()) public id: string; - + @Index() @Column({ ...id(), diff --git a/src/models/repositories/user.ts b/src/models/repositories/user.ts index 1d669feb5..c6bc35030 100644 --- a/src/models/repositories/user.ts +++ b/src/models/repositories/user.ts @@ -98,7 +98,7 @@ export class UserRepository extends Repository { public async getHasUnreadAntenna(userId: User['id']): Promise { const antennas = await Antennas.find({ userId }); - + const unread = antennas.length > 0 ? await AntennaNotes.findOne({ antennaId: In(antennas.map(x => x.id)), read: false @@ -112,7 +112,7 @@ export class UserRepository extends Repository { muterId: userId }); const mutedUserIds = mute.map(m => m.muteeId); - + const count = await Notifications.count({ where: { notifieeId: userId, diff --git a/src/server/api/endpoints/antennas/create.ts b/src/server/api/endpoints/antennas/create.ts index f11b198f8..bc7938526 100644 --- a/src/server/api/endpoints/antennas/create.ts +++ b/src/server/api/endpoints/antennas/create.ts @@ -82,7 +82,7 @@ export default define(meta, async (ps, user) => { id: ps.userListId, userId: user.id, }); - + if (userList == null) { throw new ApiError(meta.errors.noSuchUserList); } @@ -91,7 +91,7 @@ export default define(meta, async (ps, user) => { userGroupId: ps.userGroupId, userId: user.id, }); - + if (userGroupJoining == null) { throw new ApiError(meta.errors.noSuchUserGroup); } diff --git a/src/server/api/endpoints/antennas/update.ts b/src/server/api/endpoints/antennas/update.ts index ab4ce5793..b329e86ad 100644 --- a/src/server/api/endpoints/antennas/update.ts +++ b/src/server/api/endpoints/antennas/update.ts @@ -101,7 +101,7 @@ export default define(meta, async (ps, user) => { id: ps.userListId, userId: user.id, }); - + if (userList == null) { throw new ApiError(meta.errors.noSuchUserList); } @@ -110,7 +110,7 @@ export default define(meta, async (ps, user) => { userGroupId: ps.userGroupId, userId: user.id, }); - + if (userGroupJoining == null) { throw new ApiError(meta.errors.noSuchUserGroup); } diff --git a/src/server/api/stream/channels/main.ts b/src/server/api/stream/channels/main.ts index 7419ba420..22e664bac 100644 --- a/src/server/api/stream/channels/main.ts +++ b/src/server/api/stream/channels/main.ts @@ -11,7 +11,8 @@ export default class extends Channel { public async init(params: any) { // Subscribe main stream channel this.subscriber.on(`mainStream:${this.user!.id}`, async data => { - let { type, body } = data; + const { type } = data; + let { body } = data; switch (type) { case 'notification': { diff --git a/src/services/add-note-to-antenna.ts b/src/services/add-note-to-antenna.ts index 0055639c0..88a6613c6 100644 --- a/src/services/add-note-to-antenna.ts +++ b/src/services/add-note-to-antenna.ts @@ -38,7 +38,7 @@ export async function addNoteToAntenna(antenna: Antenna, note: Note, noteUser: U if (note.renoteId != null) { _note.renote = await Notes.findOne(note.renoteId).then(ensure); } - + if (shouldMuteThisNote(_note, mutings.map(x => x.muteeId))) { return; } diff --git a/src/services/note/create.ts b/src/services/note/create.ts index a10ee5164..50586e8bc 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -223,7 +223,7 @@ export default async (user: User, data: Option, silent = false) => new Promise f.followerId); - + for (const antenna of antennas) { checkHitAntenna(antenna, note, user, followers).then(hit => { if (hit) { diff --git a/tslint.json b/tslint.json index 733c291f3..4a072b4ff 100644 --- a/tslint.json +++ b/tslint.json @@ -61,7 +61,9 @@ "no-duplicated-branches": false, "no-identical-conditions": false, "no-useless-cast": false, - "no-hardcoded-credentials": false + "no-hardcoded-credentials": false, + "no-nested-switch": false, + "unified-signatures": false }, "rulesDirectory": [] }