Skip to content

Commit

Permalink
config eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
JulCyan committed Dec 15, 2019
1 parent 313617f commit ec35d3a
Show file tree
Hide file tree
Showing 14 changed files with 1,349 additions and 125 deletions.
104 changes: 104 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
module.exports = {
root: true,
env: {
node: true,
browser: true,
},
extends: [
'eslint:recommended',
'plugin:vue/recommended',
// '@vue/typescript'
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// 结尾不允许有分号
semi: [2, 'never'],
// error; 一个缩进必须用四个空格替代, switch语句里面的case 2个空格
indent: [1, 2, {
SwitchCase: 2
}],
// error; 必须使用单引号
quotes: [2, 'single', {
avoidEscape: true,
allowTemplateLiterals: true
}],
// warn; 不允许多个空行
'no-multiple-empty-lines': [1, {
max: 1
}],
// error; 箭头函数的箭头前后必须有空格
'arrow-spacing': [2, {
before: true,
after: true
}],
// warn; 推荐使用箭头函数作为回调
'prefer-arrow-callback': [1, {
allowNamedFunctions: true
}],
// warn; 推荐结构赋值
'prefer-destructuring': [
1,
{
array: true,
object: true
},
{
enforceForRenamedProperties: false
}
],
// warn; 推荐rest运算符
'prefer-rest-params': 1,
// warn; 推荐扩展运算符
'prefer-spread': 1,
// error; require symbol description
'symbol-description': 2,
// error; 禁止import重复模块
'no-duplicate-imports': 2,
// error; 要求使用 let 或 const 而不是 var
'no-var': 2,
// error; if, function 等的大括号之前必须要有空格
'space-before-blocks': [2, 'always'],
// error; 逗号风格,换行时在行首还是行尾
'comma-style': [2, 'last'],
// error; 变量命名需要以驼峰命名法,对属性字段不做限制
camelcase: [2, {
properties: 'never'
}],
// error; 是否允许非空数组里面有多余的空格
'array-bracket-spacing': [2, 'never'],
// error; 禁用特定的全局变量
'no-restricted-globals': 2,
// error; 禁止变量声明与外层作用域的变量同名
'no-shadow': 2,
// error; js关键字和保留字不能作为函数名或者变量名
'no-shadow-restricted-names': 2,
// error; 禁止label名称和var相同
'no-label-var': 2,
// error; 避免初始化变量值为 undefined
'no-undef-init': 2,
// error; 变量使用之前必须进行定义,函数除外
'no-use-before-define': [2, {
functions: false
}],
// error; 禁止 catch 子句的参数与外层作用域中的变量同名
'no-catch-shadow': 2,
// error; getter必须有返回值,并且禁止返回值为undefined, 比如 return;
'getter-return': [2, {
allowImplicit: false
}],
// error; 强制 getter 和 setter 在对象中成对出现
'accessor-pairs': 2,
// off; 对于数据相关操作函数比如reduce, map, filter等,callback必须有return
'array-callback-return': 0,
// error; switch case语句里面一定需要default分支
'default-case': 2,
// error; 要求点操作符和属性放在同一行
'dot-location': [2, 'property'],
// error; 代码中不允许使用eval
'no-eval': 2
},
parserOptions: {
// parser: '@typescript-eslint/parser'
}
}
15 changes: 13 additions & 2 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const HtmlWebpackPlugin = require('html-webpack-plugin')
const {
CleanWebpackPlugin,
} = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const base = {
path: path.join(__dirname, '..')
}
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
// const lastStyleLoader = MiniCssExtractPlugin.loader
const lastStyleLoader = 'style-loader'
Expand Down Expand Up @@ -88,6 +88,17 @@ module.exports = {
test: /\.(woff|woff2|eot|svg|ttf)$/,
use: 'url-loader'
},
// js eslint
{
test: /\.js$/,
loader: 'eslint-loader',
enforce: 'pre',
// include: [path.resolve(__dirname, 'src')], // 指定检查的目录
exclude: /node_modules/,
options: { // 这里的配置项参数将会被传递到 eslint 的 CLIEngine
formatter: require('eslint-tap') // 指定错误报告的格式规范
}
},
// js
{
test: /\.js$/,
Expand Down
7 changes: 2 additions & 5 deletions config/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const merge = require('webpack-merge')
const config = require('./webpack.config')
const TerserJSPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
// const TerserJSPlugin = require('terser-webpack-plugin')
// const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const {
DefinePlugin
} = require('webpack')
Expand All @@ -18,9 +18,6 @@ module.exports = merge(config, {
API_URL: '"yyyyyy"'
}
}),
// new MiniCssExtractPlugin({
// filename: '[name][hash:8].css'
// })
],
devtool: 'none',
// optimization: {
Expand Down
1 change: 0 additions & 1 deletion forget.txt

