mirror of
https://github.com/bendtherules/eslint-plugin-undef-init.git
synced 2026-08-18 22:02:50 +00:00
Add rule docs
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# eslint-plugin-undef-init
|
# eslint-plugin-undef-init
|
||||||
|
|
||||||
Always initialize variables declarations. Instead of naked declarations, set it to undefined.
|
Always initialize variables during declaration. Set it explicitly to undefined, if required.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -30,22 +30,37 @@ Add `undef-init` to the plugins section of your `.eslintrc` configuration file.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Then, either extend from the plugin or add the rules explicitly.
|
||||||
|
|
||||||
|
### A. Extend from plugin
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
// ... other extends here (like airbnb)
|
||||||
|
"undef-init"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## OR
|
||||||
|
|
||||||
|
### B. Use rule directly
|
||||||
|
|
||||||
Then configure the rules you want to use under the rules section.
|
Then configure the rules you want to use under the rules section.
|
||||||
|
|
||||||
```json
|
```js
|
||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"undef-init/rule-name": 2
|
"no-undef-init": 0, // Disable conflicting rule
|
||||||
|
"undef-init/undef-init": 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Supported Rules
|
## Supported Rules
|
||||||
|
|
||||||
* Fill in provided rules here
|
There is only one rule, for now -
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
* `undef-init` - Disallow variable declaration without initialization.
|
||||||
|
|
||||||
|
There is a built-in conflicting rule `no-undef-init` in eslint, so you'll need to disable it if you are using this rule
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Always initialize variables during declaration. Set it explicitly to undefined, if required. (undef-init)
|
# Always initialize variables during declaration. Set it explicitly to undefined, if required. (undef-init)
|
||||||
|
|
||||||
Please describe the origin of the rule here.
|
### It is better to explicitly initialize all variable declarations.
|
||||||
|
Instead of naked var / let declarations (which are implicitly set to `undefined` anyway), always explicitly set them to `undefined`. It makes clear that you explicitly intended to set them to undefined, not just because you forgot to initialize.
|
||||||
|
|
||||||
## Rule Details
|
## Rule Details
|
||||||
|
|
||||||
@@ -11,7 +11,13 @@ Examples of **incorrect** code for this rule:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
// fill me in
|
var a;
|
||||||
|
let b;
|
||||||
|
let c, d;
|
||||||
|
let d, e = 1;
|
||||||
|
|
||||||
|
for (var f of {}){var g;}
|
||||||
|
for (var i in []){var j;}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -19,18 +25,25 @@ Examples of **correct** code for this rule:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
||||||
// fill me in
|
var a = undefined;
|
||||||
|
let b = undefined;
|
||||||
|
let b1 = b;
|
||||||
|
let c = undefined, d = undefined;
|
||||||
|
|
||||||
|
for (var f of {}){var g = undefined;}
|
||||||
|
|
||||||
|
for (var i in []){do_something()}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
If there are any options, describe them here. Otherwise, delete this section.
|
There are no options
|
||||||
|
|
||||||
## When Not To Use It
|
## When Not To Use It
|
||||||
|
|
||||||
Give a short description of when it would be appropriate to turn off this rule.
|
If you feel setting vraiables implicitly to `undefined` is better than setting them explicitly, then don't use this - use `no-undef-init`.
|
||||||
|
|
||||||
## Further Reading
|
## More
|
||||||
|
|
||||||
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.
|
Ideally this would be a configuration in the in-built eslint rule `no-undef-init` instead of a separate rule, but wasn't accepted by maintainers. Hence, it's an external plugin.
|
||||||
@@ -14,8 +14,6 @@ module.exports = {
|
|||||||
meta: {
|
meta: {
|
||||||
docs: {
|
docs: {
|
||||||
description: ruleMessage,
|
description: ruleMessage,
|
||||||
category: "Fill me in",
|
|
||||||
recommended: false
|
|
||||||
},
|
},
|
||||||
fixable: "code",
|
fixable: "code",
|
||||||
schema: [
|
schema: [
|
||||||
|
|||||||
Reference in New Issue
Block a user