From 16e4889a9248fd119082bd34e31a5f9e42b1072f Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 14 Dec 2018 14:24:23 +0800 Subject: [PATCH] [improvement] update eslint config (#2288) --- .eslintrc | 20 +- babel.config.js | 2 +- build/build-entry.js | 7 +- build/build-lib.js | 1 + build/build-style-entry.js | 26 +- build/build-style.js | 8 +- build/get-components.js | 2 +- build/webpack.build.js | 3 +- docs/src/demo-common.js | 15 +- docs/src/demo-entry.js | 1 + docs/src/docs-entry.js | 1 + docs/src/index.js | 8 +- docs/src/mobile.js | 4 +- docs/src/router.js | 26 +- docs/src/utils/iframe-router.js | 6 +- docs/src/utils/lang.js | 6 +- package.json | 12 +- packages/actionsheet/index.vue | 11 +- .../test/__snapshots__/demo.spec.js.snap | 9 +- packages/actionsheet/test/index.spec.js | 2 +- packages/address-edit/Detail.vue | 2 +- packages/address-edit/index.vue | 7 +- .../test/__snapshots__/demo.spec.js.snap | 26 +- .../test/__snapshots__/index.spec.js.snap | 33 +- packages/address-edit/test/index.spec.js | 12 +- packages/address-list/demo/index.vue | 2 +- .../test/__snapshots__/demo.spec.js.snap | 21 +- packages/area/demo/area-en.js | 132 +- packages/area/demo/area.js | 7552 ++++++++--------- packages/area/demo/area.simple.js | 32 +- packages/area/index.vue | 8 +- .../test/__snapshots__/index.spec.js.snap | 48 +- packages/area/test/index.spec.js | 6 +- .../test/__snapshots__/demo.spec.js.snap | 15 +- packages/badge/test/index.spec.js | 2 +- .../test/__snapshots__/demo.spec.js.snap | 50 +- packages/card/index.vue | 5 +- .../card/test/__snapshots__/demo.spec.js.snap | 16 +- .../cell/test/__snapshots__/demo.spec.js.snap | 66 +- packages/checkbox/demo/index.vue | 2 +- .../test/__snapshots__/demo.spec.js.snap | 150 +- .../test/__snapshots__/demo.spec.js.snap | 11 +- packages/collapse-item/index.vue | 2 +- .../test/__snapshots__/demo.spec.js.snap | 61 +- packages/collapse/test/index.spec.js | 4 +- .../test/__snapshots__/demo.spec.js.snap | 36 +- packages/contact-card/test/index.spec.js | 4 +- packages/coupon-list/demo/index.vue | 2 +- packages/coupon-list/index.vue | 4 +- .../test/__snapshots__/demo.spec.js.snap | 6 +- .../test/__snapshots__/index.spec.js.snap | 12 +- packages/datetime-picker/demo/index.vue | 3 +- packages/datetime-picker/index.vue | 6 +- .../test/__snapshots__/demo.spec.js.snap | 398 +- packages/dialog/index.js | 9 +- .../test/__snapshots__/demo.spec.js.snap | 33 +- packages/dialog/test/index.spec.js | 2 +- .../test/__snapshots__/demo.spec.js.snap | 43 +- .../test/__snapshots__/index.spec.js.snap | 13 +- packages/field/test/index.spec.js | 8 +- .../test/__snapshots__/demo.spec.js.snap | 31 +- packages/icon/config/template-local.js | 4 +- packages/icon/demo/index.vue | 2 +- packages/image-preview/demo/index.vue | 2 +- .../test/__snapshots__/index.spec.js.snap | 28 +- packages/image-preview/test/index.spec.js | 4 +- packages/index.js | 1 + packages/list/test/index.spec.js | 6 +- .../test/__snapshots__/demo.spec.js.snap | 3 +- packages/mixins/bem.js | 2 +- packages/mixins/i18n.js | 2 +- .../test/__snapshots__/demo.spec.js.snap | 19 +- packages/notice-bar/index.vue | 2 +- .../test/__snapshots__/demo.spec.js.snap | 16 +- .../test/__snapshots__/demo.spec.js.snap | 8 +- packages/notify/test/index.spec.js | 6 +- .../test/__snapshots__/demo.spec.js.snap | 40 +- packages/number-keyboard/test/index.spec.js | 2 +- packages/pagination/demo/index.vue | 12 +- .../test/__snapshots__/demo.spec.js.snap | 7 +- .../test/__snapshots__/demo.spec.js.snap | 39 +- packages/picker/index.vue | 4 +- .../test/__snapshots__/index.spec.js.snap | 4 +- packages/picker/test/index.spec.js | 4 +- .../test/__snapshots__/demo.spec.js.snap | 12 +- packages/popup/test/index.spec.js | 2 +- .../test/__snapshots__/demo.spec.js.snap | 15 +- .../test/__snapshots__/index.spec.js.snap | 3 +- packages/progress/test/index.spec.js | 2 +- .../test/__snapshots__/index.spec.js.snap | 22 +- packages/rate/index.vue | 1 + .../rate/test/__snapshots__/demo.spec.js.snap | 96 +- packages/rate/test/index.spec.js | 4 +- .../test/__snapshots__/demo.spec.js.snap | 27 +- packages/sku/Sku.vue | 13 +- packages/sku/components/SkuHeader.vue | 4 +- packages/sku/components/SkuMessages.vue | 6 +- packages/sku/demo/index.vue | 14 +- .../sku/test/__snapshots__/demo.spec.js.snap | 18 +- packages/sku/utils/skuHelper.js | 44 +- packages/step/index.vue | 5 +- packages/stepper/index.vue | 2 +- .../test/__snapshots__/demo.spec.js.snap | 18 +- .../test/__snapshots__/index.spec.js.snap | 16 +- .../test/__snapshots__/demo.spec.js.snap | 63 +- .../test/__snapshots__/demo.spec.js.snap | 23 +- .../test/__snapshots__/index.spec.js.snap | 5 +- packages/submit-bar/test/index.spec.js | 2 +- packages/swipe-cell/index.vue | 6 +- .../test/__snapshots__/index.spec.js.snap | 10 +- packages/swipe/demo/index.vue | 2 +- .../test/__snapshots__/demo.spec.js.snap | 16 +- packages/swipe/test/index.spec.js | 2 +- packages/tab/index.vue | 1 + .../tab/test/__snapshots__/demo.spec.js.snap | 12 +- .../tab/test/__snapshots__/index.spec.js.snap | 14 +- packages/tab/test/index.spec.js | 6 +- .../test/__snapshots__/demo.spec.js.snap | 39 +- packages/tabs/index.vue | 2 +- packages/toast/demo/index.vue | 2 +- packages/toast/index.js | 6 +- .../test/__snapshots__/demo.spec.js.snap | 18 +- packages/toast/test/index.spec.js | 6 +- .../test/__snapshots__/demo.spec.js.snap | 4 +- packages/tree-select/test/index.spec.js | 2 +- .../test/__snapshots__/demo.spec.js.snap | 16 +- packages/uploader/test/index.spec.js | 17 +- packages/utils/create-basic.js | 8 +- packages/utils/create.js | 4 +- packages/utils/deep-assign.js | 12 +- packages/utils/deep-clone.js | 3 +- packages/utils/event.js | 6 +- packages/utils/index.js | 2 +- packages/utils/scroll.js | 12 +- packages/utils/test/index.spec.js | 6 +- packages/utils/validate/mobile.js | 2 +- packages/waterfall/demo/index.vue | 2 +- packages/waterfall/directive.js | 69 +- packages/waterfall/index.js | 4 +- postcss.config.js | 2 +- yarn.lock | 3931 ++++----- 141 files changed, 6387 insertions(+), 7536 deletions(-) diff --git a/.eslintrc b/.eslintrc index c4b23b207..d0707a444 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,22 +1,4 @@ { "root": true, - "env": { - "jest": true - }, - "extends": ["plugin:vue-libs/recommended", "plugin:vue/recommended"], - "rules": { - "semi": ["error", "always"], - "space-before-function-paren": ["error", "never"], - "vue/attributes-order": 0, - "vue/require-v-for-key": 0, - "vue/require-default-prop": 0, - "vue/name-property-casing": ["error", "kebab-case"], - "vue/html-closing-bracket-newline": [ - "error", - { - "singleline": "never", - "multiline": "always" - } - ] - } + "extends": ["@vant"] } diff --git a/babel.config.js b/babel.config.js index 7bfd419ad..8175adeb9 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,4 +1,4 @@ -module.exports = function(api) { +module.exports = function (api) { const { BABEL_MODULE, NODE_ENV } = process.env; const useESModules = BABEL_MODULE !== 'commonjs' && NODE_ENV !== 'test'; diff --git a/build/build-entry.js b/build/build-entry.js index b836f1661..87ff3af7e 100644 --- a/build/build-entry.js +++ b/build/build-entry.js @@ -3,8 +3,11 @@ const glob = require('fast-glob'); const path = require('path'); const uppercamelize = require('uppercamelcase'); const Components = require('./get-components')(); -const version = process.env.VERSION || require('../package.json').version; -const tips = '// This file is auto gererated by build/build-entry.js'; +const packageJson = require('../package.json'); + +const version = process.env.VERSION || packageJson.version; +const tips = `/* eslint-disable */ +// This file is auto gererated by build/build-entry.js`; const root = path.join(__dirname, '../'); const join = dir => path.join(root, dir); diff --git a/build/build-lib.js b/build/build-lib.js index 6114ebc0d..1864fe0d6 100644 --- a/build/build-lib.js +++ b/build/build-lib.js @@ -3,6 +3,7 @@ */ const shell = require('shelljs'); const signale = require('signale'); + const { Signale } = signale; const tasks = [ 'bootstrap', diff --git a/build/build-style-entry.js b/build/build-style-entry.js index cae6b83bd..4182bad00 100644 --- a/build/build-style-entry.js +++ b/build/build-style-entry.js @@ -1,11 +1,13 @@ +/* eslint-disable no-use-before-define */ /** * Build style entry of all components */ const fs = require('fs-extra'); const path = require('path'); -const components = require('./get-components')(); const dependencyTree = require('dependency-tree'); +const components = require('./get-components')(); + const whiteList = [ 'info', 'icon', @@ -17,17 +19,10 @@ const whiteList = [ ]; const dir = path.join(__dirname, '../es'); -components.forEach(component => { - // css entry - destEntryFile(component, 'index.js', '.css'); - // less entry - destEntryFile(component, 'less.js', '.less'); -}); - function destEntryFile(component, filename, ext = '') { - const deps = analyzeDependencies(component).map(dep => + const deps = analyzeDependencies(component).map(dep => ( getStyleRelativePath(component, dep, ext) - ); + )); const esEntry = path.join(dir, component, `style/${filename}`); const libEntry = path.join( @@ -68,12 +63,12 @@ function search(tree, component, checkList) { Object.keys(tree).forEach(key => { search(tree[key], component, checkList); components - .filter(item => + .filter(item => ( key .replace(dir, '') .split('/') .includes(item) - ) + )) .forEach(item => { if ( !checkList.includes(item) && @@ -103,3 +98,10 @@ function getStyleRelativePath(component, style, ext) { function checkComponentHasStyle(component) { return fs.existsSync(getStylePath(component)); } + +components.forEach(component => { + // css entry + destEntryFile(component, 'index.js', '.css'); + // less entry + destEntryFile(component, 'less.js', '.less'); +}); diff --git a/build/build-style.js b/build/build-style.js index 377b131e2..9c0fd1263 100644 --- a/build/build-style.js +++ b/build/build-style.js @@ -4,13 +4,13 @@ const csso = require('gulp-csso'); const postcss = require('gulp-postcss'); // compile component css -gulp.task('compile', () => { - return gulp +gulp.task('compile', () => ( + gulp .src(['../es/**/*.less', '../lib/**/*.less']) .pipe(less()) .pipe(postcss()) .pipe(csso()) - .pipe(gulp.dest(file => file.base.replace('.less', '.css'))); -}); + .pipe(gulp.dest(file => file.base.replace('.less', '.css'))) +)); gulp.task('default', ['compile']); diff --git a/build/get-components.js b/build/get-components.js index 3476940b5..748a84a94 100644 --- a/build/get-components.js +++ b/build/get-components.js @@ -10,7 +10,7 @@ const excludes = [ '.DS_Store' ]; -module.exports = function() { +module.exports = function () { const dirs = fs.readdirSync(path.resolve(__dirname, '../packages')); return dirs.filter(dirName => excludes.indexOf(dirName) === -1); }; diff --git a/build/webpack.build.js b/build/webpack.build.js index cf081d568..37ebd8c16 100644 --- a/build/webpack.build.js +++ b/build/webpack.build.js @@ -1,5 +1,6 @@ const path = require('path'); const config = require('./webpack.dev.js'); + const isMinify = process.argv.indexOf('-p') !== -1; delete config.serve; @@ -7,7 +8,7 @@ delete config.serve; module.exports = Object.assign(config, { mode: 'production', entry: { - 'vant': './es/index.js' + vant: './es/index.js' }, output: { path: path.join(__dirname, '../lib'), diff --git a/docs/src/demo-common.js b/docs/src/demo-common.js index f8f892341..443e04872 100644 --- a/docs/src/demo-common.js +++ b/docs/src/demo-common.js @@ -3,11 +3,10 @@ */ import Vue from 'vue'; -import i18n from '../../packages/mixins/i18n'; -import Vant, { Lazyload } from '../../packages'; -import VantDoc, { DemoBlock, DemoSection } from 'vant-doc'; import VueRouter from 'vue-router'; -import { Locale } from '../../packages'; +import VantDoc, { DemoBlock, DemoSection } from 'vant-doc'; +import i18n from '../../packages/mixins/i18n'; +import Vant, { Lazyload, Locale } from '../../packages'; import { camelize } from '../../packages/utils'; Vue @@ -86,12 +85,12 @@ export function wrapper(promise, name) { component = component.default; name = 'demo-' + name; component.name = name; - const { i18n } = component; - if (i18n) { + const { i18n: config } = component; + if (config) { const formattedI18n = {}; const camelizedName = camelize(name); - Object.keys(i18n).forEach(key => { - formattedI18n[key] = { [camelizedName]: i18n[key] }; + Object.keys(config).forEach(key => { + formattedI18n[key] = { [camelizedName]: config[key] }; }); Locale.add(formattedI18n); } diff --git a/docs/src/demo-entry.js b/docs/src/demo-entry.js index fbdac6068..3549f9b06 100644 --- a/docs/src/demo-entry.js +++ b/docs/src/demo-entry.js @@ -1,3 +1,4 @@ +/* eslint-disable */ // This file is auto gererated by build/build-entry.js import { wrapper } from './demo-common'; diff --git a/docs/src/docs-entry.js b/docs/src/docs-entry.js index 70b5caf4e..5234f8d69 100644 --- a/docs/src/docs-entry.js +++ b/docs/src/docs-entry.js @@ -1,3 +1,4 @@ +/* eslint-disable */ // This file is auto gererated by build/build-entry.js export default { 'changelog.en-US': () => import('../markdown/changelog.en-US.md'), diff --git a/docs/src/index.js b/docs/src/index.js index 8f92527c6..ce9d24984 100644 --- a/docs/src/index.js +++ b/docs/src/index.js @@ -1,8 +1,8 @@ import Vue from 'vue'; import VueRouter from 'vue-router'; +import VantDoc, { progress } from 'vant-doc'; import App from './DocsApp'; import routes from './router'; -import VantDoc, { progress } from 'vant-doc'; import { isMobile } from './utils'; Vue.use(VueRouter).use(VantDoc); @@ -33,8 +33,8 @@ if (process.env.NODE_ENV !== 'production') { Vue.config.productionTip = false; } -new Vue({ // eslint-disable-line +new Vue({ + el: '#app', render: h => h(App), - router, - el: '#app' + router }); diff --git a/docs/src/mobile.js b/docs/src/mobile.js index 9724e3ab1..0a3010637 100644 --- a/docs/src/mobile.js +++ b/docs/src/mobile.js @@ -1,9 +1,9 @@ import '../../packages/index.less'; import Vue from 'vue'; import VueRouter from 'vue-router'; +import { progress } from 'vant-doc'; import App from './WapApp'; import routes from './router'; -import { progress } from 'vant-doc'; import 'vant-doc/helper/touch-simulator'; const router = new VueRouter({ @@ -32,7 +32,7 @@ if (process.env.NODE_ENV !== 'production') { Vue.config.productionTip = false; } -new Vue({ // eslint-disable-line +new Vue({ el: '#app', render: h => h(App), router diff --git a/docs/src/router.js b/docs/src/router.js index 5575e5530..603651b53 100644 --- a/docs/src/router.js +++ b/docs/src/router.js @@ -9,10 +9,10 @@ import './utils/iframe-router'; const registerRoute = (isDemo) => { const route = [{ path: '*', - redirect: to => `/${Vue.prototype.$vantLang}/` + redirect: () => `/${Vue.prototype.$vantLang}/` }]; - Object.keys(docConfig).forEach((lang, index) => { + Object.keys(docConfig).forEach((lang) => { if (isDemo) { route.push({ path: `/${lang}`, @@ -26,17 +26,6 @@ const registerRoute = (isDemo) => { }); } - const navs = docConfig[lang].nav || []; - navs.forEach(nav => { - if (nav.groups) { - nav.groups.forEach(group => { - group.list.forEach(page => addRoute(page, lang)); - }); - } else { - addRoute(nav, lang); - } - }); - function addRoute(page, lang) { let { path } = page; if (path) { @@ -65,6 +54,17 @@ const registerRoute = (isDemo) => { }); } } + + const navs = docConfig[lang].nav || []; + navs.forEach(nav => { + if (nav.groups) { + nav.groups.forEach(group => { + group.list.forEach(page => addRoute(page, lang)); + }); + } else { + addRoute(nav, lang); + } + }); }); return route; diff --git a/docs/src/utils/iframe-router.js b/docs/src/utils/iframe-router.js index d7085b3f4..8a8b23e5d 100644 --- a/docs/src/utils/iframe-router.js +++ b/docs/src/utils/iframe-router.js @@ -3,9 +3,9 @@ */ import { setLang } from './lang'; -import { iframeReady, isMobile } from './'; +import { iframeReady, isMobile } from '.'; -window.syncPath = function(dir) { +window.syncPath = function () { const router = window.vueRouter; const isInIframe = window !== window.top; const currentDir = router.history.current.path; @@ -28,7 +28,7 @@ window.syncPath = function(dir) { } }; -window.changePath = function(lang, path = '') { +window.changePath = function (lang, path = '') { setLang(lang); window.vueRouter.replace(path); }; diff --git a/docs/src/utils/lang.js b/docs/src/utils/lang.js index 9d563d77d..ce90fa9fe 100644 --- a/docs/src/utils/lang.js +++ b/docs/src/utils/lang.js @@ -14,11 +14,9 @@ const langMap = { }; let currentLang = ''; -setLang(getDefaultLang()); - function getDefaultLang() { const langs = Object.keys(langMap); - const hash = location.hash; + const { hash } = location; for (let i = 0; i < langs.length; i++) { if (hash.indexOf(langs[i]) !== -1) { @@ -42,3 +40,5 @@ export function setLang(lang) { Locale.use(lang, langMap[lang].messages); document.title = langMap[lang].title; } + +setLang(getDefaultLang()); diff --git a/package.json b/package.json index 986e2e001..baf024c10 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "@babel/plugin-transform-runtime": "^7.1.0", "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.1.6", + "@vant/eslint-config": "^1.0.6", "@vue/server-test-utils": "^1.0.0-beta.26", "@vue/test-utils": "^1.0.0-beta.26", "autoprefixer": "^9.3.1", @@ -80,21 +81,20 @@ "babel-loader": "^8.0.4", "codecov": "^3.1.0", "cross-env": "^5.2.0", - "css-loader": "^1.0.1", + "css-loader": "^2.0.0", "dependency-tree": "^6.3.0", "eslint": "^5.9.0", - "eslint-plugin-vue-libs": "^3.0.0", "fast-glob": "^2.2.4", "fast-vue-md-loader": "^1.0.3", "gh-pages": "^2.0.1", - "gulp": "^3.9.1", + "gulp": "^4.0.0", "gulp-csso": "^3.0.1", "gulp-iconfont": "^10.0.2", "gulp-iconfont-css": "^2.3.0", "gulp-less": "^4.0.1", "gulp-postcss": "^8.0.0", "html-webpack-plugin": "3.2.0", - "husky": "^1.2.0", + "husky": "^1.2.1", "jest": "^23.6.0", "jest-serializer-vue": "^2.0.2", "less": "^3.8.1", @@ -114,13 +114,13 @@ "uppercamelcase": "^3.0.0", "url-loader": "^1.1.2", "vant-doc": "1.0.20", - "vue": "2.5.17", + "vue": "2.5.21", "vue-jest": "^3.0.1", "vue-loader": "^15.4.2", "vue-router": "^3.0.2", "vue-server-renderer": "^2.5.17", "vue-sfc-compiler": "^0.1.3", - "vue-template-compiler": "2.5.17", + "vue-template-compiler": "2.5.21", "vue-template-es2015-compiler": "^1.6.0", "webpack": "^4.26.1", "webpack-cli": "^3.1.2", diff --git a/packages/actionsheet/index.vue b/packages/actionsheet/index.vue index b684a44d3..71d6644d7 100644 --- a/packages/actionsheet/index.vue +++ b/packages/actionsheet/index.vue @@ -22,7 +22,11 @@ >