Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
manjuu-eater opened this issue Jan 11, 2023 · 1 comment

Comments

@manjuu-eater
Copy link

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
Copy link
Collaborator

ljharb commented Jan 11, 2023

"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 #1946 (review), this would be both an acceptable but valueless change. Feel free to submit a PR if you feel strongly about it.

@ljharb ljharb closed this as completed Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants