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.

Allow the `object` or `property` option to be omitted with `no-restricted-properties`

See original GitHub issue

What rule do you want to change?

no-restricted-properties

Does this change cause the rule to produce more or fewer warnings?

The default behavior of the rule would be unchanged.

How will the change be implemented? (New option, new default behavior, etc.)? What will the rule do after it’s changed?

Currently, no-restricted-properties accepts a list of objects with the object and property keys. Both options are required.

It would be useful to be able to disallow access to a property on every object, rather than having to provide explicit object names. For example, one might want to disallow use of the deprecated __defineGetter__ property, which is currently not possible with ESLint.

Similarly, it would be useful to be able to disallow all property access for a particular object, without specifying property names. For example, one might want to encourage use of the require() function, and disallow access to require.resolve(), require.cache, etc.

I propose that we make the object and property arguments optional. If property is provided and object is omitted, an error is reported whenever property is accessed from any object. If object is provided and property is omitted, an error is reported whenever any property of object is accessed.

If both object and property are omitted, ESLint should raise an error about an invalid schema. (The consistent behavior would be to disallow all forms of property access, but it’s unlikely that anyone would actually want to do this and so it would cause confusion.)

Please provide some example code that this change will affect:

/* eslint no-restricted-properties: [2, {"property": "__defineGetter__"}] */

foo.__defineGetter__(bar, baz); // report error
bar.__defineGetter__(bar, baz); // report error
/* eslint no-restricted-properties: [2, {"object": "require"}] */

require('foo') // ok
require.resolve('foo') // report error
require.cache // report error
require['foo'] // report error

What does the rule currently do for this code?

It causes ESLint to throw an error because the schema is considered invalid.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Sep 13, 2016

Ah, I didn’t realize JSON Schema would let us require just one or the other (in conjunction with anyOf). Okay, I like the original proposal (just omit the config properties as needed) better and withdraw my suggestion of null valuing.

1reaction
ljharbcommented, Sep 13, 2016

@alecharmon and also all-properties? The current proposal seems the clearest to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-properties - ESLint - Pluggable JavaScript Linter
Rule Details. This rule looks for accessing a given property key on a given object name, either when reading the property's value or...
Read more >
Omit property variable when using object destructuring
Using a Rest Property it is possible to “omit” properties from an object, but by default the sibling properties are marked as “unused”....
Read more >
Restrict view and edit access for properties - Knowledge Base
Users with super admin permissions can restrict a property so that only specific users and teams can view or edit the property's data...
Read more >
Object.defineProperty() - JavaScript - MDN Web Docs
A function which serves as a getter for the property, or undefined if there is no getter. When the property is accessed, this...
Read more >
Properties in C# | Microsoft Learn
It's also legal to place the more restrictive modifier on the get accessor. For example, you could have a public property, but restrict...
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