Skip to content

Create Linting Rules

github-actions[bot] edited this page Jun 16, 2026 · 1 revision

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.

Create Linting Rules

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.

Step 1: Create the new rule file

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.

Step 2: Define the types for the rule

For new rules, the central interface is LintingRule. Its type parameters are documented directly as part of the interface.

Step 3: Define the rule itself

A new linting rule must implement the LintingRule interface. It consists of the following main parts:

  • LintingRule::createSearch Creates a flowR search that will then be executed and whose results will be passed to processSearchResult . In the future, additional optimizations and transformations may be applied to the search between this function and processSearchResult .
  • LintingRule::processSearchResult Processes the search results of the search created through createSearch . This function is expected to return the linting results from this rule for the given search, ie usually the given script file.
  • LintingRule::prettyPrint A set of functions used to pretty-print the given linting result. By default, the LintingResult#certainty and whether any LintingResult#quickFix values are available is automatically printed alongside this information.
  • LintingRule::info

The LintingRule::info field has type LinterRuleInformation and contains:

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

Step 4: Register the rule

After implementing the rule, register it by adding it to LintingRules.

Step 5: Add the rule to the linter wiki generation

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.

Step 6: Add tests for the rule

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.

Clone this wiki locally