-
Notifications
You must be signed in to change notification settings - Fork 12
Create Linting Rules
This document was generated from 'src/documentation/wiki-create-linting-rules.ts' on 2026-06-16, 16:56:25 UTC presenting an overview of flowR's creating linting rules (v2.10.9, using R v4.5.0). Please do not edit this file/wiki page directly.
This page explains how to add a new linting rule to flowR. For an overview of the linter and the existing linting rules, see Linter.
To add a new linting rule, create a dedicated rule file next to the existing rule implementations. The file name should correspond to the exported linting rule object, for example my-new-rule.ts for a rule object named MY_NEW_RULE.
Existing rules such as DEPRECATED_FUNCTIONS can be used as references.
Before implementing a new linting rule, open a corresponding linting rule issue using the accompanying issue template.
For new rules, the central interface is LintingRule. Its type parameters are documented directly as part of the interface.
A new linting rule must implement the LintingRule interface. It consists of the following main parts:
-
LintingRule::createSearchCreates a flowR search that will then be executed and whose results will be passed toprocessSearchResult. In the future, additional optimizations and transformations may be applied to the search between this function andprocessSearchResult. -
LintingRule::processSearchResultProcesses the search results of the search created throughcreateSearch. This function is expected to return the linting results from this rule for the given search, ie usually the given script file. -
LintingRule::prettyPrintA set of functions used to pretty-print the given linting result. By default, theLintingResult#certaintyand whether anyLintingResult#quickFixvalues are available is automatically printed alongside this information. LintingRule::info
The LintingRule::info field has type LinterRuleInformation and contains:
-
LinterRuleInformation::nameHuman-Readable name of the linting rule. -
LinterRuleInformation::tagsA short list of tags that describe and categorize the linting rule. -
LinterRuleInformation::certaintyThe linting rule's certainty in terms of the rule's calculations' precision and recall. -
LinterRuleInformation::descriptionA short description of the linting rule. This is used to display the rule in the UI and to provide a brief overview of what the rule does. -
LinterRuleInformation::defaultConfigThe default config for this linting rule. This config is combined with the user config when executing the rule.
The following example shows the basic structure of a linting rule:
const MY_NEW_RULE = {
createSearch: (_config) => Q.all(),
processSearchResult: (_elements, _config, _data) => ({
results: [],
'.meta': {}
}),
prettyPrint: {
query: (_result, _metadata) => 'my-rule finding',
full: (_result, _metadata) => 'My Rule reported a finding that should be reviewed.'
},
info: {
name: 'My Rule',
description: 'Detects something.',
tags: [],
certainty: LintingRuleCertainty.BestEffort,
defaultConfig: {}
}
} as const satisfies LintingRule<MyRuleResult, MyRuleMetadata, MyRuleConfig>;Defined at src/documentation/wiki-create-linting-rules.ts#L23
After implementing the rule, register it by adding it to LintingRules.
After registering the rule, add a corresponding rule entry to the linter wiki generation in WikiLinter. These entries are used to generate the linter overview and the individual wiki pages for linting rules, which can then be inspected through Linter.
New linting rules should be covered by tests following the existing linter test pattern. The test file should be named lint-<my-new-rule>.test.ts. Existing linter tests can be used as references for the expected structure.
The linter wiki automatically extracts additional examples from these tests by reading assertLinter calls. If a test should not appear as a generated wiki example, add /* @ignore-in-wiki */ to the test.
For general information on creating and regenerating wiki pages, see FAQ, especially the FAQ entry on creating new wiki pages. The linter overview and the generated rule documentation can then be inspected through Linter.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information