Skip to content

Linter: Make RuleClass().name static#1268

Merged
marcoroth merged 3 commits into
marcoroth:mainfrom
citizen428:issue-1264
Mar 3, 2026
Merged

Linter: Make RuleClass().name static#1268
marcoroth merged 3 commits into
marcoroth:mainfrom
citizen428:issue-1264

Conversation

@citizen428

Copy link
Copy Markdown
Contributor

Closes #1264

This PR refactors the linter code to use a static ruleName property instead of name on the instance.


const RuleClass = (this.linter as any).rules.find((rule: any) => {
const instance = new rule()
const ruleClass = (this.linter as any).rules.find(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On top of changing the find I also renamed RuleClass to ruleClass. I think it's confusing to name a variable referencing a class in camel-case like the constructor function.

}

async processFiles(files: string[], formatOption: FormatOption = 'detailed', context?: ProcessingContext): Promise<ProcessingResult> {
async processFiles(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't catch that my editor auto-formatted this. Let me know if you want me to roll this back. Same for other format changes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If you can easily revert it, then that would be great! On that note, I guess we should also enforce formatting for JavaScript/TypeScript files.

@citizen428 citizen428 marked this pull request as draft March 2, 2026 14:46
Comment thread javascript/packages/linter/src/types.ts
@citizen428

citizen428 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

@marcoroth OK, I believe this is ready now. I know you also mentioned potentially doing something similar for type, but I think this PR is big enough now.

@citizen428 citizen428 marked this pull request as ready for review March 2, 2026 15:39
@marcoroth

Copy link
Copy Markdown
Owner

I think we also need to update the docs: https://herb-tools.dev/projects/linter#custom-rules

Also wondering if we can easily provide a deprecation message if we see somebody is trying to define name. I know some people are using custom linter rules already.

@citizen428

Copy link
Copy Markdown
Contributor Author

I think we also need to update the docs: herb-tools.dev/projects/linter#custom-rules

Done in 153de47, please check.

Also wondering if we can easily provide a deprecation message if we see somebody is trying to define name. I know some people are using custom linter rules already.

I pushed an approach for that in b5c5020, let me know what you think. I opted for an error and termination to force people into updating their custom rules,. but maybe that's too aggressive.

Comment thread javascript/packages/linter/src/custom-rule-loader.ts
Comment thread javascript/packages/linter/src/custom-rule-loader.ts

@marcoroth marcoroth left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you @citizen428, I really appreciate the thoroughness! 🙏🏼

@marcoroth marcoroth merged commit c70b962 into marcoroth:main Mar 3, 2026
12 checks passed
@citizen428 citizen428 deleted the issue-1264 branch March 3, 2026 11:09
marcoroth added a commit that referenced this pull request Mar 5, 2026
This pull request refactors the linter by accessing the `static type`
field directly on rule classes instead of instantiating rules and
reading it from `rule.constructor`.

The instance-level type guards (`isLexerRule`, `isSourceRule`,
`isParserRule`) are replaced with class-level equivalents
(`isLexerRuleClass`, `isSourceRuleClass`, `isParserRuleClass`) that take
a `ruleClass` rather than a Rule instance.

It also extracts a `findRuleClass(ruleName)` helper to deduplicate the
six occurrences of `this.rules.find(rule => rule.ruleName === ...)`, and
renames `RuleClass` local variables to `ruleClass` to follow camelCase
conventions for non-type identifiers.

Follow up on #1268
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.

Linter: Make RuleClass().name static

2 participants