Skip to content

[doc] how to add new linting rules#2551

Draft
EagleoutIce wants to merge 2 commits into
mainfrom
1811-linter-document-how-to-add-new-linting-rules
Draft

[doc] how to add new linting rules#2551
EagleoutIce wants to merge 2 commits into
mainfrom
1811-linter-document-how-to-add-new-linting-rules

Conversation

@EagleoutIce

Copy link
Copy Markdown
Member

No description provided.

@EagleoutIce EagleoutIce linked an issue Jun 13, 2026 that may be closed by this pull request
Comment thread wiki/_Sidebar.md
* [Analyzer (FlowrAnalyzer, Projects, ...)](https://github.com/flowr-analysis/flowr/wiki/Analyzer)
* [Engines](https://github.com/flowr-analysis/flowr/wiki/Engines)
* [Linting R](https://github.com/flowr-analysis/flowr/wiki/Linter)
* [Create Linting Rules](https://github.com/flowr-analysis/flowr/wiki/Create-Linting-Rules)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Please remove it in the sidebar and use ctx.linkPage to add pointers to:

  • link to this page in the Linter wiki page
  • link to this page in the FAQ


## Step 1: Create the new rule file

To add a new linting rule, create a separate file for it under [\`src/linter/rules/\`](${RemoteFlowrFilePathBaseRef}/src/linter/rules/)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

please avoid these hardcoded constructions of paths, either reference a file within or just reference the objects!


For new rules, the central interface is ${ctx.link('LintingRule')}. The relevant type parameters are:

${codeBlock('typescript', 'LintingRule<Result, Metadata, Config>')}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd argue this should be documented in the code and not here in the wiki

return `
# Create Linting Rules

This page explains how to add a new linting rule to flowR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

please also add a pointer to the linter wiki here


| Part | Purpose |
|---|---|
| ${ctx.link('LintingRule::createSearch')} | Creates a flowR search query that selects potentially relevant program elements. |

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

likewise, this should print ctx.doc instead of adding a new textual explanation :D
to stay consistent with other wikis I'd also prefer to just have bullet points here and no table


## Step 5: Add tests for the rule

New rules should be covered by tests in [\`src/test/functionality/linter/\`](${RemoteFlowrFilePathBaseRef}/test/functionality/linter/).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

  • Likewise with the paths please do not use them like this.
  • Also the tests must follow the existing pattern (of adding lint-<rule>.test.ts to the linter rule name).
  • and I think it is good to mention that these tests are automatically used to generate examples in the linter wiki, which are extracted from assertLinter calls. They can also use /* @ignore-in-wiki */ to ignore some tests in the wiki.

## Step 5: Add tests for the rule

New rules should be covered by tests in [\`src/test/functionality/linter/\`](${RemoteFlowrFilePathBaseRef}/test/functionality/linter/).
`;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there could be another pointer that tells people how to rerun the wiki generation and explore the rule documentation

} as const satisfies LintingRule<MyRuleResult, MyRuleMetadata, MyRuleConfig>;`)}


## Step 4: Register the rule

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there is a step missing, before the tests but after the registration, users must add a new rule block in the wiki-linter.ts

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.

[Linter] document how to add new linting rules

2 participants