Directives
In addition to configuring rules in your flint.config.* file, you can also disable specific rules inline in your code using comment directives.
This is useful when you need to suppress a rule for a specific line, block, or file.
All inline directives are comments that follow the pattern flint-<directive-type>-<rule-id>:
- For JavaScript-like languages:
// flint-... - For Markdown and HTML-like languages:
<!-- flint-... --> - For YAML:
# flint-...
Flint supports the following directives:
flint-disable-file: Disables one or more rules for the entire file.flint-disable-lines-begin: Disables one or more rules for a range of lines.flint-disable-next-line: Disables one or more rules for just the next line of code.
flint-disable-file
Section titled “flint-disable-file”Disables one or more rules for the entire file. This directive must appear at the top of the file, before any code.
// flint-disable-file forInArraysconst array = ["a", "b", "c"];for (const i in array) { console.log(array[i]);}You can specify multiple rule IDs separated by spaces and/or use multiple directives:
// flint-disable-file chainedAssignments forInArrays// flint-disable-file namespaceDeclarationsflint-disable-lines-begin
Section titled “flint-disable-lines-begin”Disables one or more rules for a range of lines.
Use flint-disable-lines-begin to start disabling rules, and flint-disable-lines-end to stop.
// flint-disable-lines-begin forInArraysconst array = ["a", "b", "c"];for (const i in array) { console.log(array[i]);}// flint-disable-lines-end forInArraysYou can nest multiple begin/end pairs, and they will stack:
// flint-disable-lines-begin forInArrays// flint-disable-lines-begin namespaceDeclarationsconst array = ["a", "b", "c"];for (const i in array) { console.log(array[i]);}// flint-disable-lines-end namespaceDeclarations// flint-disable-lines-end forInArraysflint-disable-next-line
Section titled “flint-disable-next-line”Disables one or more rules for just the next line of code.
const array = ["a", "b", "c"];// flint-disable-next-line forInArraysfor (const i in array) { console.log(array[i]);}Rule IDs
Section titled “Rule IDs”The rule ID in a directive should match the rule’s identifier. For example:
altTextsspecifies JSX >altTextsimageAltTextsspecifies MD >imageAltTextsforInArraysspecifies TS >forInArrays
You can find rule IDs by looking at the rules documentation or by checking the error message when a rule reports an issue.
Unused Directives
Section titled “Unused Directives”Flint will report if you use a directive that doesn’t match any reports. This helps you identify directives that are no longer needed or have incorrect rule IDs.
For example, if you disable a rule that doesn’t apply to your code, Flint will report the directive as unused:
// flint-disable-file altTextsconst value = 42;Since altTexts is a JSX rule that checks for alt text on images, it doesn’t apply to this plain TypeScript code, so Flint will report that this directive is unused.