javascript - Eslint rule to ensure minimum variable name length, but not on JSON? - Stack Overflow

Our code has bee a bit of a maintenance nightmare due to previous developers being liberal with single

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:

  1. minimum of two characters, since id would be an acceptable variable
  2. allow i and j, since they are monly used in 'for' loops as indexes
  3. 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:

  1. minimum of two characters, since id would be an acceptable variable
  2. allow i and j, since they are monly used in 'for' loops as indexes
  3. 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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

ESLint 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" }]
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745186816a4615675.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信