Skip to content

feat: add ruleCreationMethods rule#2301

Merged
JoshuaKGoldberg merged 8 commits intoflint-fyi:mainfrom
kovsu:fix-#1747
Mar 1, 2026
Merged

feat: add ruleCreationMethods rule#2301
JoshuaKGoldberg merged 8 commits intoflint-fyi:mainfrom
kovsu:fix-#1747

Conversation

@kovsu
Copy link
Member

@kovsu kovsu commented Feb 10, 2026

PR Checklist

Overview

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

🦋 Changeset detected

Latest commit: 62e1a89

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Feb 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flint Ready Ready Preview, Comment Mar 1, 2026 4:10pm

Request Review

"RuleCreator adds the `docs` property and ensures consistent rule structure across plugins.",
],
suggestions: [
"Import RuleCreator and use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we tell them which package to import RuleCreator from? Without that, I'm not sure I'd know what to do to address the violation.

Copy link
Member Author

Choose a reason for hiding this comment

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

how about this?

suggestions: [
	"Import RuleCreator from `@flint.fyi/core` and instantiate a ruleCreator (e.g. `const ruleCreator = new RuleCreator({ presets: [...] })`).",
	"Use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
],

Copy link
Contributor

@michaelfaith michaelfaith left a comment

Choose a reason for hiding this comment

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

Just a minor wording suggestion (for the suggestion 😅). Otherwise looks good! I'll mark as Approved and you can decide if you like the suggestion or not.

suggestions: [
"Import RuleCreator and use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
"Import RuleCreator from `@flint.fyi/core` and instantiate a ruleCreator (e.g. `const ruleCreator = new RuleCreator({ presets: [...] })`).",
"Use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor suggestion to read a bit more smoothly between the two lines

Suggested change
"Use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
"Create an instance of RuleCreator from `@flint.fyi/core` (e.g. `const ruleCreator = new RuleCreator({ presets: [...] })`).",
"And then use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",

Copy link
Contributor

Choose a reason for hiding this comment

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

(apparently you can't provide suggestions across multiple lines, but you get the idea 😅)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh you have to select multiple lines. Which... GitHub sometimes breaks in the UI 🙃

const propertyAccess = node.expression as AST.PropertyAccessExpression;
const type = typeChecker.getTypeAtLocation(propertyAccess.expression);
if (
node.expression.kind === SyntaxKind.PropertyAccessExpression &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I was suggesting something like this

const isPropertyAccessExpression = (node: : AST.CallExpression): node is PropertyAccessExpression {
  return node.expression.kind === SyntaxKind.PropertyAccessExpression;
}

const isCreateRuleCall = (node: : AST.CallExpression): boolean {
  return isPropertyAccessExpression(node) && node.expression.name.text === "createRule";
}

But this works fine too. 👍

@michaelfaith michaelfaith added the 1 approval One team member approved; we're now waiting for a second approval or for 2 business days to pass. label Feb 10, 2026
Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

The implementation looks great - I love how clean this is with the shared isLanguageCreateRule helper! 🙌

Just requesting that an .mdx file be added.

suggestions: [
"Import RuleCreator and use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
"Import RuleCreator from `@flint.fyi/core` and instantiate a ruleCreator (e.g. `const ruleCreator = new RuleCreator({ presets: [...] })`).",
"Use `ruleCreator.createRule(language, { ... })` instead of `language.createRule({ ... })`.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh you have to select multiple lines. Which... GitHub sometimes breaks in the UI 🙃

@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author Needs an action taken by the original poster and removed 1 approval One team member approved; we're now waiting for a second approval or for 2 business days to pass. labels Feb 10, 2026
Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

(wrong button)

@github-actions github-actions bot removed the status: waiting for author Needs an action taken by the original poster label Feb 14, 2026
Copy link
Member

@lishaduck lishaduck left a comment

Choose a reason for hiding this comment

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

Looks good, just a few very minor comments!

Comment on lines +50 to +51
// Use RuleCreator.createRule instead of Language.createRule
// But this is the original implementation
Copy link
Member

@lishaduck lishaduck Feb 18, 2026

Choose a reason for hiding this comment

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

I just wanna say this is 🔥 lol.

Actually, TBH maybe we should ignore this rule for the core package specifically, because it shouldn't be defining any rules? No, that depends on how we structure #2181. Though, having said that, we probably should structure it out-of-core. Ehh, who cares?

Copy link
Member

@lishaduck lishaduck left a comment

Choose a reason for hiding this comment

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

Looks fine by me :)

….mdx

Co-authored-by: Eli <88557639+lishaduck@users.noreply.github.com>
@vercel
Copy link

vercel bot commented Feb 21, 2026

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I don't know what's going on with the deployment, but this is great. Thanks @kovsu! 🙌

@JoshuaKGoldberg JoshuaKGoldberg merged commit efe6df5 into flint-fyi:main Mar 1, 2026
8 checks passed
@kovsu kovsu deleted the fix-#1747 branch March 2, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: Add Flint rule that plugins should define rule with RuleCreator

4 participants