Difference between revisions of "User:Saul/eslint"

From Organic Design wiki
(Added dependencies.)
(Updated ruleset.)
Line 10: Line 10:
 
module.exports = {
 
module.exports = {
 
root: true,
 
root: true,
parser: 'babel-eslint',
+
parser: "babel-eslint",
 
parserOptions: {
 
parserOptions: {
sourceType: 'module'
+
sourceType: "module"
 
},
 
},
 
env: {
 
env: {
Line 18: Line 18:
 
},
 
},
 
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
 
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
extends: 'standard',
+
extends: "standard",
 
// required to lint *.vue files
 
// required to lint *.vue files
 
plugins: [
 
plugins: [
'html'
+
"html"
 
],
 
],
'rules': {
+
"rules": {
 
// disallow single quotes
 
// disallow single quotes
 
"quotes": ["error", "double"],
 
"quotes": ["error", "double"],
Line 33: Line 33:
 
"indent": ["error", "tab"],
 
"indent": ["error", "tab"],
 
// allow paren-less arrow functions
 
// allow paren-less arrow functions
'arrow-parens': 0,
+
"arrow-parens": 0,
 
// allow async-await
 
// allow async-await
'generator-star-spacing': 0,
+
"generator-star-spacing": 0,
 
// allow debugger during development
 
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
+
"no-debugger": process.env.NODE_ENV === "production" ? 2 : 0
 
}
 
}
}
+
};
 
</source>
 
</source>

Revision as of 21:22, 7 August 2018

Linting is a way to ensure your code follows convention.
There is a package for the text editor atom (atom.io) that intergrates linting, the package is called: "linter-eslint"
The linting config file is stored as ".eslintrc.js"
Here are the dependencies needed for linting vue:

npm i -D babel-eslint eslint eslint-config-standard eslint-plugin-html eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard

Here is the rule set I like to use:

module.exports = {
	root: true,
	parser: "babel-eslint",
	parserOptions: {
		sourceType: "module"
	},
	env: {
		browser: true,
	},
	// https://github.com/standard/standard/blob/master/docs/RULES-en.md
	extends: "standard",
	// required to lint *.vue files
	plugins: [
		"html"
	],
	"rules": {
		// disallow single quotes
		"quotes": ["error", "double"],
		// force semi-colons
		"semi": ["error", "always"],
		// allow tabs
		"no-tabs": [0],
		// use tab indentation
		"indent": ["error", "tab"],
		// allow paren-less arrow functions
		"arrow-parens": 0,
		// allow async-await
		"generator-star-spacing": 0,
		// allow debugger during development
		"no-debugger": process.env.NODE_ENV === "production" ? 2 : 0
	}
};