eslint-config-dt-insight
English | 简体中文 (Simplified Chinese)
An eslint shareable config for dt-insight Code Style Guide
This module saves time in three ways for you:
- No configuration - The easier way to enforce code quality in your project. No configuration rules. It just works.
-
Automatically format code - Just run
yarn lint-fix
and say goodbye to messy or inconsistent code. - Catch style issues & programmer errors early - Reduce manual review in the code review process, and leave simple things to tools to save time.
No hesitation. No more maintenance .eslintrc
. Give it a try right now!
Detailed rules
- four spaces are required – indent
- single quotation marks are required for string – except where escape is need
-
require keyword followed by space -
if (condition) {...}
-
requires no spaces after the function name -
function name (arg) {...}
except anonymous functions and asyncfunction (arg) {...} `` async () { ... }
- semicolons are not mandatory
- not mandatory = = = - the field type returned by the backend cannot be guaranteed
- do not force ternary operators to wrap
- allow but do not require trailing commas - when the last element or attribute is on a different line from the end or attribute
- function content is allowed to be empty
-
allow this alias - alias optional
self
_this
`that', cannot be deconstructed from this - no debugger required
- no console is recommended
Install
yarn add eslint-config-dt-insight -D
Usage
Shareable configs are designed to work with the extends
feature of .eslintrc
files.
You can learn more about
Shareable Configs on the
official ESLint website.
1、Then, add this to your .eslintrc
file:
{
"extends": "dt-insight"
}
Note: We omitted the eslint-config-
prefix since it is automatically assumed by ESLint.
You can not override settings. Because this is a Code Style Guide for dt-insight's project.
2、Add script to package.json
:
"scripts": {
"lint": "npx eslint './src/**/*.ts' './src/**/*.tsx'",
"lint-fix": "npx eslint './src/**/*.ts' './src/**/*.tsx' --fix"
},
You can use yarn lint-fix
to correct most code style problems.
How do I disable a rule?
In rare cases, you'll need to break a rule and hide the error generated by Code Style Guide
.
eslint-config-dt-insight
uses ESLint under-the-hood and
you can hide errors as you normally would if you used ESLint directly.
Disable all rules on a specific line:
file = 'I know what I am doing' // eslint-disable-line
Or, disable only the "no-use-before-define"
rule:
file = 'I know what I am doing' // eslint-disable-line no-use-before-define
Or, disable the "no-use-before-define"
rule for multiple lines:
/* eslint-disable no-use-before-define */
console.log('offending code goes here...')
console.log('offending code goes here...')
console.log('offending code goes here...')
/* eslint-enable no-use-before-define */
Looking for something easier than this?
You can add to your yarn lint
script and install eslint plugin for vscode.
Learn more
License
MIT. Copyright (c) 2022 dt-insight