Skip to content

Replacement/improvement of func-name-matching eslint rule #57899

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

Open
LiviaMedeiros opened this issue Apr 16, 2025 · 0 comments
Open

Replacement/improvement of func-name-matching eslint rule #57899

LiviaMedeiros opened this issue Apr 16, 2025 · 0 comments
Labels
tools Issues and PRs related to the tools directory.

Comments

@LiviaMedeiros
Copy link
Member

There are quite a few places where a property is defined like this:

ObjectDefineProperty(someObject, 'someFunction', {
  __proto__: null,
  value: function() {
    /* `someObject.someFunction`'s body */
  },
});

As result, we end up with quite a few functions named value:

someObject.someFunction.name === 'value'

There is a func-name-matching rule in eslint that enforces function names to match the property names. However, in these cases, this rule rejects correct code and insists that these functions must be named value, to the point that in some places we have them explicitly named like this:

value: function value() {

I think, it would be nice to have a custom linter rule that:

  • works the same way as func-name-matching everywhere outside of ObjectDefineProperty, ObjectDefineProperties, and ReflectDefineProperty
  • in the descriptors in these functions, the rule should be reversed: it should not allow the function to end up with a name value
  • (ideally) if property name(s) is defined as plain string, the function name must match this string

I'm not familiar with eslint rules definitions but the original func-name-matching rule seems to be defined here: https://github.com/eslint/eslint/blob/e8f8d57bd6c0d95f9f25db8c5b3ff72de42488b7/lib/rules/func-name-matching.js.

The rule already has considerPropertyDescriptor option, but it's not applicable here because:

  • it recognizes the normal form of these functions (Object.defineProperty) but not primordials (ObjectDefineProperty)
  • it still allows both implicitly inherited name (value: function() {) and concise notation (value() {)
  • it also disables the rule inside of Object.create()
@LiviaMedeiros LiviaMedeiros added the tools Issues and PRs related to the tools directory. label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Issues and PRs related to the tools directory.
Projects
None yet
Development

No branches or pull requests

1 participant