From d254a0577005ac9df80129b8c42341520b2db2a9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 18 Nov 2021 23:32:43 +0900 Subject: [PATCH] introduce lint for client Resolve #7998 --- package.json | 4 +- packages/backend/.eslintrc.js | 66 +-- packages/client/.eslintrc | 32 -- packages/client/.eslintrc.js | 46 ++ packages/client/package.json | 7 +- .../src/components/date-separated-list.vue | 4 - packages/client/src/components/post-form.vue | 7 +- packages/client/src/components/sparkle.vue | 32 +- packages/client/src/components/ui/menu.vue | 8 +- packages/client/src/components/ui/popup.vue | 2 + .../page-editor/els/page-editor.el.button.vue | 2 + .../page-editor/els/page-editor.el.canvas.vue | 2 + .../els/page-editor.el.counter.vue | 2 + .../page-editor/els/page-editor.el.if.vue | 2 + .../page-editor/els/page-editor.el.image.vue | 2 + .../page-editor/els/page-editor.el.note.vue | 2 + .../els/page-editor.el.number-input.vue | 2 + .../page-editor/els/page-editor.el.post.vue | 2 + .../els/page-editor.el.radio-button.vue | 2 + .../els/page-editor.el.section.vue | 2 + .../page-editor/els/page-editor.el.switch.vue | 2 + .../els/page-editor.el.text-input.vue | 2 + .../page-editor/els/page-editor.el.text.vue | 2 + .../els/page-editor.el.textarea-input.vue | 2 + .../els/page-editor.el.textarea.vue | 2 + .../page-editor/page-editor.script-block.vue | 2 + packages/client/src/pages/settings/index.vue | 1 + packages/client/src/pages/settings/theme.vue | 2 +- packages/client/src/pages/share.vue | 2 +- .../client/src/pages/welcome.timeline.vue | 2 +- .../client/src/scripts/reaction-picker.ts | 6 +- .../src/ui/chat/date-separated-list.vue | 6 - packages/client/src/ui/chat/index.vue | 4 - packages/client/src/ui/chat/note.sub.vue | 2 +- packages/client/src/ui/chat/post-form.vue | 2 +- packages/client/src/ui/visitor/kanban.vue | 2 +- packages/client/yarn.lock | 410 +++++++++++++++++- packages/shared/.eslintrc.js | 69 +++ scripts/lint.js | 8 + yarn.lock | 214 ++++++++- 40 files changed, 817 insertions(+), 153 deletions(-) delete mode 100644 packages/client/.eslintrc create mode 100644 packages/client/.eslintrc.js create mode 100644 packages/shared/.eslintrc.js diff --git a/package.json b/package.json index d712e21e2..dd7d36e6e 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,10 @@ "devDependencies": { "@redocly/openapi-core": "1.0.0-beta.54", "@types/fluent-ffmpeg": "2.1.17", + "@typescript-eslint/parser": "5.4.0", "cross-env": "7.0.3", "cypress": "9.0.0", - "start-server-and-test": "1.14.0" + "start-server-and-test": "1.14.0", + "typescript": "4.5.2" } } diff --git a/packages/backend/.eslintrc.js b/packages/backend/.eslintrc.js index 7e99ef86e..e2e31e9e3 100644 --- a/packages/backend/.eslintrc.js +++ b/packages/backend/.eslintrc.js @@ -1,73 +1,9 @@ module.exports = { - root: true, - parser: '@typescript-eslint/parser', parserOptions: { tsconfigRootDir: __dirname, project: ['./tsconfig.json'], }, - plugins: [ - '@typescript-eslint', - 'import' - ], extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:import/recommended', - 'plugin:import/typescript' + '../shared/.eslintrc.js', ], - rules: { - 'indent': ['warn', 'tab', { - 'SwitchCase': 1, - 'MemberExpression': 'off', - 'flatTernaryExpressions': true, - 'ArrayExpression': 'first', - 'ObjectExpression': 'first', - }], - 'eol-last': ['error', 'always'], - 'semi': ['error', 'always'], - 'quotes': ['warn', 'single'], - 'comma-dangle': ['warn', 'always-multiline'], - 'keyword-spacing': ['error', { - 'before': true, - 'after': true, - }], - 'key-spacing': ['error', { - 'beforeColon': false, - 'afterColon': true, - }], - /* TODO: path aliasを使わないとwarnする - 'no-restricted-imports': ['warn', { - 'patterns': [ - ] - }], - */ - 'no-multi-spaces': ['error'], - 'no-var': ['error'], - 'prefer-arrow-callback': ['error'], - 'no-throw-literal': ['warn'], - 'no-param-reassign': ['warn'], - 'no-constant-condition': ['warn'], - 'no-empty-pattern': ['warn'], - 'no-async-promise-executor': ['off'], - 'no-useless-escape': ['off'], - 'no-multi-spaces': ['warn'], - 'no-multiple-empty-lines': ['error', { 'max': 1 }], - 'no-control-regex': ['warn'], - 'no-empty': ['warn'], - 'no-inner-declarations': ['off'], - 'no-sparse-arrays': ['off'], - 'nonblock-statement-body-position': ['error', 'beside'], - 'object-curly-spacing': ['error', 'always'], - 'space-infix-ops': ['error'], - 'space-before-blocks': ['error', 'always'], - '@typescript-eslint/no-var-requires': ['warn'], - '@typescript-eslint/no-inferrable-types': ['warn'], - '@typescript-eslint/no-empty-function': ['off'], - '@typescript-eslint/no-non-null-assertion': ['warn'], - '@typescript-eslint/no-misused-promises': ['error', { - 'checksVoidReturn': false, - }], - 'import/no-unresolved': ['off'], - 'import/no-default-export': ['warn'], - }, }; diff --git a/packages/client/.eslintrc b/packages/client/.eslintrc deleted file mode 100644 index b3b631e1d..000000000 --- a/packages/client/.eslintrc +++ /dev/null @@ -1,32 +0,0 @@ -{ - "env": { - "node": false - }, - "extends": [ - "eslint:recommended", - "plugin:vue/recommended" - ], - "rules": { - "vue/require-v-for-key": 0, - "vue/max-attributes-per-line": 0, - "vue/html-indent": 0, - "vue/html-self-closing": 0, - "vue/no-unused-vars": 0, - "vue/attributes-order": 0, - "vue/require-prop-types": 0, - "vue/require-default-prop": 0, - "vue/html-closing-bracket-spacing": 0, - "vue/singleline-html-element-content-newline": 0, - "vue/no-v-html": 0 - }, - "globals": { - "_DEV_": false, - "_LANGS_": false, - "_VERSION_": false, - "_ENV_": false, - "_PERF_PREFIX_": false, - "_DATA_TRANSFER_DRIVE_FILE_": false, - "_DATA_TRANSFER_DRIVE_FOLDER_": false, - "_DATA_TRANSFER_DECK_COLUMN_": false - } -} diff --git a/packages/client/.eslintrc.js b/packages/client/.eslintrc.js new file mode 100644 index 000000000..18f312a15 --- /dev/null +++ b/packages/client/.eslintrc.js @@ -0,0 +1,46 @@ +module.exports = { + root: true, + env: { + "node": false + }, + parser: "vue-eslint-parser", + parserOptions: { + "parser": "@typescript-eslint/parser", + tsconfigRootDir: __dirname, + //project: ['./tsconfig.json'], + }, + extends: [ + //"../shared/.eslintrc.js", + "plugin:vue/vue3-recommended" + ], + rules: { + "vue/html-indent": ["warn", "tab", { + "attribute": 1, + "baseIndent": 0, + "closeBracket": 0, + "alignAttributesVertically": true, + "ignores": [] + }], + "vue/html-closing-bracket-spacing": ["warn", { + "startTag": "never", + "endTag": "never", + "selfClosingTag": "never" + }], + "vue/multi-word-component-names": "warn", + "vue/require-v-for-key": "warn", + "vue/no-unused-components": "warn", + "vue/valid-v-for": "warn", + "vue/return-in-computed-property": "warn", + }, + globals: { + "require": false, + "_DEV_": false, + "_LANGS_": false, + "_VERSION_": false, + "_ENV_": false, + "_PERF_PREFIX_": false, + "_DATA_TRANSFER_DRIVE_FILE_": false, + "_DATA_TRANSFER_DRIVE_FOLDER_": false, + "_DATA_TRANSFER_DECK_COLUMN_": false + } +} diff --git a/packages/client/package.json b/packages/client/package.json index 57cc51953..911dadcee 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -2,7 +2,8 @@ "private": true, "scripts": { "watch": "webpack --watch", - "build": "webpack" + "build": "webpack", + "lint": "eslint --quiet src/**/*.{ts,vue}" }, "resolutions": { "chokidar": "^3.3.1", @@ -72,7 +73,7 @@ "dateformat": "4.5.1", "escape-regexp": "0.0.1", "eslint": "8.2.0", - "eslint-plugin-vue": "8.0.3", + "eslint-plugin-vue": "8.1.1", "eventemitter3": "4.0.7", "feed": "4.2.2", "glob": "7.2.0", @@ -152,8 +153,10 @@ "devDependencies": { "@redocly/openapi-core": "1.0.0-beta.54", "@types/fluent-ffmpeg": "2.1.17", + "@typescript-eslint/eslint-plugin": "5.4.0", "cross-env": "7.0.3", "cypress": "8.5.0", + "eslint-plugin-import": "2.25.3", "start-server-and-test": "1.14.0" } } diff --git a/packages/client/src/components/date-separated-list.vue b/packages/client/src/components/date-separated-list.vue index 1aea9fd35..aa84c6f60 100644 --- a/packages/client/src/components/date-separated-list.vue +++ b/packages/client/src/components/date-separated-list.vue @@ -31,10 +31,6 @@ export default defineComponent({ }, methods: { - focus() { - this.$slots.default[0].elm.focus(); - }, - getDateText(time: string) { const date = new Date(time).getDate(); const month = new Date(time).getMonth() + 1; diff --git a/packages/client/src/components/post-form.vue b/packages/client/src/components/post-form.vue index 88b88e17e..6cbcc57a7 100644 --- a/packages/client/src/components/post-form.vue +++ b/packages/client/src/components/post-form.vue @@ -128,7 +128,7 @@ export default defineComponent({ type: Boolean, required: false }, - visibleUsers: { + initialVisibleUsers: { type: Array, required: false, default: () => [] @@ -167,6 +167,7 @@ export default defineComponent({ cw: null, localOnly: this.$store.state.rememberNoteVisibility ? this.$store.state.localOnly : this.$store.state.defaultNoteLocalOnly, visibility: (this.$store.state.rememberNoteVisibility ? this.$store.state.visibility : this.$store.state.defaultNoteVisibility) as typeof noteVisibilities[number], + visibleUsers: [], autocomplete: null, draghover: false, quoteId: null, @@ -273,6 +274,10 @@ export default defineComponent({ this.localOnly = this.initialLocalOnly; } + if (this.initialVisibleUsers) { + this.visibleUsers = this.initialVisibleUsers; + } + if (this.mention) { this.text = this.mention.host ? `@${this.mention.username}@${toASCII(this.mention.host)}` : `@${this.mention.username}`; this.text += ' '; diff --git a/packages/client/src/components/sparkle.vue b/packages/client/src/components/sparkle.vue index 3aaf03995..21b57f158 100644 --- a/packages/client/src/components/sparkle.vue +++ b/packages/client/src/components/sparkle.vue @@ -33,11 +33,25 @@ export default defineComponent({ ctx: null, }; }, + unmounted() { + window.cancelAnimationFrame(this.anim); + }, + mounted() { + this.ctx = this.$refs.canvas.getContext('2d'); + + new ResizeObserver(this.resize).observe(this.$refs.content); + + this.resize(); + this.tick(); + }, + updated() { + this.resize(); + }, methods: { createSparkles(w, h, count) { - var holder = []; + const holder = []; - for (var i = 0; i < count; i++) { + for (let i = 0; i < count; i++) { const color = '#' + ('000000' + Math.floor(Math.random() * 16777215).toString(16)).slice(-6); @@ -143,20 +157,6 @@ export default defineComponent({ } }, }, - mounted() { - this.ctx = this.$refs.canvas.getContext('2d'); - - new ResizeObserver(this.resize).observe(this.$refs.content); - - this.resize(); - this.tick(); - }, - updated() { - this.resize(); - }, - destroyed() { - window.cancelAnimationFrame(this.anim); - }, }); diff --git a/packages/client/src/components/ui/menu.vue b/packages/client/src/components/ui/menu.vue index 5938fb00a..c17cc43ce 100644 --- a/packages/client/src/components/ui/menu.vue +++ b/packages/client/src/components/ui/menu.vue @@ -5,7 +5,7 @@ @contextmenu.self="e => e.preventDefault()" v-hotkey="keymap" > -