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

Globals configuration is unintuitive #9940

Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue

Comments

@not-an-aardvark
Copy link
Member

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:

{
  "globals": {
    "Foo": true,
    "Bar": false,
    "baz": false
  }
}

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 of false 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:

  • Globals from an inherited config file cannot be turned off; they can only be reconfigured to true (rewritable) and false (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.
  • The correlation between 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 make Foo read-only. (I had previously thought that it would turn off Foo.)

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 as false)
  • writable to indicate that a global is writable (same as true)
  • off to indicate that a global is not present

To encourage people to use the new forms, we should deprecate the use of true and false for configuring globals. (However, for backwards compatibility, true and false would continue to be supported without a warning for the foreseeable future.)

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Feb 4, 2018
@ilyavolodin
Copy link
Member

ilyavolodin commented Feb 6, 2018

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'm not opposed to enhancing this, but I think we have to keep it backwards-compatible.

@platinumazure
Copy link
Member

platinumazure commented Jun 22, 2018

I'd like to see this get implemented in 5.x. Curious to see what the rest of @eslint/eslint-team thinks.

@michaelficarra
Copy link
Member

👍 but I noticed that you used "read-only" to describe the readonly option, so why not just use read-only?

@not-an-aardvark
Copy link
Member Author

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 readonly without a dash in C#.

A third option would be to just use the word readable for consistency with writable. That would have the possibility to be misleading if someone thinks a variable can be writable without being readable, but I'm not sure if this would actually cause much confusion in practice.

@ilyavolodin ilyavolodin added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jun 26, 2018
@ilyavolodin
Copy link
Member

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 readonly or readable. Although I don't think latter conveys the right meaning.

@kaicataldo kaicataldo added help wanted The team would welcome a contribution from the community for this issue Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Oct 15, 2018
@nzakas
Copy link
Member

nzakas commented Nov 7, 2018

@aladdin-add it looks like you started working on this. Are you still working on this?

@kaicataldo kaicataldo removed Hacktoberfest Recommended issue for those participating in Hacktoberfest https://hacktoberfest.digitalocean.com/ labels Nov 13, 2018
not-an-aardvark added a commit that referenced this issue Jan 31, 2019
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.
not-an-aardvark added a commit that referenced this issue Jan 31, 2019
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.
not-an-aardvark added a commit that referenced this issue Jan 31, 2019
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.
@not-an-aardvark not-an-aardvark self-assigned this Jan 31, 2019
@btmills btmills closed this as completed in 0a3c3ff Feb 1, 2019
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 1, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint help wanted The team would welcome a contribution from the community for this issue
Projects
None yet
7 participants