Modify no-restricted-globals to allow providing optional custom messages
See original GitHub issue@not-an-aardvark @platinumazure
This is a continuation of a new rule proposal and subsequent discussion initially started here - https://github.com/eslint/eslint/issues/8229
Please describe what the rule should do:
no-restricted-globals
allows to prevent the use of certain globals, but it doesn’t allow providing custom messages that would explain why the usage is being prevented.
What category of rule is this? (place an “X” next to just one item)
[x] Enforces code style [x] Warns about a potential error [x] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
// should warn/error with an explanation on use of window and suggest usage of self instead
if (window.crypto && window.crypto.getRandomValues) {
// Modern browsers
Rand.prototype._rand = function _rand(n) {
var arr = new Uint8Array(n);
window.crypto.getRandomValues(arr);
return arr;
};
} else if (window.msCrypto && window.msCrypto.getRandomValues) {
// IE
Rand.prototype._rand = function _rand(n) {
var arr = new Uint8Array(n);
window.msCrypto.getRandomValues(arr);
return arr;
};
} else {
// Old junk
Rand.prototype._rand = function() {
throw new Error('Not implemented yet');
};
}
===============
// should not warn/error on the usage of self
if (self.crypto && self.crypto.getRandomValues) {
// Modern browsers
Rand.prototype._rand = function _rand(n) {
var arr = new Uint8Array(n);
self.crypto.getRandomValues(arr);
return arr;
};
} else if (self.msCrypto && self.msCrypto.getRandomValues) {
// IE
Rand.prototype._rand = function _rand(n) {
var arr = new Uint8Array(n);
self.msCrypto.getRandomValues(arr);
return arr;
};
} else {
// Old junk
Rand.prototype._rand = function() {
throw new Error('Not implemented yet');
};
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
Top Results From Across the Web
no-restricted-globals - ESLint - Pluggable JavaScript Linter
This rule allows you to specify global variable names that you don't want to use in ... where the global name and an...
Read more >javascript - No restricted globals - Stack Overflow
Try adding window before location (i.e. window.location ).
Read more >eslint-config-eslint | Yarn - Package Manager
Contains the ESLint configuration used for projects maintained by the ESLint team. Installation. You can install ESLint using npm: npm install eslint --save-dev....
Read more >React js confirm dialog - POSTGRAVITYART
To create this i will use react-confirm-alert package It is a very simple package and easy to customize. You can see the demo...
Read more >Code Issues - Embold Help Center
A variable naming conventions rule – customize this to your liking. Currently, it checks for final variables that should be fully capitalized and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dryajov Could you provide a schema of what you think the options should look like with this change?
Working on this.