Skip to content

Commit

Permalink
Update: globals configuration support readonly/writable/off (fixes es…
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Aug 16, 2018
1 parent 985567d commit 9b23504
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ function parseListConfig(string) {
return items;
}

/**
* normize globals config to new-style:
* - 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
* @param {boolean|string} config The given global config, can be old-style: true/false
* @returns {string} normalized new-style globals
*/
function normalizeGlobalConfig(config) {
return config === true ? "writable" // eslint-disable-line no-nested-ternary
: (config === false ? "readonly" : config);
}

/**
* Ensures that variables representing built-in properties of the Global Object,
* and any globals declared by special block comments, are present in the global
Expand All @@ -189,7 +202,7 @@ function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
globalScope.variables.push(variable);
globalScope.set.set(name, variable);
}
variable.writeable = configGlobals[name];
variable.config = normalizeGlobalConfig(configGlobals[name]);
});

Object.keys(commentDirectives.enabledGlobals).forEach(name => {
Expand All @@ -202,7 +215,7 @@ function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
globalScope.variables.push(variable);
globalScope.set.set(name, variable);
}
variable.writeable = commentDirectives.enabledGlobals[name].value;
variable.config = normalizeGlobalConfig(commentDirectives.enabledGlobals[name].value);
});

// mark all exported variables as such
Expand Down

0 comments on commit 9b23504

Please sign in to comment.