User:Saul/eslint

From Organic Design wiki

Linting is a way to ensure your code follows convention.
The linting config file is stored as ".eslintrc.js"

npm i --save-dev eslint

# If using Vue
npm i --save-dev eslint-plugin-html

# If using TypeScript
npm i --save-dev @typescript-eslint/eslint-plugin @typescript-eslint/parser

Here is the rule set I like to use:

module.exports = {
	// If using typescript:
	//parser: "@typescript-eslint/parser",

	parserOptions: {
		ecmaVersion: "latest"
	},
	env: {
		// For nodejs
		commonjs: true,
		es2021: true,
		node: true

		// For browser:
		browser: true,
	},
	extends: "eslint:recommended",
	// required to lint *.vue files
	// plugins: [ "html" ],
	rules: {
		curly: [1, "all"],
		// disallow single quotes
		quotes: [1, "double", { allowTemplateLiterals: true }],
		// force semi-colons
		semi: 1,
		// allow tabs
		"no-tabs": [0],
		// use tab indentation
		indent: [1, "tab", {
			SwitchCase: 1
		}],
		// prevent commar dangles
		"comma-dangle": [1, "never"],
		// allow paren-less arrow functions
		"arrow-parens": 0,
		// allow async-await
		"generator-star-spacing": 0,
		"no-unused-vars": [1, { args: "after-used", vars: "local" }],
		"no-constant-condition": 0,
		// allow debugger during development
		"no-debugger": process.env.NODE_ENV === "production" ? 2 : 0
	}
};