From c18f6fde80c4672df2d2b98d4ecd45bb2958a97d 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 d8c29abc37..91668786e2 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 4fc350cc2f..fa66bdcf64 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 55bebd9bfb..bc9d746f7e 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 c4dd7b145d..541f38fd76 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 2f2f9f5d59..29eabfee4e 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 a29dcd8550..c2ba8ac5cd 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 0d72c3f340..fa24794984 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 19e4750fc6..7d96b2ef7a 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 1d669feb5e..c6bc35030c 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 f11b198f86..bc79385260 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 ab4ce57937..b329e86ade 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 7419ba4203..22e664baca 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 0055639c0b..88a6613c60 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 a10ee5164b..50586e8bc7 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 733c291f3c..4a072b4ffe 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": [] }