Good code is its own best documentation. β Steve McConnell
Enforce variable names to include their type (declare-keyword
) β
πΌ This rule is enabled in the following configs: π all
, β
recommended
.
π§ This rule is automatically fixable by the --fix
CLI option.
π Rule details β
Don't you hate it when you're unsure whether you can mutate a variable because it's declared with const, or if you're dealing with a class that can be instantiated?
By prefixing the variable name with its type, you can easily avoid these confusions and have a clearer understanding of your code at a glance.
βοΈ Options β
side β
(default: natural
)
start
- the type must be at the start of the variable nameend
- the type must be at the end of the variable namenatural
- the type must be at the natural position of the variable name (start for consts, end for classes, etc.)
oneLetter β
(default: false
)
If true, the type must be a single letter (e.g. cName
for a const, eName
for an enum, etc.). Classes get k
, not to be confused with consts.
π§ Config β
js
{ rules: { 'ninja/declare-keyword': [2, { side: 'start', oneLetter: false }] } }