Repository navigation
feat: add allowProperties option to no-restricted-properties - #19772
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
How should this new option work in case of nested properties? For example, the current behavior is as follows: /* eslint no-restricted-properties: [2, {
"object": "config",
"allowProperties": ["settings", "version"]
}] */
config.apiKey.settings = "12345"; // Error: 'config.apiKey' is restricted from being used
config.timeout = 5000; // Error: 'config.timeout' is restricted from being used
config.version.node = "1.0.0"; // No error
config.node.version = "1.0.0"; // Error: 'config.node' is restricted from being usedNow, let's suppose I want to allow only |
|
IMHO, the rule should apply to the immediate property and therefore any of its sub-properties. Allow "object": "config",
"allowProperties": ["settings", "version"]For controlling nested properties, the rule can consider the following format: "object": "config.node",
"allowProperties": ["version"]It should be allowed to enter multiple rules e.g. no-restricted-properties: [2,
{
"object": "config",
"allowProperties": ["settings", "version"]
},
{
"object": "foo",
"allowProperties": ["bar", "barbell"]
},
{
"object": "config.node",
"allowProperties": ["number", "value"]
},
] |
|
I agree. The rule should look only at immediate properties and not look at any other level. This mirrors the existing behavior of the rule. |
|
Makes sense. Let's make the behavior as per #19772 (comment) /* eslint no-restricted-properties: [2, {
"object": "config.node",
"allowProperties": ["version"]
}] */
config.node.version = "1.0.0"; // No error
config.node.other = "1" // Error |
|
I think supporting nested properties/complex objects is out of scope for this change, as that feature is not currently supported by this rule, and the accepted proposal is just to add |
|
I agree with @mdjermanovic that supporting nested properties is out of scope for this change. I've opened a separate issue to discuss this. |
mdjermanovic
left a comment
There was a problem hiding this comment.
LGTM, thanks! Leaving open for a second review.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
This PR adds a new allowProperties option to the no-restricted-properties rule, allowing users to restrict all properties on an object except for specific ones.
Closes #19762
Is there anything you'd like reviewers to focus on?