From e5d4290938e87d93c4df2e4b50fe513f30e59f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Sun, 19 Aug 2018 16:55:24 +0800 Subject: [PATCH] refactor: add eslint-plugin-vue && lint code (#976) --- .eslintrc.js | 28 ++- package.json | 4 +- src/App.vue | 8 +- src/components/BackToTop/index.vue | 4 +- src/components/Breadcrumb/index.vue | 14 +- src/components/Charts/keyboard.vue | 2 +- src/components/Charts/lineMarker.vue | 2 +- src/components/Charts/mixChart.vue | 2 +- src/components/DndList/index.vue | 42 ++-- src/components/Dropzone/index.vue | 145 +++++++------- src/components/ErrorLog/index.vue | 31 +-- src/components/GithubCorner/index.vue | 21 +- src/components/Hamburger/index.vue | 32 +++- src/components/ImageCropper/index.vue | 180 +++++++++--------- src/components/JsonEditor/index.vue | 7 +- src/components/Kanban/index.vue | 12 +- src/components/LangSelect/index.vue | 9 +- src/components/MDinput/index.vue | 136 ++++++++++--- src/components/MarkdownEditor/index.vue | 25 ++- src/components/PanThumb/index.vue | 6 +- src/components/Screenfull/index.vue | 35 ++-- src/components/ScrollPane/index.vue | 8 +- src/components/Share/dropdownMenu.vue | 15 +- src/components/Sticky/index.vue | 3 +- src/components/SvgIcon/index.vue | 7 +- src/components/TextHoverEffect/Mallki.vue | 12 +- src/components/ThemePicker/index.vue | 4 +- .../Tinymce/components/editorImage.vue | 16 +- src/components/Tinymce/index.vue | 20 +- src/components/TreeTable/index.vue | 29 +-- src/components/Upload/singleImage.vue | 47 +++-- src/components/Upload/singleImage2.vue | 31 +-- src/components/Upload/singleImage3.vue | 35 ++-- src/components/UploadExcel/index.vue | 4 +- src/lang/en.js | 4 +- src/router/index.js | 46 ++--- src/router/modules/charts.js | 8 +- src/router/modules/components.js | 28 +-- src/router/modules/nested.js | 16 +- src/router/modules/table.js | 14 +- src/styles/btn.scss | 1 - src/views/charts/keyboard.vue | 6 +- src/views/charts/line.vue | 6 +- src/views/charts/mixChart.vue | 6 +- src/views/clipboard/index.vue | 10 +- src/views/components-demo/avatarUpload.vue | 19 +- src/views/components-demo/backToTop.vue | 8 +- src/views/components-demo/countTo.vue | 38 ++-- src/views/components-demo/dndList.vue | 5 +- src/views/components-demo/dragDialog.vue | 13 +- src/views/components-demo/dragKanban.vue | 8 +- src/views/components-demo/dropzone.vue | 7 +- src/views/components-demo/jsonEditor.vue | 4 +- src/views/components-demo/markdown.vue | 9 +- src/views/components-demo/mixin.vue | 15 +- src/views/components-demo/splitpane.vue | 12 +- src/views/components-demo/sticky.vue | 22 +-- src/views/components-demo/tinymce.vue | 11 +- .../dashboard/admin/components/BarChart.vue | 2 +- .../dashboard/admin/components/BoxCard.vue | 40 ++-- .../dashboard/admin/components/LineChart.vue | 21 +- .../dashboard/admin/components/PanelGroup.vue | 12 +- .../dashboard/admin/components/PieChart.vue | 2 +- .../admin/components/RaddarChart.vue | 2 +- .../admin/components/TodoList/Todo.vue | 35 ++-- .../admin/components/TodoList/index.scss | 1 + .../admin/components/TodoList/index.vue | 25 ++- .../admin/components/TransactionTable.vue | 16 +- src/views/dashboard/admin/index.vue | 21 +- src/views/dashboard/editor/index.vue | 12 +- src/views/dashboard/index.vue | 4 +- src/views/documentation/index.vue | 8 +- src/views/errorLog/errorTestA.vue | 4 +- src/views/errorLog/errorTestB.vue | 2 +- src/views/errorLog/index.vue | 14 +- src/views/errorPage/401.vue | 12 +- src/views/errorPage/404.vue | 4 +- .../example/components/ArticleDetail.vue | 37 ++-- .../example/components/Dropdown/Comment.vue | 17 +- .../example/components/Dropdown/Platform.vue | 16 +- .../example/components/Dropdown/SourceUrl.vue | 13 +- src/views/example/components/Warning.vue | 3 +- src/views/example/create.vue | 4 +- src/views/example/edit.vue | 4 +- src/views/example/list.vue | 48 +++-- src/views/excel/exportExcel.vue | 24 +-- src/views/excel/selectExcel.vue | 33 ++-- src/views/excel/uploadExcel.vue | 7 +- src/views/guide/index.vue | 6 +- src/views/i18n-demo/index.vue | 48 ++--- src/views/i18n-demo/local.js | 4 +- src/views/layout/Layout.vue | 14 +- src/views/layout/components/AppMain.vue | 2 +- src/views/layout/components/Navbar.vue | 28 +-- .../layout/components/Sidebar/SidebarItem.vue | 42 ++-- src/views/layout/components/Sidebar/index.vue | 6 +- src/views/layout/components/TagsView.vue | 24 ++- src/views/login/authredirect.vue | 14 +- src/views/login/index.vue | 58 +++--- src/views/login/socialsignin.vue | 6 +- src/views/nested/menu1/index.vue | 2 +- src/views/nested/menu1/menu1-1/index.vue | 2 +- src/views/nested/menu1/menu1-2/index.vue | 2 +- .../nested/menu1/menu1-2/menu1-2-1/index.vue | 2 +- .../nested/menu1/menu1-2/menu1-2-2/index.vue | 2 +- src/views/nested/menu1/menu1-3/index.vue | 2 +- src/views/nested/menu2/index.vue | 2 +- .../permission/components/SwitchRoles.vue | 8 +- src/views/permission/directive.vue | 4 +- src/views/permission/page.vue | 2 +- src/views/qiniu/upload.vue | 5 +- src/views/svg-icons/index.vue | 8 +- src/views/tab/components/tabPane.vue | 44 +++-- src/views/tab/index.vue | 13 +- src/views/table/complexTable.vue | 145 +++++++------- src/views/table/dragTable.vue | 44 ++--- src/views/table/dynamicTable/fixedThead.vue | 8 +- src/views/table/dynamicTable/index.vue | 10 +- src/views/table/dynamicTable/unfixedThead.vue | 7 +- src/views/table/inlineEditTable.vue | 42 ++-- src/views/table/treeTable/customTreeTable.vue | 20 +- src/views/table/treeTable/treeTable.vue | 4 +- src/views/theme/index.vue | 26 +-- src/views/zip/index.vue | 22 +-- 124 files changed, 1329 insertions(+), 1084 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 00d60805..6f55c5a1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { root: true, - parser: 'babel-eslint', parserOptions: { + parser: 'babel-eslint', sourceType: 'module' }, env: { @@ -9,22 +9,19 @@ module.exports = { node: true, es6: true, }, - extends: 'eslint:recommended', - // required to lint *.vue files - plugins: [ - 'html' - ], - // check if imports actually resolve - 'settings': { - 'import/resolver': { - 'webpack': { - 'config': 'build/webpack.base.conf.js' - } - } - }, + extends: ['plugin:vue/recommended', 'eslint:recommended'], + // add your custom rules here //it is base on https://github.com/vuejs/eslint-config-vue - 'rules': { + rules: { + "vue/max-attributes-per-line": [2, { + "singleline": 10, + "multiline": { + "max": 1, + "allowFirstLine": false + } + }], + "vue/name-property-casing": ["error", "PascalCase"], 'accessor-pairs': 2, 'arrow-spacing': [2, { 'before': true, @@ -196,4 +193,3 @@ module.exports = { 'array-bracket-spacing': [2, 'never'] } } - diff --git a/package.json b/package.json index 8f7847cf..89e6ec12 100644 --- a/package.json +++ b/package.json @@ -82,10 +82,10 @@ "eslint": "4.19.1", "eslint-friendly-formatter": "4.0.1", "eslint-loader": "2.0.0", - "eslint-plugin-html": "4.0.5", + "eslint-plugin-vue": "4.7.1", "file-loader": "1.1.11", "friendly-errors-webpack-plugin": "1.7.0", - "hash-sum": "^1.0.2", + "hash-sum": "1.0.2", "html-webpack-plugin": "^4.0.0-alpha", "husky": "0.14.3", "lint-staged": "7.2.2", diff --git a/src/App.vue b/src/App.vue index 690cfc98..ab408f3e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,11 +1,11 @@ diff --git a/src/components/BackToTop/index.vue b/src/components/BackToTop/index.vue index de953821..2d4b0193 100644 --- a/src/components/BackToTop/index.vue +++ b/src/components/BackToTop/index.vue @@ -1,10 +1,10 @@ @@ -27,7 +27,7 @@ const content = ` ` export default { - name: 'markdown-demo', + name: 'MarkdownDemo', components: { MarkdownEditor }, data() { return { @@ -46,4 +46,3 @@ export default { } - diff --git a/src/views/components-demo/mixin.vue b/src/views/components-demo/mixin.vue index 7f713f6d..99b62468 100644 --- a/src/views/components-demo/mixin.vue +++ b/src/views/components-demo/mixin.vue @@ -37,7 +37,7 @@
- 标题 + 标题
@@ -74,20 +74,20 @@ hover text
- +
- +
Share
- +
@@ -104,7 +104,7 @@ import DropdownMenu from '@/components/Share/dropdownMenu' import waves from '@/directive/waves/index.js' // 水波纹指令 export default { - name: 'componentMixin-demo', + name: 'ComponentMixinDemo', components: { PanThumb, MdInput, @@ -134,10 +134,7 @@ export default { { title: '登录权限篇', href: 'https://juejin.im/post/591aa14f570c35006961acac' }, { title: '实战篇', href: 'https://juejin.im/post/593121aa0ce4630057f70d35' }, { title: 'vue-admin-template 篇', href: 'https://juejin.im/post/595b4d776fb9a06bbe7dba56' }, - { title: '自行封装 component', href: 'https://segmentfault.com/a/1190000009090836' }, - { title: '优雅的使用 icon', href: 'https://juejin.im/post/59bb864b5188257e7a427c09' }, - { title: 'webpack4(上)', href: 'https://juejin.im/post/59bb864b5188257e7a427c09' }, - { title: 'webpack4(下)', href: 'https://juejin.im/post/5b5d6d6f6fb9a04fea58aabc' } + { title: '优雅的使用 icon', href: 'https://juejin.im/post/59bb864b5188257e7a427c09' } ] } } diff --git a/src/views/components-demo/splitpane.vue b/src/views/components-demo/splitpane.vue index 5a0bfb2b..dcd87149 100644 --- a/src/views/components-demo/splitpane.vue +++ b/src/views/components-demo/splitpane.vue @@ -3,19 +3,19 @@ SplitPane If you've used codepen, jsfiddle will not be unfamiliar. - Github repository + Github repository - + @@ -27,7 +27,7 @@ import splitPane from 'vue-splitpane' export default { - name: 'splitpane-demo', + name: 'SplitpaneDemo', components: { splitPane }, methods: { resize() { diff --git a/src/views/components-demo/sticky.vue b/src/views/components-demo/sticky.vue index 49772bea..65cfb091 100644 --- a/src/views/components-demo/sticky.vue +++ b/src/views/components-demo/sticky.vue @@ -1,14 +1,14 @@ - diff --git a/src/views/dashboard/admin/components/LineChart.vue b/src/views/dashboard/admin/components/LineChart.vue index 9be9c92d..6c6637a8 100644 --- a/src/views/dashboard/admin/components/LineChart.vue +++ b/src/views/dashboard/admin/components/LineChart.vue @@ -1,5 +1,5 @@ diff --git a/src/views/dashboard/admin/components/TransactionTable.vue b/src/views/dashboard/admin/components/TransactionTable.vue index 7c79b77b..bcbfbb43 100644 --- a/src/views/dashboard/admin/components/TransactionTable.vue +++ b/src/views/dashboard/admin/components/TransactionTable.vue @@ -2,17 +2,17 @@ @@ -22,11 +22,6 @@ import { fetchList } from '@/api/transaction' export default { - data() { - return { - list: null - } - }, filters: { statusFilter(status) { const statusMap = { @@ -39,6 +34,11 @@ export default { return str.substring(0, 30) } }, + data() { + return { + list: null + } + }, created() { this.fetchData() }, diff --git a/src/views/dashboard/admin/index.vue b/src/views/dashboard/admin/index.vue index 8da28543..1a79637a 100644 --- a/src/views/dashboard/admin/index.vue +++ b/src/views/dashboard/admin/index.vue @@ -1,48 +1,47 @@ - diff --git a/src/views/errorLog/errorTestB.vue b/src/views/errorLog/errorTestB.vue index a1303f89..b04c2511 100644 --- a/src/views/errorLog/errorTestB.vue +++ b/src/views/errorLog/errorTestB.vue @@ -1,5 +1,5 @@ diff --git a/src/views/errorPage/401.vue b/src/views/errorPage/401.vue index b8bbb013..d43be52d 100644 --- a/src/views/errorPage/401.vue +++ b/src/views/errorPage/401.vue @@ -1,10 +1,10 @@ @@ -30,7 +30,7 @@ import errGif from '@/assets/401_images/401.gif' export default { - name: 'page401', + name: 'Page401', data() { return { errGif: errGif + '?' + +new Date(), diff --git a/src/views/errorPage/404.vue b/src/views/errorPage/404.vue index 97e57b2f..c3eafea0 100644 --- a/src/views/errorPage/404.vue +++ b/src/views/errorPage/404.vue @@ -10,7 +10,7 @@
OOPS!
{{ message }}
请检查您输入的网址是否正确,请点击以下按钮返回主页或者发送错误报告
@@ -23,7 +23,7 @@ diff --git a/src/views/example/edit.vue b/src/views/example/edit.vue index 097b6140..c21af0c9 100644 --- a/src/views/example/edit.vue +++ b/src/views/example/edit.vue @@ -1,12 +1,12 @@ diff --git a/src/views/example/list.vue b/src/views/example/list.vue index 7dccafa6..f44d7078 100644 --- a/src/views/example/list.vue +++ b/src/views/example/list.vue @@ -1,41 +1,41 @@