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
Globals configuration is unintuitive #9940
Globals configuration is unintuitive #9940
Comments
As you correctly mentioned, this is due to legacy support for JSHint. I remember when it was implemented, there was some discussion about it, but that was pretty early on, and we decided to follow JSHint notation (seeing how it would help people migrate from JSHint without having to update all of their files manually). |
I'd like to see this get implemented in 5.x. Curious to see what the rest of @eslint/eslint-team thinks. |
👍 but I noticed that you used "read-only" to describe the |
I don't feel strongly either way, but I would speculate that configuration keywords might be slightly easier to use when they don't have internal punctuation, because they would be easier to understand when spoken aloud (without needing to say something like "read dash only"), and they would be consistent with our other configuration keywords (none of which have punctuation). There is precedent for using the term A third option would be to just use the word |
I'll mark it as accepted, since this has been up-voted by 5 members of TSC. In terms of the name, I would vote for either |
@aladdin-add it looks like you started working on this. Are you still working on this? |
As described in #9940, this allows globals in a config file to be specified with the strings `readable` and `writeable` rather than `false` and `true`, respectively. It also adds a new value, `off`, which turns off a previously-enabled global.
As described in #9940, this allows globals in a config file to be specified with the strings `readable` and `writeable` rather than `false` and `true`, respectively. It also adds a new value, `off`, which turns off a previously-enabled global.
As described in #9940, this allows globals in a config file to be specified with the strings `readable` and `writeable` rather than `false` and `true`, respectively. It also adds a new value, `off`, which turns off a previously-enabled global.
Previous issues: #4734, #5765
Background
Currently (ESLint v4.17.0), the
globals
value in a config file allows a user to configure globals for their project. The configuration looks like this, where each global is given a boolean value:Similarly, a boolean value can be used in a
/* global */
comment directive to enable globals for a file:/* global Foo: true, Bar: false, baz: false */
A value of
true
indicates that a global is allowed to be rewritten, and a value offalse
indicates that a global is read-only. This behavior is inherited from JSHint and JSLint.Problem
There are a few disadvantages to the current behavior:
true
(rewritable) andfalse
(read-only). This will make it more complex to enable a set of globals by default in the future (e.g. when we start supporting ES6 by default), because users will not be able to disable the globals.true
/false
and "rewritable"/"read-only" is somewhat arbitrary, which makes it confusing to users. Anecdotally, I had been on the ESLint team for almost a year before I learned that/* global Foo: false */
would makeFoo
read-only. (I had previously thought that it would turn offFoo
.)The root cause of these problems is that there are three possible states of a global ("not present", "present but read-only", and "present and writable") but we only allow them to be configured with a boolean field.
Proposal
We should start allowing string values for globals. The possible values are (bikesheddable):
readonly
to indicate that a global is read-only (same asfalse
)writable
to indicate that a global is writable (same astrue
)off
to indicate that a global is not presentTo encourage people to use the new forms, we should deprecate the use of
true
andfalse
for configuring globals. (However, for backwards compatibility,true
andfalse
would continue to be supported without a warning for the foreseeable future.)The text was updated successfully, but these errors were encountered: