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

Modify no-restricted-globals to allow providing optional custom messages #8315

Closed
dryajov opened this issue Mar 23, 2017 · 6 comments
Closed
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@dryajov
Copy link

dryajov commented Mar 23, 2017

@not-an-aardvark @platinumazure

This is a continuation of a new rule proposal and subsequent discussion initially started here - #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');
    };
  }
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Mar 23, 2017
@platinumazure platinumazure added enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Mar 24, 2017
@platinumazure platinumazure self-assigned this Mar 24, 2017
@platinumazure
Copy link
Member

Thanks for the rule suggestion! I'll champion this.

@dryajov
Copy link
Author

dryajov commented Mar 24, 2017

Thanks @platinumazure!

@ilyavolodin
Copy link
Member

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

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Jul 11, 2017
@not-an-aardvark
Copy link
Member

@platinumazure This has three 👍s from the team -- marking as accepted.

@platinumazure
Copy link
Member

platinumazure commented Jul 12, 2017

@ilyavolodin Missed your question about proposed schema for this rule, sorry. I would want to do something similar to what we have in no-restricted-syntax. Maybe something like this:

        schema: {
            type: "array",
            items: [{
                oneOf: [
                    {
                        type: "string"
                    },
                    {
                        type: "object",
                        properties: {
                            global: { type: "string" },
                            message: { type: "string" }
                        },
                        required: ["global"],
                        additionalProperties: false
                    }
                ]
            }],
            uniqueItems: true,
            minItems: 0
        }

@platinumazure
Copy link
Member

Working on this.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

5 participants