admin管理员组文章数量:1414621
Our code has bee a bit of a maintenance nightmare due to previous developers being liberal with single letter variables and little documentation. The latter we could deal with if the variables names were meaningful and self-descriptive. For this reason we are trying to set up eslint to avoid this going forward.
Our requirements:
- minimum of two characters, since
id
would be an acceptable variable - allow
i
andj
, since they are monly used in 'for' loops as indexes - allow single letter properties on json, to allow
point = { x: 2, y: 2 }
So far the best we have e up with is:
"id-length": [2, { "exceptions": ["i", "j"] }]
This covers points 1 and 2, but fails for point 3. Quoting single letter json attributes does not work for us to the quote-props
rule being present and that we would rather keep.
Can anyone suggest an eslint configuration that would allow to support all three requirements?
Our code has bee a bit of a maintenance nightmare due to previous developers being liberal with single letter variables and little documentation. The latter we could deal with if the variables names were meaningful and self-descriptive. For this reason we are trying to set up eslint to avoid this going forward.
Our requirements:
- minimum of two characters, since
id
would be an acceptable variable - allow
i
andj
, since they are monly used in 'for' loops as indexes - allow single letter properties on json, to allow
point = { x: 2, y: 2 }
So far the best we have e up with is:
"id-length": [2, { "exceptions": ["i", "j"] }]
This covers points 1 and 2, but fails for point 3. Quoting single letter json attributes does not work for us to the quote-props
rule being present and that we would rather keep.
Can anyone suggest an eslint configuration that would allow to support all three requirements?
Share Improve this question asked Aug 25, 2020 at 20:02 Andre MAndre M 7,5989 gold badges64 silver badges107 bronze badges1 Answer
Reset to default 8ESLint allows the rule to not be applied on object properties with "properties": never
. It's not enabled by default, so you have to specify it deliberately.
"rules": {
"id-length": [ 2, { "exceptions": ["i", "j"], "properties": "never" }]
}
本文标签: javascriptEslint rule to ensure minimum variable name lengthbut not on JSONStack Overflow
版权声明:本文标题:javascript - Eslint rule to ensure minimum variable name length, but not on JSON? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745186816a2646722.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论