Skip to content

feat: Add new rule no-meta-replaced-by #518

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

Conversation

error-four-o-four
Copy link
Contributor

Hey there,

This pull request introduces a new rule, no-meta-replaced-by to disallow the use of the replacedBy property at the top level of rule meta.

I'd appreciate any improvements to the non-generated sections in the docs.

Closes #517

@error-four-o-four error-four-o-four requested a review from bmish June 17, 2025 20:50
error-four-o-four and others added 2 commits June 17, 2025 22:57
Co-authored-by: Bryan Mishkin <698306+bmish@users.noreply.github.com>
Copy link
Contributor Author

@error-four-o-four error-four-o-four left a comment

Choose a reason for hiding this comment

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

Would it be appropriate to write

## When Not To Use It

If you need to support versions of ESLint prior to v9.


/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
Copy link
Member

@bmish bmish Jun 17, 2025

Choose a reason for hiding this comment

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

We could also add an autofixer to this rule to move meta.replacedBy to meta.deprecated.replacedBy. A follow-up to do that would be fine since it could be tricky to get it right.

Copy link
Contributor Author

@error-four-o-four error-four-o-four Jun 17, 2025

Choose a reason for hiding this comment

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

Yes, thought so too. But I'd have to get down to the nitty-gritty of eslint and ASTs. The autofixer should be added in a follow-up.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another fix in a follow-up might be to remove replacedBy from the defaultOrder in meta-property-order, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also thinking about the neccessity and possibilities so that the autofixer is able to add the property plugin to the replacement rule according to ReplacedByInfo

If this is not the desired behaviour of the autofixer it would simply convert the items of the old replacedBy array to the new format e.g. [{ rule: { name: 'the-new-rule' } }]

If it is the desired behaviour one would have to determine and compare the prefix of the plugin. This could be achieved by either providing an option in no-meta-replaced-by or reading the value of an exported flat config which might be trickier and not reliable.

Copy link
Member

Choose a reason for hiding this comment

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

Another fix in a follow-up might be to remove replacedBy from the defaultOrder in meta-property-order, right?

I think we can leave it. Doesn't hurt to continue to support the older rule properties.

Copy link
Member

@bmish bmish Jun 18, 2025

Choose a reason for hiding this comment

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

Regarding the autofixer, it would be nice if the autofixer can work without any configuration. But if there's an option that can be provided to the rule to improve the autofixer further, I'm open to that as an added bonus.

Copy link
Member

@bmish bmish Jun 17, 2025

Choose a reason for hiding this comment

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

Would it be appropriate to write

## When Not To Use It

If you need to support versions of ESLint prior to v9.

Regarding when not to use it, I don't think we necessarily need to include this section. In fact, anyone can use this rule regardless of ESLint version. As far as I know, ESLint itself does not validate nor use the meta.deprecated property. So anybody can use the object format for meta.deprecated.

Note that if someone is using TypeScript to define their rules, they would want to make sure they have up-to-date rule types (which I believe come from @types/eslint or typescript-eslint). And rule authors would want to make sure they are using up-to-date versions of any third-party tooling like eslint-doc-generator that use this property.

OR, you could include the section and just state the context I've mentioned here.

@bmish bmish mentioned this pull request Jun 15, 2025
Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

Nice work!

@bmish bmish changed the title New rule: no-meta-replaced-by Add new rule no-meta-replaced-by Jun 18, 2025
@bmish bmish merged commit 105f05d into eslint-community:main Jun 18, 2025
8 checks passed
@bmish bmish changed the title Add new rule no-meta-replaced-by feat: Add new rule no-meta-replaced-by Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Rule: no-meta-replaced-by
2 participants