Sentence "Enforce spacing inside of computed property brackets" is confusing

1
closed
manjuu-eater
manjuu-eater
Posted 2 months ago

Sentence "Enforce spacing inside of computed property brackets" is confusing #2711

When I read this sentence, I thought like this:

// bad: freedom spacing (hard to read)
obj[foo ]
obj[ 'foo']
const x = {[ b ]: a}
obj[foo[ bar ]]

// good: forced to spacing inside brackets (easy to read)
obj[ foo ]
obj[ 'foo' ]
const x = { [ b ]: a }
obj[ foo[ bar ] ]

But, it was wrong. Correct answer is this:

  • 19.16 Enforce spacing inside of computed property brackets. eslint: computed-property-spacing

    // bad
    obj[foo ]
    obj[ 'foo']
    const x = {[ b ]: a}
    obj[foo[ bar ]]
    
    // good
    obj[foo]
    obj['foo']
    const x = { [b]: a }
    obj[foo[bar]]
    

I have some possible solutions:

  1. Change the word "enforce" to "avoid".
  2. Exclude explaining about spacing in "{}" from sample code. (already talken in about eslint: object-curly-spacing and eslint: block-spacing)

or,

  1. Use ESLint official sentence "Enforce consistent spacing inside computed property brackets".

Similar Issues and PRs exist already and some have been merged:

reference: https://www.merriam-webster.com/dictionary/enforce

ljharb
ljharb
Created 2 months ago

"enforce" is the correct English word, because it does not imply either "forced" or "prohibited", and because "no spaces" is also "spacing".

Similarly to #1946, we could tweak the wording here, but just like https://github.com/airbnb/javascript/pull/1946#pullrequestreview-171808707, this would be both an acceptable but valueless change. Feel free to submit a PR if you feel strongly about it.