Skip to content

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:

Disables one or more rules for the entire file. This directive must appear at the top of the file, before any code.

example.ts
// flint-disable-file forInArrays
const 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:

example.ts
// flint-disable-file chainedAssignments forInArrays
// flint-disable-file namespaceDeclarations

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.

example.ts
// flint-disable-lines-begin forInArrays
const array = ["a", "b", "c"];
for (const i in array) {
console.log(array[i]);
}
// flint-disable-lines-end forInArrays

You can nest multiple begin/end pairs, and they will stack:

example.ts
// flint-disable-lines-begin forInArrays
// flint-disable-lines-begin namespaceDeclarations
const array = ["a", "b", "c"];
for (const i in array) {
console.log(array[i]);
}
// flint-disable-lines-end namespaceDeclarations
// flint-disable-lines-end forInArrays

Disables one or more rules for just the next line of code.

example.ts
const array = ["a", "b", "c"];
// flint-disable-next-line forInArrays
for (const i in array) {
console.log(array[i]);
}

The rule ID in a directive should match the rule’s identifier. For example:

You can find rule IDs by looking at the rules documentation or by checking the error message when a rule reports an issue.

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:

example.ts
// flint-disable-file altTexts
const 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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.