This file was deleted.

32 changes: 25 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server --config ./config/webpack.dev.js",
"build": "webpack --config ./config/webpack.prod.js"
"build": "webpack --config ./config/webpack.prod.js",
"lint": "eslint --fix --ext .js --ext .ts --ext .jsx --ext .tsx --ext .vue src/"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@babel/polyfill": "^7.7.0",
"axios": "^0.19.0",
"vue": "^2.6.11",
"vue-router": "^3.1.3",
"vuex": "^3.1.2"
},
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
Expand All @@ -39,11 +47,17 @@
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.1.1",
"css-loader": "^3.3.2",
"eslint": "^6.7.2",
"eslint-loader": "^3.0.3",
"eslint-plugin-vue": "^6.0.1",
"eslint-tap": "^2.0.1",
"file-loader": "^5.0.2",
"html-webpack-plugin": "^3.2.0",
"html-withimg-loader": "^0.1.16",
"husky": "^3.1.0",
"less": "^3.10.3",
"less-loader": "^5.0.0",
"lint-staged": "^9.5.0",
"mini-css-extract-plugin": "^0.8.0",
"node-sass": "^4.13.0",
"optimize-css-assets-webpack-plugin": "^5.0.3",
Expand All @@ -59,11 +73,15 @@
"webpack-dev-server": "^3.9.0",
"webpack-merge": "^4.2.2"
},
"dependencies": {
"@babel/polyfill": "^7.7.0",
"axios": "^0.19.0",
"vue": "^2.6.11",
"vue-router": "^3.1.3",
"vuex": "^3.1.2"
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,vue,ts}": [
"yarn lint",
"git add"
]
}
}
2 changes: 2 additions & 0 deletions remember.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
静态资源拷贝问题 public 下 图片 报错
eslint 格式化 import()语法 报错
53 changes: 31 additions & 22 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<template>
<div class="app-container">
<p> {{ title }} </p>
<p> 作者是 {{ $store.state.author }}</p>
<div @click="add" class="app-btn">这是按钮</div>
<router-link to="/home">home</router-link>
<router-link to="/about">about</router-link>
<router-view></router-view>
</div>
<div class="app-container">
<p> {{ title }} </p>
<p> 作者是 {{ $store.state.author }}</p>
<div
class="app-btn"
@click="add"
>
这是按钮
</div>
<router-link to="/home">
home
</router-link>
<router-link to="/about">
about
</router-link>
<router-view />
</div>
</template>
<style scoped lang="less">
.app-container {
Expand All @@ -17,19 +26,19 @@
</style>
<script>
export default {
data() {
return {
title: '这是使用 webpack 构建的'
}
},
methods: {
add () {
console.log('1111111111111')
}
},
created() {
console.log('app 构建了')
this.$axios('getUserInfo')
},
data() {
return {
title: '这是使用 webpack 构建的'
}
},
created() {
console.log('app 构建了')
this.$axios('getUserInfo')
},
methods: {
add () {
console.log('1111111111111')
}
},
}
</script>
4 changes: 2 additions & 2 deletions src/configs/decorator/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const Throttle = (target, name, description) => {
console.log(name);
export const Throttle = (target, name) => {
console.log(name)
}
export const name = '3333'
30 changes: 15 additions & 15 deletions src/plugins/axios/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import axios from 'axios'

let instance = axios.create({
baseURL: 'api/',
timeout: 10 * 1000,
headers: {
post: {
'Content-Type': 'application/json'
}
},
// post json 转 表单
// transformRequest: [function (data) {
// let ret = ''
// for (let it in data) {
// ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
// }
// return ret
// }],
baseURL: 'api/',
timeout: 10 * 1000,
headers: {
post: {
'Content-Type': 'application/json'
}
},
// post json 转 表单
// transformRequest: [function (data) {
// let ret = ''
// for (let it in data) {
// ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
// }
// return ret
// }],
})

export default instance
20 changes: 10 additions & 10 deletions src/plugins/router/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import VueRouter from 'vue-router'
import Index from '@/views/Home/index.vue'
const router = new VueRouter({
routes: [{
path: '/',
component: Index,
alias: '/home'
},
{
path: '/about',
component: () => import(`@/views/About/index.vue`)
}
]
routes: [{
path: '/',
component: Index,
alias: '/home'
},
{
path: '/about',
component: () => require('@/views/About/index.vue')
}
]

})

Expand Down
Loading

0 comments on commit ec35d3a

Please sign in to comment.