Skip to content

fix: update error message for no-restricted-properties #19855

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

Merged
merged 5 commits into from
Jun 19, 2025

Conversation

Tanujkanti4441
Copy link
Contributor

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)

Updated the error message of no-restricted-properties for two new options allowObjects and allowProperties; now the error message will also show the property or objects names that are allowed.

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

myArray.push(5);

Now the error is - 'push' is restricted from being used. It can be used only in allowed objects - router.

/* eslint no-restricted-properties: [2, {
    "object": "config",
    "allowProperties": ["settings", "version"]
}] */

config.apiKey = "12345";

Now the error is - 'config.apiKey' is restricted from being used. Only allowed properties can be used - settings, version.

Is there anything you'd like reviewers to focus on?

@Tanujkanti4441 Tanujkanti4441 requested a review from a team as a code owner June 15, 2025 18:22
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 15, 2025
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Jun 15, 2025
Copy link

netlify bot commented Jun 15, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 6303e30
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/6852e14f3cae030008ce4e7e

@github-actions github-actions bot added the rule Relates to ESLint's core rules label Jun 15, 2025
@lumirlumir
Copy link
Member

Hi @Tanujkanti4441, could you take a look at the CI failure? The formatting is currently causing an error.

@@ -155,6 +155,10 @@ module.exports = {
const message = matchedObjectProperty.message
? ` ${matchedObjectProperty.message}`
: "";
const allowedPropertiesMessage =
matchedObjectProperty.allowProperties
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clean this up a bit?

Suggested change
matchedObjectProperty.allowProperties
? ` Only these properties are allowed: ${matchedObjectProperty.allowProperties.join(", ")}.`

@@ -172,13 +177,17 @@ module.exports = {
const message = globalMatchedProperty.message
? ` ${globalMatchedProperty.message}`
: "";
const allowedObjectsMessage = globalMatchedProperty.allowObjects
? ` It can be used only in allowed objects - ${globalMatchedProperty.allowObjects.join(", ")}.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity.

Suggested change
? ` It can be used only in allowed objects - ${globalMatchedProperty.allowObjects.join(", ")}.`
? ` Property ${propertyName} is only allowed on these objects: ${globalMatchedProperty.allowObjects.join(", ")}.`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! also added quotes around propertyName.

@nzakas nzakas moved this from Needs Triage to Implementing in Triage Jun 18, 2025
@nzakas nzakas changed the title feat: update error message for no-restricted-properties fix: update error message for no-restricted-properties Jun 19, 2025
@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label Jun 19, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -73,10 +73,10 @@ module.exports = {
messages: {
restrictedObjectProperty:
// eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
"'{{objectName}}.{{propertyName}}' is restricted from being used.{{message}}",
"'{{objectName}}.{{propertyName}}' is restricted from being used.{{allowedPropertiesMessage}}{{message}}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to double-check, do we need a space here?

Suggested change
"'{{objectName}}.{{propertyName}}' is restricted from being used.{{allowedPropertiesMessage}}{{message}}",
"'{{objectName}}.{{propertyName}}' is restricted from being used.{{allowedPropertiesMessage}} {{message}}",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const message = matchedObjectProperty.message
			? ` ${matchedObjectProperty.message}`
			: "";

There is already a space before the message, so we don't need space here.

restrictedProperty:
// eslint-disable-next-line eslint-plugin/report-message-format -- Custom message might not end in a period
"'{{propertyName}}' is restricted from being used.{{message}}",
"'{{propertyName}}' is restricted from being used.{{allowedObjectsMessage}}{{message}}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question.

Suggested change
"'{{propertyName}}' is restricted from being used.{{allowedObjectsMessage}}{{message}}",
"'{{propertyName}}' is restricted from being used.{{allowedObjectsMessage}} {{message}}",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one.

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit 3fbcd70 into eslint:main Jun 19, 2025
30 checks passed
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ESLint is working incorrectly feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy