Skip to content

Rule Change: add "allowProperties" option to no-restricted-properties #19762

@erosman

Description

@erosman

What rule do you want to change?

no-restricted-properties

What change do you want to make?

Generate more warnings

How do you think the change should be implemented?

A new option

Example code

/* global obj */

obj.a = 1;
obj.b = 2;
obj.c = 3;

obj.x = 4;
obj.y = 4;

What does the rule currently do for this code?

As per the issue mentioned in Define specific object properties in globals, additional "allowProperties" option in no-restricted-properties could be beneficial and avoids having to generate a large rule list by entering them individually.

{
  "rules": {
    "no-restricted-properties": [2, {
        "object": "obj",
        "allowProperties": [ "a", "b", "c" ],
        "message": "Property is not supported."
    }]
  }
}

What will the rule do after it's changed?

Generates error for obj.x, obj.y, etc

'obj.x' is restricted from being used. Property is not supported. (no-restricted-properties) ESLint

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

No response

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions