TypeScript (and JavaScript) Plugin
Rules for linting JavaScript and TypeScript code, including the latest and greatest powerful typed linting rules.
This plugin comes packaged with the flint npm package.
Presets
Section titled “Presets”Flint’s TypeScript plugin provides the following presets:
| Preset | Recommended | Description |
|---|---|---|
logical | ✅ Always | Common rules for finding bugs and enforcing good logical practices. |
logicalStrict | ☑️ When Ready | Additional rules for finding bugs and enforcing good logical practices. |
stylistic | ✅ Always | Common rules for consistent styling and best stylistic practices. |
stylisticStrict | ☑️ When Ready | Additional rules for consistent styling and best stylistic practices. |
untyped | Extra rules for files that aren’t type-checked by TypeScript. |
If you are just getting started with linting, Flint recommends using the logical and stylistic presets:
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: [ts.presets.logical, ts.presets.stylistic], }, ],});If you are experienced with both JavaScript/TypeScript and linting, Flint recommends using the logicalStrict and stylisticStrict presets:
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: [ts.presets.logicalStrict, ts.presets.stylisticStrict], }, ],});logical
Section titled “logical”Rules that find bugs and enforce good logical practices for most-to-all JavaScript and TypeScript files.
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: ts.presets.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 using a linter.
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: ts.presets.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 JavaScript and TypeScript files.
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: ts.presets.stylistic, }, ],});stylisticStrict
Section titled “stylisticStrict”Additional stylistic 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 using a linter.
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: ts.presets.stylisticStrict, }, ],});This preset’s rules are a superset of those in stylistic.
untyped
Section titled “untyped”Rules that fill in rudimentary safety practices that would normally be caught by TypeScript.
import { defineConfig, ts } from "flint";
export default defineConfig({ use: [ { files: ts.files.all, rules: ts.presets.untyped, }, ],});The untyped preset is broadly applicable for JavaScript files that aren’t type-checked by TypeScript.
For long-lived projects, Flint recommends using this only as a stopgap measure pending converting files fully to TypeScript.
Implemented: 92 of 399 (23%)
| Flint Rule | Preset |
|---|---|
anyArgumentsReports calling a function with a value typed as any as an argument. | logical |
anyAssignmentsReports assigning a value with type any to variables and properties. | logical |
anyCallsReports calling a value with type any. | logical |
anyMemberAccessReports member access on a value with type any. | logical |
anyReturnsReports returning a value with type any from a function. | logical |
argumentsReports using the arguments object instead of rest parameters. | logical |
arrayConstructorsReports using the Array constructor to create arrays instead of array literal syntax. | logical |
arrayElementDeletions | logical |
arrayEmptyCallbackSlots | logical |
arrayMapIdentitiesReports using .flatMap() with an identity function that returns its argument unchanged. | logical |
arrayUnnecessaryLengthChecksReports unnecessary array length checks before .some() or .every() calls. | logical |
asyncFunctionAwaits | logical |
asyncPromiseExecutorsReports using async functions as Promise executor functions. | logical |
asyncUnnecessaryPromiseWrappersReports unnecessary Promise.resolve() or Promise.reject() in async contexts. | logical |
awaitThenable | logical |
caseDuplicatesReports switch statements with duplicate case clause test expressions. | logical |
caseFallthroughs | logical |
catchCallbackTypes | logical |
charAtComparisons | logical |
constVariables | logical |
dateConstructorClonesPrefer passing a Date directly to the Date constructor when cloning, rather than calling getTime(). | logical |
debuggerStatementsReports using debugger statements. | logical |
defaultCaseLastReports switch statements where the default clause is not last. | logical |
deprecatedDisallow using code marked as @deprecated. | logical |
dynamicDeletesDisallow using the delete operator on computed key expressions. | logical |
elseIfDuplicatesReports duplicate conditions in if-else-if chains that make code unreachable. | logical |
emptyDestructuresReports using empty destructuring patterns that destructure no values. | logical |
emptyEnums | logical |
emptyExports | logical |
emptyObjectTypes | logical |
enumMemberLiterals | logical |
enumMixedValues | logical |
enumValueConsistency | logical |
enumValueDuplicates | logical |
equalityOperators | logical |
errorUnnecessaryCaptureStackTraces | logical |
evals | logical |
exceptionAssignmentsReports reassigning exception parameters in catch clauses. | logical |
explicitAnys | logical |
exportMutables | logical |
fetchMethodBodiesDisallow providing a body with GET or HEAD fetch requests. | logical |
finallyStatementSafetyReports control flow statements in finally blocks that can override control flow in try/catch blocks. | logical |
floatingPromises | logical |
forInArraysReports iterating over an array with a for-in loop. | logical |
functionCurryingRedundancyReports using .apply() or .call() or when the context (this value) provides no benefit. | logical |
functionNewCallsReports using the Function constructor to create functions from strings. | logical |
generatorFunctionYieldsReports generator functions that do not yield values. | logical |
getterSetterPairedTypes | logical |
impliedEvals | logical |
importEmptyBlocks | logical |
instanceOfArrays | logical |
irregularWhitespaces | logical |
isNaNComparisons | logical |
meaninglessVoidOperators | logical |
misleadingVoidExpressions | logical |
misusedPromises | logical |
moduleSpecifierLists | logical |
namespaceDeclarationsReports using legacy namespace declarations. | logical |
negativeZeroComparisonsReports comparisons with -0 that may not behave as expected. | logical |
newDefinitions | logical |
newExpressionsReports standalone new expressions that don't use the constructed object. | logical |
nonNullAssertedOptionalChains | logical |
nonOctalDecimalEscapesReports non-octal decimal escape sequences (\8 and \9) in string literals. | logical |
numberMethodRanges | logical |
numericErasingOperations | logical |
numericPrecision | logical |
objectCallsPrefer {} object literal notation or Object.create instead of calling or constructing Object. | logical |
objectPrototypeBuiltInsReports direct calls to Object.prototype methods on object instances. | logical |
objectSpreadUnnecessaryFallbacks | logical |
parameterPropertyAssignment | logical |
parseIntRadixes | logical |
plusOperands | logical |
promiseExecutorReturns | logical |
promiseFinallyReturns | logical |
promiseMethodSingleArrayArguments | logical |
promiseRejectErrors | logical |
recursionOnlyArguments | logical |
redundantTypeConstituents | logical |
regexAllGlobalFlags | logical |
regexAmbiguousInvalidity | logical |
regexContradictoryAssertions | logical |
regexControlCharacterEscapes | logical |
regexControlCharacters | logical |
regexDuplicateCharacterClassCharacters | logical |
regexDuplicateDisjunctions | logical |
regexEmptyAlternatives | logical |
regexEmptyCapturingGroups | logical |
regexEmptyCharacterClasses | logical |
regexEmptyGroups | logical |
regexEmptyLazyQuantifiers | logical |
regexEmptyLookaroundsAssertions | logical |
regexEmptyStringLiterals | logical |
regexEscapeBackspaces | logical |
regexIgnoreCaseFlags | logical |
regexInvisibleCharacters | logical |
regexLegacyFeatures | logical |
regexLiterals | logical |
regexLookaroundQuantifierOptimizations | logical |
regexMisleadingCapturingGroups | logical |
regexMisleadingQuantifiers | logical |
regexMisleadingUnicodeCharacters | logical |
regexNamedCaptureGroups | logical |
regexNonStandardFlags | logical |
regexObscureRanges | logical |
regexOctalEscapes | logical |
regexQuantifierOptimizations | logical |
regexSetOperationOptimizations | logical |
regexStandaloneBackslashes | logical |
regexSuperLinearBacktracking | logical |
regexSuperLinearMoves | logical |
regexUnnecessaryAssertions | logical |
regexUnnecessaryBackreferences | logical |
regexUnnecessaryCharacterClasses | logical |
regexUnnecessaryCharacterRanges | logical |
regexUnnecessaryDisjunctions | logical |
regexUnnecessaryDollarReplacements | logical |
regexUnnecessaryLookaroundAssertions | logical |
regexUnnecessaryNestedAssertions | logical |
regexUnnecessaryNestedQuantifiers | logical |
regexUnnecessaryNumericQuantifiers | logical |
regexUnnecessaryOptionalAssertions | logical |
regexUnnecessaryReferentialBackreferences | logical |
regexUnnecessarySetOperands | logical |
regexUnusedCapturingGroups | logical |
regexUnusedFlags | logical |
regexUnusedLazyQuantifiers | logical |
regexUnusedQuantifiers | logical |
regexValidity | logical |
regexZeroQuantifiers | logical |
requireImports | logical |
returnAwaitPromises | logical |
selfAssignmentsReports self-assignments which have no effect and are likely errors. | logical |
singleVariableDeclarations | logical |
sparseArraysReports array literals with holes (sparse arrays). | logical |
strictBooleanExpressions | logical |
stringCaseMismatches | logical |
templateExpressionValues | logical |
thisAliases | logical |
throwErrors | logical |
tripleSlashReferences | logical |
tripleSlashReferenceValidity | logical |
tsComments | logical |
typeConstituentDuplicates | logical |
unboundMethods | logical |
unnecessaryBind | logical |
unnecessaryCatchesReports catch clauses that only rethrow the caught error without modification. | logical |
unnecessaryComparisons | logical |
unnecessaryConditions | logical |
unnecessaryContinues | logical |
unnecessaryLogicalComparisons | logical |
unnecessaryMathClamps | logical |
unnecessaryNumericFractions | logical |
unnecessarySpreads | logical |
unnecessaryTemplateExpressions | logical |
unnecessaryTypeArguments | logical |
unnecessaryTypeAssertions | logical |
unnecessaryTypeConstraints | logical |
unnecessaryTypeConversions | logical |
unnecessaryTypeParameters | logical |
unnecessaryUndefinedDefaults | logical |
unnecessaryUseStricts | logical |
unsafeDeclarationmerging | logical |
unsafeEnumComparisons | logical |
unsafeFunctionTypes | logical |
unsafeToString | logical |
unsafeTypeAssertions | logical |
unsafeUnaryNegations | logical |
unusedExpressions | logical |
unusedPrivateClassMembers | logical |
unusedSwitchStatements | logical |
unusedValues | logical |
unusedVariables | logical |
uselessDefaultAssignments | logical |
wrapperObjects | logical |
wrapperObjectTypes | logical |
accessorThisRecursion | logical (strict) |
awaitInsidePromiseMethods | logical (strict) |
caughtErrorCauses | logical (strict) |
dateNowTimestampsPrefer the shorter Date.now() to get the number of milliseconds since the Unix Epoch. | logical (strict) |
directivePairs | logical (strict) |
errorMessages | logical (strict) |
errorSubclassProperties | logical (strict) |
extraneousClasses | logical (strict) |
invalidVoidTypes | logical (strict) |
nonNullAssertedNullishCoalesces | logical (strict) |
nonNullAssertions | logical (strict) |
reduceTypeParameters | logical (strict) |
regexGraphemeStringLiterals | logical (strict) |
returnThisTypes | logical (strict) |
selfComparisonsReports comparing a value to itself. | logical (strict) |
stringCodePoints | logical (strict) |
unifiedSignatures | logical (strict) |
importExtraneousDependencies | none |
arrayDeleteUnnecessaryCountsReports using .length or Infinity as the deleteCount or skipCount argument of Array#splice() or Array#toSpliced(). | stylistic |
arrayExistenceChecksConsistencyReports inconsistent styles for checking element existence using index methods. | stylistic |
arrayFindsReports using .filter()[0] instead of .find() when looking for a single element. | stylistic |
arrayFlatUnnecessaryDepths | stylistic |
arrayIncludes | stylistic |
arrayLoops | stylistic |
arrayMutableReversesReports .reverse() calls on arrays that mutate the original array. | stylistic |
arrayMutableSortsReports .sort() calls on arrays that mutate the original array. | stylistic |
arraySliceUnnecessaryEndReports unnecessary end argument in .slice() calls when it equals the length or is Infinity. | stylistic |
arrayTernarySpreadingConsistencyReports inconsistent types when spreading a ternary in an array literal. | stylistic |
arrayTypes | stylistic |
asConstAssertionsReports using explicit literal types when as const can be used. | stylistic |
assignmentOperatorShorthandsPrefer logical assignment operator shorthand expressions. | stylistic |
builtinConstructorNewsEnforces using new for constructors that require it, and disallows new for primitive coercion functions. | stylistic |
chainedAssignmentsReports using chained assignment expressions (e.g., a = b = c). | stylistic |
classLiteralPropertiesReports getters that return literal values instead of using readonly class fields. | stylistic |
consecutiveNonNullAssertionsReports unnecessary extra non-null assertions. | stylistic |
emptyBlocksReports empty block statements that should contain code. | stylistic |
emptyModuleAttributes | stylistic |
emptyStaticBlocksReports empty static initialization blocks within class declarations. | stylistic |
emptyTypeParameterLists | stylistic |
exponentiationOperators | stylistic |
exportFromImports | stylistic |
forDirectionsReports for loops with counter variables that move in the wrong direction. | stylistic |
functionApplySpreadsPrefer the spread operator over .apply() calls. | stylistic |
functionTypeDeclarations | stylistic |
genericConstructorCalls | stylistic |
groupedAccessorPairs | stylistic |
importCycles | stylistic |
importDuplicates | stylistic |
importSelf | stylistic |
importUnnecessaryPathSegments | stylistic |
indexedObjectTypes | stylistic |
jsdocAccessTags | stylistic |
jsdocEmptyBlocks | stylistic |
jsdocEmptyTags | stylistic |
jsdocImplementsTags | stylistic |
jsdocParameterNames | stylistic |
jsdocPropertyNames | stylistic |
jsdocRedundantTypes | stylistic |
jsdocTemplateNames | stylistic |
jsdocTypesSyntax | stylistic |
jsdocUnnecessaryReturns | stylistic |
jsdocUnnecessaryYields | stylistic |
jsdocValidTypes | stylistic |
jsdocValues | stylistic |
jsdocYields | stylistic |
literalConstructorWrappers | stylistic |
methodSignatureStyles | stylistic |
multilineAmbiguitiesReports ambiguous multiline expressions that could be misinterpreted. | stylistic |
namespaceKeywords | stylistic |
nestedStandaloneIfs | stylistic |
nonNullableTypeAssertions | stylistic |
nullishCoalescingOperators | stylistic |
numericLiteralParsingReports parseInt calls with binary, hexadecimal, or octal strings that can be replaced with numeric literals. | stylistic |
objectAssignSpreads | stylistic |
objectHasOwnsPrefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() for checking own properties. | stylistic |
objectShorthand | stylistic |
objectTypeDefinitions | stylistic |
operatorAssignmentShorthand | stylistic |
optionalChainOperators | stylistic |
overloadSignaturesAdjacent | stylistic |
promiseFunctionAsync | stylistic |
propertyAccessNotation | stylistic |
regexCharacterClassRanges | stylistic |
regexCharacterClassSetOperations | stylistic |
regexConciseCharacterClassNegations | stylistic |
regexDollarEscapes | stylistic |
regexPredefinedAssertions | stylistic |
regexRepeatQuantifiers | stylistic |
regexTestMethods | stylistic |
regexUnicodeEscapes | stylistic |
regexUnicodeProperties | stylistic |
regexUnnecessaryEscapes | stylistic |
responseMethods | stylistic |
returnAssignmentsReports using assignment expressions in return statements. | stylistic |
shadows | stylistic |
stringStartsEndsWith | stylistic |
symbolDescriptionsReports Symbol() calls without description arguments. | stylistic |
tslintComments | stylistic |
typeAssertions | stylistic |
typeExports | stylistic |
typeImports | stylistic |
undefinedInitialValues | stylistic |
unicodeBOMsReports files with Unicode Byte Order Marks (BOMs). | stylistic |
unnecessaryBlocksReports standalone block statements that don't create a meaningful scope. | stylistic |
unnecessaryBooleanCasts | stylistic |
unnecessaryComputedKeys | stylistic |
unnecessaryConcatenationReports string concatenation using the + operator when both operands are string literals. | stylistic |
unnecessaryConstructors | stylistic |
unnecessaryEscapes | stylistic |
unnecessaryQualifiers | stylistic |
unnecessaryRenames | stylistic |
unnecessaryReturns | stylistic |
unnecessaryTypeAnnotations | stylistic |
unusedLabels | stylistic |
varDeclarations | stylistic |
voidOperatorReports using the void operator. | stylistic |
arrayFilteredFinds | stylistic (strict) |
arrayFlatMapMethods | stylistic (strict) |
arrayFlatMethods | stylistic (strict) |
arrayIncludesMethods | stylistic (strict) |
arrayIndexOfMethods | stylistic (strict) |
arraySomeMethodsReports patterns that can be replaced with .some() for checking array element existence. | stylistic (strict) |
atAccessesPrefer using .at() for accessing elements at negative indices. | stylistic (strict) |
builtinCoercionsReports functions that wrap native coercion functions like String, Number, BigInt, Boolean, or Symbol. | stylistic (strict) |
caughtVariableNames | stylistic (strict) |
classMethodsThis | stylistic (strict) |
combinedPushesReports consecutive array.push() calls that could be combined into a single call. | stylistic (strict) |
destructuringConsistencyUse destructured variables over properties for consistency. | stylistic (strict) |
directiveRequireDescriptions | stylistic (strict) |
elseReturns | stylistic (strict) |
emptyFiles | stylistic (strict) |
emptyFunctions | stylistic (strict) |
escapeSequenceCasing | stylistic (strict) |
functionDefinitionScopeConsistency | stylistic (strict) |
globalThisAliases | stylistic (strict) |
jsdocAsterisks | stylistic (strict) |
jsdocInformativeDocs | stylistic (strict) |
jsdocMisleadingBlocks | stylistic (strict) |
jsdocMultilineBlocks | stylistic (strict) |
jsdocParameterDescriptionHyphens | stylistic (strict) |
jsdocTagNames | stylistic (strict) |
mathMethods | stylistic (strict) |
namedDefaultExports | stylistic (strict) |
namespaceImplicitAmbientImports | stylistic (strict) |
negativeIndexLengthMethods | stylistic (strict) |
nonNullAssertionPlacement | stylistic (strict) |
numberStaticMethods | stylistic (strict) |
numericLiteralCasing | stylistic (strict) |
numericSeparatorGroups | stylistic (strict) |
objectEntriesMethods | stylistic (strict) |
parameterReassignments | stylistic (strict) |
regexCharacterClasses | stylistic (strict) |
regexDigitMatchers | stylistic (strict) |
regexExecutors | stylistic (strict) |
regexHexadecimalEscapes | stylistic (strict) |
regexLetterCasing | stylistic (strict) |
regexLookaroundAssertions | stylistic (strict) |
regexMatchNotation | stylistic (strict) |
regexNamedBackreferences | stylistic (strict) |
regexNamedReplacements | stylistic (strict) |
regexPlusQuantifiers | stylistic (strict) |
regexQuestionQuantifiers | stylistic (strict) |
regexResultArrayGroups | stylistic (strict) |
regexStarQuantifiers | stylistic (strict) |
regexUnicodeCodepointEscapes | stylistic (strict) |
regexUnnecessaryNonCapturingGroups | stylistic (strict) |
regexWordMatchers | stylistic (strict) |
setHasExistenceChecks | stylistic (strict) |
setSizeLengthChecks | stylistic (strict) |
sizeComparisonOperators | stylistic (strict) |
staticMemberOnlyClasses | stylistic (strict) |
stringSliceMethods | stylistic (strict) |
stringTrimMethods | stylistic (strict) |
structuredCloneMethods | stylistic (strict) |
topLevelAwaits | stylistic (strict) |
undefinedTypeofChecks | stylistic (strict) |
unnecessaryTernaries | stylistic (strict) |
arrayCallbackReturnsReports missing return statements in callbacks of array methods. | untyped |
caseDeclarationsReports lexical declarations in case clauses without wrapping them in blocks. | untyped |
classAssignmentsReports reassigning class declarations. | untyped |
classFieldDeclarationsReports assigning literal values to this in constructors instead of using class field declarations. | untyped |
classMemberDuplicatesReports duplicate class member names that will be overwritten. | untyped |
constantAssignmentsReports attempting to reassign variables declared with const. | untyped |
constructorReturnsReports returning values from constructor functions. | untyped |
constructorSupers | untyped |
defaultParameterLastEnforce default parameters to be last. | untyped |
duplicateArgumentsReports functions with duplicate parameter names in their signatures. | untyped |
functionAssignmentsReports reassigning variables declared with function declarations. | untyped |
getterReturns | untyped |
globalAssignmentsReports attempting to assign to read-only global variables such as undefined, NaN, Infinity, Object, etc. | untyped |
globalObjectCallsReports calling global objects like Math, JSON, or Reflect as functions. | untyped |
importAssignments | untyped |
invalidThis | untyped |
nativeObjectExtensions | untyped |
newNativeNonConstructorsDisallows using new with global non-constructor functions like Symbol and BigInt. | untyped |
objectKeyDuplicatesReports unnecessary duplicate keys that override previous values. | untyped |
objectProtoReports using the deprecated proto property to access or modify an object's prototype. | untyped |
octalEscapesReports using octal escape sequences in string literals. | untyped |
octalNumbersReports using legacy octal numeric literals. | untyped |
sequencesReports using the comma operator in expressions. | untyped |
setterReturns | untyped |
shadowedRestrictedNamesReports variable declarations that shadow JavaScript's restricted names. | untyped |
thisBeforeSuper | untyped |
typeofComparisonsReports typeof expressions that compare impossible string literals. | untyped |
unassignedVariablesReports variables that are declared but never assigned a value. | untyped |
undefinedVariablesReports using variables that are not defined. | untyped |
unreachableStatements | untyped |
unsafeNegationsReports negating the left operand of in or instanceof relations. | untyped |
unsafeOptionalChains | untyped |
usageBeforeDefinition | untyped |
useStrictDirectives | untyped |
variableBlockScopeUsage | untyped |
variableDeletionsReports attempting to delete variables with the delete operator. | untyped |
variableRedeclarations | untyped |
withStatementsReports using with statements | untyped |
consoleCalls | (none) |
importTypeSideEffects | (none) |
regexUnicodeFlag | (none) |
restrictedGlobals | (none) |
restrictedIdentifiers | (none) |
restrictedImports | (none) |
restrictedProperties | (none) |
restrictedSyntax | (none) |
restrictedTypes | (none) |
Selectors
Section titled “Selectors”Flint’s TypeScript plugin provides the following file selector:
all:**/*.{cjs,js,jsx,mjs,ts,tsx}