Flint Plugin
Rules for writing third-party Flint plugins and custom rules. Meta!
This plugin is provided in a standalone @flint.fyi/plugin-flint npm package.
npm install @flint.fyi/plugin-flintbun install @flint.fyi/plugin-flintdeno install @flint.fyi/plugin-flintpnpm install @flint.fyi/plugin-flintyarn install @flint.fyi/plugin-flintPresets
Section titled “Presets”logical
Section titled “logical”Rules that find bugs and enforce good practices for Flint plugins and rules.
import { const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint } from "@flint.fyi/plugin-flint";import { function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig, const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts } from "flint";
export default function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig({ ConfigDefinition.use: ConfigUseDefinition[]
Specifies the files to be linted alongside the rules and settings to lint with.
use: [ { ConfigUseDefinition.files: AnyLevelDeep<FilesValue>
A list of glob patterns describing which file(s) to lint.
files: const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts.Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: [...]; } & { ...; }, object, object, "notGrouped", AnyOptionalSchema>, ... 293 more ..., Rule<...>]>.files: Record<"javascript" | "typescript" | "all", FilesValue>
Selectors of files this plugin suggests applying its rules to.
files.all: FilesValue
all, ConfigUseDefinition.rules: AnyLevelDeep<ConfigRuleDefinition>
Any number of rules and/or presets of rules to enable for those files.
rules: const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint.Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: [...]; } & { ...; }, object, object, "missingSourceFile", AnyOptionalSchema>, ... 10 more ..., Rule<...>]>.presets: PluginPresets<RuleAbout, "logical" | "stylistic" | "stylisticStrict">
Preset lists of rules to enable on files.
presets.logical: Rule<RuleAbout, object, object, string, AnyOptionalSchema | undefined>[]
logical, }, ],});logicalStrict
Section titled “logicalStrict”Additional logical rules that enforce best practices which are not always straightforward to implement. These rules are recommended for projects where a majority of developers are experienced with both JavaScript/TypeScript and writing plugins for a linter.
import { const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint } from "@flint.fyi/plugin-flint";import { function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig, const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts } from "flint";
export default function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig({ ConfigDefinition.use: ConfigUseDefinition[]
Specifies the files to be linted alongside the rules and settings to lint with.
use: [ { ConfigUseDefinition.files: AnyLevelDeep<FilesValue>
A list of glob patterns describing which file(s) to lint.
files: const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts.Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: [...]; } & { ...; }, object, object, "notGrouped", AnyOptionalSchema>, ... 293 more ..., Rule<...>]>.files: Record<"javascript" | "typescript" | "all", FilesValue>
Selectors of files this plugin suggests applying its rules to.
files.all: FilesValue
all, ConfigUseDefinition.rules: AnyLevelDeep<ConfigRuleDefinition>
Any number of rules and/or presets of rules to enable for those files.
rules: const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint.Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: [...]; } & { ...; }, object, object, "missingSourceFile", AnyOptionalSchema>, ... 10 more ..., Rule<...>]>.presets: PluginPresets<RuleAbout, "logical" | "stylistic" | "stylisticStrict">
Preset lists of rules to enable on files.
presets.any
logicalStrict, }, ],});This preset’s rules are a superset of those in logical.
stylistic
Section titled “stylistic”Rules that enforce consistent styling and best stylistic practices for most-to-all Flint plugins.
import { const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint } from "@flint.fyi/plugin-flint";import { function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig, const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts } from "flint";
export default function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig({ ConfigDefinition.use: ConfigUseDefinition[]
Specifies the files to be linted alongside the rules and settings to lint with.
use: [ { ConfigUseDefinition.files: AnyLevelDeep<FilesValue>
A list of glob patterns describing which file(s) to lint.
files: const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts.Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: [...]; } & { ...; }, object, object, "notGrouped", AnyOptionalSchema>, ... 293 more ..., Rule<...>]>.files: Record<"javascript" | "typescript" | "all", FilesValue>
Selectors of files this plugin suggests applying its rules to.
files.all: FilesValue
all, ConfigUseDefinition.rules: AnyLevelDeep<ConfigRuleDefinition>
Any number of rules and/or presets of rules to enable for those files.
rules: const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint.Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: [...]; } & { ...; }, object, object, "missingSourceFile", AnyOptionalSchema>, ... 10 more ..., Rule<...>]>.presets: PluginPresets<RuleAbout, "logical" | "stylistic" | "stylisticStrict">
Preset lists of rules to enable on files.
presets.stylistic: Rule<RuleAbout, object, object, string, AnyOptionalSchema | undefined>[]
stylistic, }, ],});stylisticStrict
Section titled “stylisticStrict”Additional stylistic rules that enforce best practices which are nice to keep consistent across Flint plugins. These rules are recommended for teams that want the stricter conventions enforced automatically.
import { const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint } from "@flint.fyi/plugin-flint";import { function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig, const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts } from "flint";
export default function defineConfig(definition: ConfigDefinition): Config
Defines a new linter configuration for a Flint config file.
defineConfig({ ConfigDefinition.use: ConfigUseDefinition[]
Specifies the files to be linted alongside the rules and settings to lint with.
use: [ { ConfigUseDefinition.files: AnyLevelDeep<FilesValue>
A list of glob patterns describing which file(s) to lint.
files: const ts: Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: ["stylistic", "stylisticStrict"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "notGrouped", AnyOptionalSchema>, Rule<{ readonly description: "Reports mismatched types between getter and setter accessor pairs."; readonly id: "accessorPairTypes"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict" | "javascript")[] | undefined; url: string;}, object, object, "mismatchedTypes", AnyOptionalSchema>, ... 292 more ..., Rule<...>]>
ts.Plugin<RuleAbout, "javascript" | "typescript" | "all", [Rule<{ readonly description: "Reports getter and setter accessors for the same property that are not adjacent."; readonly id: "accessorPairGroups"; readonly presets: [...]; } & { ...; }, object, object, "notGrouped", AnyOptionalSchema>, ... 293 more ..., Rule<...>]>.files: Record<"javascript" | "typescript" | "all", FilesValue>
Selectors of files this plugin suggests applying its rules to.
files.all: FilesValue
all, ConfigUseDefinition.rules: AnyLevelDeep<ConfigRuleDefinition>
Any number of rules and/or presets of rules to enable for those files.
rules: const flint: Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: ["logical"];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "missingSourceFile", AnyOptionalSchema>, Rule<{ readonly description: "Reports cases for invalid code that isn't formatted across lines."; readonly id: "invalidCodeLines"; readonly presets: [...];} & { presets?: ("logical" | "logicalStrict" | "stylistic" | "stylisticStrict")[] | undefined; url: string;}, object, object, "singleLineTest", AnyOptionalSchema>, ... 9 more ..., Rule<...>]>
flint.Plugin<RuleAbout, string | undefined, [Rule<{ readonly description: "Requires passing `sourceFile` to `getStart()` for better performance."; readonly id: "getStartSourceFile"; readonly presets: [...]; } & { ...; }, object, object, "missingSourceFile", AnyOptionalSchema>, ... 10 more ..., Rule<...>]>.presets: PluginPresets<RuleAbout, "logical" | "stylistic" | "stylisticStrict">
Preset lists of rules to enable on files.
presets.stylisticStrict: Rule<RuleAbout, object, object, string, AnyOptionalSchema | undefined>[]
stylisticStrict, }, ],});This preset’s rules are a superset of those in stylistic.
Implemented: 10 of 16 (62.5%)
| Flint Rule | Preset |
|---|---|
invalidCodeLinesReports cases for invalid code that isn't formatted across lines. | logical |
missingPlaceholdersReports context.report() calls missing data for message placeholders. | logical |
nodePropertyInChecksDisallows using the in operator to check properties on TypeScript nodes. | logical |
ruleCreationMethodsReports plugin rules created directly with language instead of through RuleCreator. | logical |
ruleDescriptions | logical |
rulePresets | logical |
ruleURLs | logical |
testCaseDuplicatesReports test cases that are identical to previous test cases. | logical |
testCaseNameDuplicatesReports test cases that have the same name as a previous test case. | logical |
testCaseNonStaticCodeTest case code should be a static string literal. | logical |
testCaseOnlies | logical |
unusedMessageIdsReports message IDs defined in the messages object that are never used in recognized report calls. | logical |
unusedPlaceholders | logical |
messagePhrases | logical (strict) |
testShorthandsTest cases with only a code property can use string shorthand syntax instead of object literal syntax. | stylistic |
pluginRuleOrderingReports Flint plugin rules arrays that are not sorted alphabetically. | stylistic (strict) |