Skip to content

feat: Allow rules to specify languages they work on #135

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 6 commits into from
Jul 28, 2025

Conversation

nzakas
Copy link
Member

@nzakas nzakas commented Jun 11, 2025

Summary

This RFC proposes adding metadata to ESLint rules that indicate which programming languages and language dialects they support. This will enable better documentation and runtime capabilities for ESLint when working with multiple languages.

Related Issues

Refs eslint/eslint#19462

@mdjermanovic mdjermanovic added the Initial Commenting This RFC is in the initial feedback stage label Jun 19, 2025

The `languages` array will contain strings that identify the specific language plugins the rule is designed to work with. Each string follows the standardized format `"plugin/language"` to uniquely identify the language plugin.

For backward compatibility, if `languages` is not specified, the rule will be assumed to work with all languages.

Choose a reason for hiding this comment

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

How would one specify only javascript?

Choose a reason for hiding this comment

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

And if they specify javascript, would that mean it wouldn't apply to Typescript files? It may not need to check anything Typescript specific, and so specifying Typescript might not be obvious, but could still be applied to ts files.

Copy link
Member Author

Choose a reason for hiding this comment

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

The language would be "js/js" for JavaScript.

And yes, that would also mean TypeScript because it uses the same language implementation. So any rule that specifies it works with JavaScript would also work with TypeScript (or any other dialect that reuses the JavaScript language implementation).

Choose a reason for hiding this comment

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

So would this explicitly endorse TypeScript, then? In other words, "js/js" would imply TS but not, for example, Flow?

Copy link
Member Author

Choose a reason for hiding this comment

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

"js/js" implies anything that runs through the JavaScript language plugin, which includes TypeScript and Flow, and anything else that swaps in a custom languageOptions.parser.

mdjermanovic
mdjermanovic previously approved these changes Jul 5, 2025
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, I only left two small suggestion.

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Copy link
Member

@fasttime fasttime 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!

@fasttime fasttime requested a review from Copilot July 19, 2025 20:10
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This RFC proposes adding language metadata to ESLint rules to specify which programming languages and dialects they support. This enhancement addresses documentation needs for multi-language compatibility and enables better runtime error handling when rules are used with unsupported languages.

Key changes:

  • Introduces a languages array property in rule metadata to specify supported languages
  • Adds validation logic to check rule compatibility at runtime
  • Maintains backward compatibility by defaulting to all-language support when not specified


### Implementation Approach

1. Update the `RuleMeta` interface in `@eslint/core` to accept `languages`. Deprecate the `language` and `dialects` properties. Add `meta.docs.dialects` property.
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

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

The implementation step mentions adding meta.docs.dialects property but this property is not explained elsewhere in the RFC. Consider clarifying what this property is for and how it relates to the languages array, or remove it if it's not needed.

Suggested change
1. Update the `RuleMeta` interface in `@eslint/core` to accept `languages`. Deprecate the `language` and `dialects` properties. Add `meta.docs.dialects` property.
1. Update the `RuleMeta` interface in `@eslint/core` to accept `languages`. Deprecate the `language` and `dialects` properties.

Copilot uses AI. Check for mistakes.

Copy link
Member

@fasttime fasttime Jul 19, 2025

Choose a reason for hiding this comment

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

The suggested change is bogus. As for "Consider clarifying what this property is for", that makes sense, although it's explained in the related discussion in eslint/eslint#19462, and I'm not sure if Copilot bothered reading that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think Copilot works great in documentation situations. I've found it often misses a lot of context.

### Implementation Approach

1. Update the `RuleMeta` interface in `@eslint/core` to accept `languages`. Deprecate the `language` and `dialects` properties. Add `meta.docs.dialects` property.
2. Update the `validateRulesConfig()` function in `lib/config/config.js` to validate each rule's `languages` property against the language specified in the `Config` instance. When a rule doesn't match the language, add to an array of invalid rules. When all validation is complete, if there is an array of invalid rules, throw an error. Normalize `"js/js"` to `"@/js"`.
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

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

[nitpick] The implementation description is dense and could be clearer. Consider breaking this into separate sub-points for validation logic, error handling, and normalization to improve readability.

Suggested change
2. Update the `validateRulesConfig()` function in `lib/config/config.js` to validate each rule's `languages` property against the language specified in the `Config` instance. When a rule doesn't match the language, add to an array of invalid rules. When all validation is complete, if there is an array of invalid rules, throw an error. Normalize `"js/js"` to `"@/js"`.
2. Update the `validateRulesConfig()` function in `lib/config/config.js`:
- **Validation Logic**: Validate each rule's `languages` property against the language specified in the `Config` instance. If a rule's `languages` property does not match the specified language, mark it as invalid by adding it to an array of invalid rules.
- **Error Handling**: After completing the validation for all rules, check if there are any invalid rules in the array. If so, throw an error with a descriptive message listing the invalid rules.
- **Normalization**: Normalize the `"js/js"` string to `"@/js"` to ensure compatibility with the current JavaScript language definition.

Copilot uses AI. Check for mistakes.

@fasttime
Copy link
Member

Moving to final commenting.

@fasttime fasttime added Final Commenting This RFC is in the final week of commenting and removed Initial Commenting This RFC is in the initial feedback stage labels Jul 19, 2025
@mdjermanovic
Copy link
Member

The final commenting period has ended, so merging.

@mdjermanovic mdjermanovic merged commit c3c4106 into main Jul 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Final Commenting This RFC is in the final week of commenting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 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