Skip to content

fix: allow JSONRuleDefinition to report on tokens#210

Merged
DMartens merged 3 commits intomainfrom
fix/rule-definition-node-type
Feb 16, 2026
Merged

fix: allow JSONRuleDefinition to report on tokens#210
DMartens merged 3 commits intomainfrom
fix/rule-definition-node-type

Conversation

@Pixel998
Copy link
Copy Markdown
Contributor

Prerequisites checklist

What is the purpose of this pull request?

This PR fixes an issue where the JSONRuleDefinition type was overly restrictive, preventing rules from reporting issues on tokens (including comments and punctuation).

Previously, the Node type parameter was set to AnyNode, which caused TypeScript errors when rules attempted to use context.report() with tokens retrieved from sourceCode.comments or node.tokens.

What changes did you make? (Give an overview)

Fixed the Node constraint in JSONRuleDefinition by changing it from AnyNode to JSONSyntaxElement.

Related Issues

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

@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Jan 31, 2026
@eslintbot eslintbot added this to Triage Jan 31, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Jan 31, 2026
Copy link
Copy Markdown
Member

@lumirlumir lumirlumir left a comment

Choose a reason for hiding this comment

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

Could you update the PR description to include the bug template? It will help others clearly identify the problem you're facing.

@lumirlumir lumirlumir moved this from Needs Triage to Triaging in Triage Feb 2, 2026
Comment thread tests/types/types.test.ts
@DMartens
Copy link
Copy Markdown

DMartens commented Feb 2, 2026

@lumirlumir This would allow reporting tokens such as a comma , or an opening brace {.
For example in a rule like no-comma-dangle this would be currently not allowed:

export default {
	create(context) {
		return {
			Object(object) {
				const lastMember = object.members.at(-1);
				
				const danglingComma = sourceCode.getTokenAfter(lastMember);
				if (danglingComma !== null) {
					// The type does not allow passing a token as the `node`
					context.report({ message: 'No dangling commas', node: danglingComma });
				}
			}
		}
	}
}

Comment thread tests/types/types.test.ts
@lumirlumir lumirlumir moved this from Triaging to Implementing in Triage Feb 8, 2026
Copy link
Copy Markdown
Member

@lumirlumir lumirlumir 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.

Would like @DMartens to verify before merging.

@lumirlumir lumirlumir moved this from Implementing to Second Review Needed in Triage Feb 15, 2026
@lumirlumir lumirlumir requested a review from DMartens February 15, 2026 13:59
Copy link
Copy Markdown

@DMartens DMartens left a comment

Choose a reason for hiding this comment

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

Changes LGTM, thanks

@DMartens DMartens merged commit 87ea56f into main Feb 16, 2026
33 checks passed
@github-project-automation github-project-automation Bot moved this from Second Review Needed to Complete in Triage Feb 16, 2026
@DMartens DMartens deleted the fix/rule-definition-node-type branch February 16, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted bug Something isn't working

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

4 participants