-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Changes from all commits
bce42ee
933640b
e6d3be1
d4f82e6
e589f7d
439de38
6dacbcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,5 +370,33 @@ module.exports = { | |
|
||
return patternList.some(pattern => minimatch(filePath, pattern, opts)) && | ||
!excludedPatternList.some(excludedPattern => minimatch(filePath, excludedPattern, opts)); | ||
}, | ||
|
||
/** | ||
* Normalizes a value for a global in a config | ||
* @param {(boolean|string|null)} configuredValue The value given for a global in configuration or in | ||
* a global directive comment | ||
* @returns {("readable"|"writeable"|"off")} The value normalized as a string | ||
*/ | ||
normalizeConfigGlobal(configuredValue) { | ||
switch (configuredValue) { | ||
case "off": | ||
return "off"; | ||
|
||
case true: | ||
case "true": | ||
case "writeable": | ||
return "writeable"; | ||
|
||
case null: | ||
case false: | ||
case "false": | ||
case "readable": | ||
return "readable"; | ||
|
||
// Fallback to minimize compatibility impact | ||
default: | ||
return "writeable"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable writability is communicated to rules via the Previously, a non-boolean value in a 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 |
||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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".