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

New: Allow globals to be disabled/configured with strings (fixes #9940) #11338

Merged
merged 7 commits into from Feb 1, 2019

Conversation

Projects
None yet
5 participants
@not-an-aardvark
Copy link
Member

not-an-aardvark commented Jan 31, 2019

What is the purpose of this pull request? (put an "X" next to item)

[x] Add something to the core

What changes did you make? (Give an overview)

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.

Is there anything you'd like reviewers to focus on?

Nothing in particular

New: Allow globals to be disabled/configured with strings (fixes #9940)
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 force-pushed the string-globals branch from 63672ed to bce42ee Jan 31, 2019

@@ -208,19 +208,19 @@ To specify globals using a comment inside of your JavaScript file, use the follo
/* global var1, var2 */
```

This defines two global variables, `var1` and `var2`. If you want to optionally specify that these global variables should never be written to (only read), then you can set each with a `false` flag:
This defines two global variables, `var1` and `var2`. If you want to optionally specify that these global variables can be written to (rather than only being read), then you can set each with a `writeable` flag:

This comment has been minimized.

@not-an-aardvark

not-an-aardvark Jan 31, 2019

Author Member

This documentation was previously misleading -- it implied that "writeable" was the default for global comments like /* global foo */, but in fact the default seems to be "readable".

Show resolved Hide resolved docs/user-guide/configuring.md

// Fallback to minimize compatibility impact
default:
return "writeable";

This comment has been minimized.

@not-an-aardvark

not-an-aardvark Jan 31, 2019

Author Member

Variable writability is communicated to rules via the variable.writeable boolean property in scope analysis.

Previously, a non-boolean value in a globals configuration would actually get passed directly to rules through scope analysis, so a configuration of {globals: {myGlobal: "foo"}} would end up as a variable object with variable.writeable = "foo".

Strictly speaking, we don't have any compatibility guarantees for non-boolean values here, since it's undocumented behavior. But since someone is probably relying on this by mistake (e.g. from a malformed config comment), I put in a fallback so that unexpected globals values default to "writeable" (and appear to rules as writeable: true). This fallback seems most likely to match existing behavior when users have malformed configs, since rules using this would typically be doing truthiness checks.

@aladdin-add aladdin-add self-requested a review Jan 31, 2019

@platinumazure
Copy link
Member

platinumazure left a comment

Direction looks good. I look forward to landing this!

Left a few inline comments.

Show resolved Hide resolved docs/user-guide/configuring.md
Show resolved Hide resolved docs/user-guide/configuring.md Outdated
```

These examples allow `var1` to be overwritten in your code, but disallow it for `var2`.

For historical reasons, the boolean values `false` and `true` can also be used to configure globals, and are equivalent to `"readable"` and `"writeable"`, respectively. However, this usage of booleans is deprecated.

This comment has been minimized.

@platinumazure

platinumazure Jan 31, 2019

Member

Not a blocker: Do we have a way to stylistically indicate that this is an aside? (I'm assuming not and that this would be a wider information architecture question, but wanted to ask.)

Also: I wonder if this should go below the next section on disabling globals? (Edit: Or another possibility might be to use subsections for enabling globals [read/write], and disabling [off], in which case the paragraph probably shouldn't move, but everything would flow a little better because the subsection headers would serve as natural breaks.)

This comment has been minimized.

@not-an-aardvark

not-an-aardvark Jan 31, 2019

Author Member

I moved this line below the section about disabling globals.

I think this line will be useful for users figuring out what's going on in existing configs containing booleans, so I don't want to make it too much of a footnote. I was thinking about preceding this line with "Note:", but in the new location this line is followed by another line that also starts with "Note:", which would look a bit strange. That said, I'm open to stylistic suggestions.

Show resolved Hide resolved lib/linter.js Outdated
Show resolved Hide resolved lib/linter.js Outdated
Show resolved Hide resolved lib/linter.js Outdated
Show resolved Hide resolved tests/lib/config/config-ops.js

platinumazure and others added some commits Jan 31, 2019

Update lib/linter.js
Co-Authored-By: not-an-aardvark <teddy.katz@gmail.com>
Update docs/user-guide/configuring.md
Co-Authored-By: not-an-aardvark <teddy.katz@gmail.com>
@platinumazure
Copy link
Member

platinumazure left a comment

LGTM, thanks!

@btmills

btmills approved these changes Feb 1, 2019

@btmills btmills merged commit 0a3c3ff into master Feb 1, 2019

5 checks passed

commit-message PR title follows commit message guidelines
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details

@not-an-aardvark not-an-aardvark deleted the string-globals branch Feb 1, 2019

PlayMa256 added a commit to PlayMa256/GrCartuchos that referenced this pull request Feb 1, 2019

Update eslint in group default to the latest version 🚀 (#125)
## The devDependency [eslint](https://github.com/eslint/eslint) was updated from `5.12.1` to `5.13.0`.
This version is **not covered** by your **current version range**.

If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

---

<details>
<summary>Release Notes for v5.13.0</summary>

<ul>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/91c8884971f5e57f5f7490d8daf92c4a9a489836"><code>91c8884</code></a> Chore: use local function to append "s" instead of a package (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="400953921" data-permission-text="Issue title is private" data-url="eslint/eslint#11293" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11293/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11293">#11293</a>) (Timo Tijhof)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/b5143bfc09e53d8da8f63421ade093b7593f4f51"><code>b5143bf</code></a> Update: for-direction detection false positives/negatives (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="397135133" data-permission-text="Issue title is private" data-url="eslint/eslint#11254" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11254/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11254">#11254</a>) (Ruben Bridgewater)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/9005e632d13476880c55f7e3c8a6e450762a5171"><code>9005e63</code></a> Chore: increase camelcase test coverage (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="401174018" data-permission-text="Issue title is private" data-url="eslint/eslint#11299" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11299/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11299">#11299</a>) (Redmond Tran)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/5b14ad1003c7df9a37621dea55c6d6d0484adc05"><code>5b14ad1</code></a> Fix: false positive in no-constant-condition (fixes <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="401916289" data-permission-text="Issue title is private" data-url="eslint/eslint#11306" data-hovercard-type="issue" data-hovercard-url="/eslint/eslint/issues/11306/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/issues/11306">#11306</a>) (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="402047796" data-permission-text="Issue title is private" data-url="eslint/eslint#11308" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11308/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11308">#11308</a>) (Pig Fang)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/6567c4f6665df85c3347388b29d8193cc8208d63"><code>6567c4f</code></a> Fix: only remove arrow before body in object-shorthand (fixes <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="401807378" data-permission-text="Issue title is private" data-url="eslint/eslint#11305" data-hovercard-type="issue" data-hovercard-url="/eslint/eslint/issues/11305/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/issues/11305">#11305</a>) (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="402033639" data-permission-text="Issue title is private" data-url="eslint/eslint#11307" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11307/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11307">#11307</a>) (Pig Fang)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/fa2f370affa4814dbdda278f9859d0172d4b7aa2"><code>fa2f370</code></a> Docs: update rule configuration values in examples (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="404018485" data-permission-text="Issue title is private" data-url="eslint/eslint#11323" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11323/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11323">#11323</a>) (Kai Cataldo)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/0a3c3ff1d91e8f39943efc4a7d2bf6927d68d37e"><code>0a3c3ff</code></a> New: Allow globals to be disabled/configured with strings (fixes <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="294234548" data-permission-text="Issue title is private" data-url="eslint/eslint#9940" data-hovercard-type="issue" data-hovercard-url="/eslint/eslint/issues/9940/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/issues/9940">#9940</a>) (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="405027784" data-permission-text="Issue title is private" data-url="eslint/eslint#11338" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11338/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11338">#11338</a>) (Teddy Katz)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/dccee63cf41234180c71bf0fe01b165c9078fc69"><code>dccee63</code></a> Chore: avoid hard-coding the list of core rules in eslint:recommended (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="404605578" data-permission-text="Issue title is private" data-url="eslint/eslint#11336" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11336/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11336">#11336</a>) (Teddy Katz)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/c1fd6f54d92efe615bcae529006221e122dbe9e6"><code>c1fd6f5</code></a> Chore: remove undocumented <code>Linter#rules</code> property (refs <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="253051999" data-permission-text="Issue title is private" data-url="eslint/eslint#9161" data-hovercard-type="issue" data-hovercard-url="/eslint/eslint/issues/9161/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/issues/9161">#9161</a>) (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="404599049" data-permission-text="Issue title is private" data-url="eslint/eslint#11335" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11335/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11335">#11335</a>) (Teddy Katz)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/36e335681d61cbe3c83b653b7cc5f95730f1d86e"><code>36e3356</code></a> Chore: remove dead code for loading rules (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="404588598" data-permission-text="Issue title is private" data-url="eslint/eslint#11334" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11334/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11334">#11334</a>) (Teddy Katz)</li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/c464e2744ec76e7e9c6c5af0f6162c92187f1ece"><code>c464e27</code></a> Docs: Rename <code>result</code> -&gt; <code>foo</code> (<a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="394168276" data-permission-text="Issue title is private" data-url="eslint/eslint#11210" data-hovercard-type="pull_request" data-hovercard-url="/eslint/eslint/pull/11210/hovercard" href="https://urls.greenkeeper.io/eslint/eslint/pull/11210">#11210</a>) (Alexis Tyler)</li>
</ul>
</details>

<details>
<summary>Commits</summary>
<p>The new version differs by 13 commits.</p>
<ul>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/4b267a5c8a42477bb2384f33b20083ff17ad578c"><code>4b267a5</code></a> <code>5.13.0</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/720dce11ed89ce17ce3600044fd8e45145d353eb"><code>720dce1</code></a> <code>Build: changelog update for 5.13.0</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/91c8884971f5e57f5f7490d8daf92c4a9a489836"><code>91c8884</code></a> <code>Chore: use local function to append "s" instead of a package (#11293)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/b5143bfc09e53d8da8f63421ade093b7593f4f51"><code>b5143bf</code></a> <code>Update: for-direction detection false positives/negatives (#11254)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/9005e632d13476880c55f7e3c8a6e450762a5171"><code>9005e63</code></a> <code>Chore: increase camelcase test coverage (#11299)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/5b14ad1003c7df9a37621dea55c6d6d0484adc05"><code>5b14ad1</code></a> <code>Fix: false positive in no-constant-condition (fixes #11306) (#11308)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/6567c4f6665df85c3347388b29d8193cc8208d63"><code>6567c4f</code></a> <code>Fix: only remove arrow before body in object-shorthand (fixes #11305) (#11307)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/fa2f370affa4814dbdda278f9859d0172d4b7aa2"><code>fa2f370</code></a> <code>Docs: update rule configuration values in examples (#11323)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/0a3c3ff1d91e8f39943efc4a7d2bf6927d68d37e"><code>0a3c3ff</code></a> <code>New: Allow globals to be disabled/configured with strings (fixes #9940) (#11338)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/dccee63cf41234180c71bf0fe01b165c9078fc69"><code>dccee63</code></a> <code>Chore: avoid hard-coding the list of core rules in eslint:recommended (#11336)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/c1fd6f54d92efe615bcae529006221e122dbe9e6"><code>c1fd6f5</code></a> <code>Chore: remove undocumented <code>Linter#rules</code> property (refs #9161) (#11335)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/36e335681d61cbe3c83b653b7cc5f95730f1d86e"><code>36e3356</code></a> <code>Chore: remove dead code for loading rules (#11334)</code></li>
<li><a href="https://urls.greenkeeper.io/eslint/eslint/commit/c464e2744ec76e7e9c6c5af0f6162c92187f1ece"><code>c464e27</code></a> <code>Docs: Rename <code>result</code> -&gt; <code>foo</code> (#11210)</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/eslint/eslint/compare/faf3c4eda0d27323630d0bc103a99dd0ecffe842...4b267a5c8a42477bb2384f33b20083ff17ad578c">full diff</a></p>
</details>

<details>
  <summary>FAQ and help</summary>

  There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>

---


Your [Greenkeeper](https://greenkeeper.io) bot 🌴

not-an-aardvark added a commit that referenced this pull request Mar 16, 2019

Breaking: throw an error for invalid global configs (refs #11338)
Previously, invalid values for `globals` configurations would default to `writable`. This change updates those cases to throw an error instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.