1. 程式人生 > >Vue中使用eslint

Vue中使用eslint

使用單引號,然後不用分號

1、.eslintrc.js

  module.exports = {
	root: true,
	parserOptions: {
	  parser: 'babel-eslint'
	},
	env: {
	  browser: true,
	},
	extends: [
	  'plugin:vue/essential',
	  'standard'
	],
	// required to lint *.vue files
	plugins: [
	  'vue'
	],
	// add your custom rules here
	rules: {
	  'no-multiple-empty-lines': 0,
	  'no-new':0,
	  indent: [1,"tab"],
	  'no-tabs': 0,
	  // allow async-await
	  'generator-star-spacing': 'off',
	  // allow debugger during development
	  'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 1,
	  // 禁止重複 import
	  "space-before-function-paren": ["off", "always"]
	}
  }

2、webpack.config加入如下程式碼

            {
				test: /\.(js|vue)$/,
				loader: 'eslint-loader',
				enforce: 'pre',
				include: [resolve('src'), resolve('test'), resolve('module')],
				exclude: /node_modules/,
				options: {
					formatter: require('eslint-friendly-formatter'),
					//不符合Eslint規則時只警告(預設執行出錯)
					emitWarning: true
				}
			}

3、.editorconfig

root = true
[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false

4、配置不希望eslint監測的檔案.eslintignore

# /node_modules/* and /bower_components/* in the project root are ignored by default

# Ignore built files except build/index.js
dist/*
!dist/index.js
module/*/vendor.js
README.md

如果還報錯的話就下載editorconfig外掛(直接在vscode裡搜尋安裝就好)