question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ilyavolodincommented, Mar 24, 2017

@dryajov Could you provide a schema of what you think the options should look like with this change?

0reactions
platinumazurecommented, Jul 12, 2017

Working on this.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found