0.0.5 • Published 3 years ago
eslint-plugin-anker v0.0.5
eslint-plugin-anker
eslint-custom-anker
Installation
You'll first need to install ESLint:
npm i eslint --save-devNext, install eslint-plugin-anker:
npm install eslint-plugin-anker --save-devUsage
Add anker to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": [
"anker"
]
}Then configure the rules you want to use under the rules section.
{
"rules": {
"anker/necessary-optional-chaining": 2
}
}Rules
1. Necessary Optional Chaining (necessary-optional-chaining)
"?." 语法的强制性使用。
Rule Details
获取对象value时,必须使用 "?." 来避免key值不存在导致的报错。
Examples of incorrect code for this rule:
var a = A?.a
var b = A?.B?.b
var c = A?.[0]?.cExamples of correct code for this rule:
var a = A.a
var b = A.B.b
var c = A[0].c