Skip to content

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.

Flint’s TypeScript plugin provides the following presets:

PresetRecommendedDescription
logical✅ AlwaysCommon rules for finding bugs and enforcing good logical practices.
logicalStrict☑️ When ReadyAdditional rules for finding bugs and enforcing good logical practices.
stylistic✅ AlwaysCommon rules for consistent styling and best stylistic practices.
stylisticStrict☑️ When ReadyAdditional rules for consistent styling and best stylistic practices.
untypedExtra 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:

flint.config.ts
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:

flint.config.ts
import { defineConfig, ts } from "flint";
export default defineConfig({
use: [
{
files: ts.files.all,
rules: [ts.presets.logicalStrict, ts.presets.stylisticStrict],
},
],
});

Rules that find bugs and enforce good logical practices for most-to-all JavaScript and TypeScript files.

flint.config.ts
import { defineConfig, ts } from "flint";
export default defineConfig({
use: [
{
files: ts.files.all,
rules: ts.presets.logical,
},
],
});

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.

flint.config.ts
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.

Rules that enforce consistent styling and best stylistic practices for most-to-all JavaScript and TypeScript files.

flint.config.ts
import { defineConfig, ts } from "flint";
export default defineConfig({
use: [
{
files: ts.files.all,
rules: ts.presets.stylistic,
},
],
});

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.

flint.config.ts
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.

Rules that fill in rudimentary safety practices that would normally be caught by TypeScript.

flint.config.ts
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 RulePreset
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
arrayElementDeletionslogical
arrayEmptyCallbackSlotslogical
arrayMapIdentitiesReports using .flatMap() with an identity function that returns its argument unchanged.logical
arrayUnnecessaryLengthChecksReports unnecessary array length checks before .some() or .every() calls.logical
asyncFunctionAwaitslogical
asyncPromiseExecutorsReports using async functions as Promise executor functions.logical
asyncUnnecessaryPromiseWrappersReports unnecessary Promise.resolve() or Promise.reject() in async contexts.logical
awaitThenablelogical
caseDuplicatesReports switch statements with duplicate case clause test expressions.logical
caseFallthroughslogical
catchCallbackTypeslogical
charAtComparisonslogical
constVariableslogical
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
emptyEnumslogical
emptyExportslogical
emptyObjectTypeslogical
enumMemberLiteralslogical
enumMixedValueslogical
enumValueConsistencylogical
enumValueDuplicateslogical
equalityOperatorslogical
errorUnnecessaryCaptureStackTraceslogical
evalslogical
exceptionAssignmentsReports reassigning exception parameters in catch clauses.logical
explicitAnyslogical
exportMutableslogical
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
floatingPromiseslogical
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
getterSetterPairedTypeslogical
impliedEvalslogical
importEmptyBlockslogical
instanceOfArrayslogical
irregularWhitespaceslogical
isNaNComparisonslogical
meaninglessVoidOperatorslogical
misleadingVoidExpressionslogical
misusedPromiseslogical
moduleSpecifierListslogical
namespaceDeclarationsReports using legacy namespace declarations.logical
negativeZeroComparisonsReports comparisons with -0 that may not behave as expected.logical
newDefinitionslogical
newExpressionsReports standalone new expressions that don't use the constructed object.logical
nonNullAssertedOptionalChainslogical
nonOctalDecimalEscapesReports non-octal decimal escape sequences (\8 and \9) in string literals.logical
numberMethodRangeslogical
numericErasingOperationslogical
numericPrecisionlogical
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
objectSpreadUnnecessaryFallbackslogical
parameterPropertyAssignmentlogical
parseIntRadixeslogical
plusOperandslogical
promiseExecutorReturnslogical
promiseFinallyReturnslogical
promiseMethodSingleArrayArgumentslogical
promiseRejectErrorslogical
recursionOnlyArgumentslogical
redundantTypeConstituentslogical
regexAllGlobalFlagslogical
regexAmbiguousInvaliditylogical
regexContradictoryAssertionslogical
regexControlCharacterEscapeslogical
regexControlCharacterslogical
regexDuplicateCharacterClassCharacterslogical
regexDuplicateDisjunctionslogical
regexEmptyAlternativeslogical
regexEmptyCapturingGroupslogical
regexEmptyCharacterClasseslogical
regexEmptyGroupslogical
regexEmptyLazyQuantifierslogical
regexEmptyLookaroundsAssertionslogical
regexEmptyStringLiteralslogical
regexEscapeBackspaceslogical
regexIgnoreCaseFlagslogical
regexInvisibleCharacterslogical
regexLegacyFeatureslogical
regexLiteralslogical
regexLookaroundQuantifierOptimizationslogical
regexMisleadingCapturingGroupslogical
regexMisleadingQuantifierslogical
regexMisleadingUnicodeCharacterslogical
regexNamedCaptureGroupslogical
regexNonStandardFlagslogical
regexObscureRangeslogical
regexOctalEscapeslogical
regexQuantifierOptimizationslogical
regexSetOperationOptimizationslogical
regexStandaloneBackslasheslogical
regexSuperLinearBacktrackinglogical
regexSuperLinearMoveslogical
regexUnnecessaryAssertionslogical
regexUnnecessaryBackreferenceslogical
regexUnnecessaryCharacterClasseslogical
regexUnnecessaryCharacterRangeslogical
regexUnnecessaryDisjunctionslogical
regexUnnecessaryDollarReplacementslogical
regexUnnecessaryLookaroundAssertionslogical
regexUnnecessaryNestedAssertionslogical
regexUnnecessaryNestedQuantifierslogical
regexUnnecessaryNumericQuantifierslogical
regexUnnecessaryOptionalAssertionslogical
regexUnnecessaryReferentialBackreferenceslogical
regexUnnecessarySetOperandslogical
regexUnusedCapturingGroupslogical
regexUnusedFlagslogical
regexUnusedLazyQuantifierslogical
regexUnusedQuantifierslogical
regexValiditylogical
regexZeroQuantifierslogical
requireImportslogical
returnAwaitPromiseslogical
selfAssignmentsReports self-assignments which have no effect and are likely errors.logical
singleVariableDeclarationslogical
sparseArraysReports array literals with holes (sparse arrays).logical
strictBooleanExpressionslogical
stringCaseMismatcheslogical
templateExpressionValueslogical
thisAliaseslogical
throwErrorslogical
tripleSlashReferenceslogical
tripleSlashReferenceValiditylogical
tsCommentslogical
typeConstituentDuplicateslogical
unboundMethodslogical
unnecessaryBindlogical
unnecessaryCatchesReports catch clauses that only rethrow the caught error without modification.logical
unnecessaryComparisonslogical
unnecessaryConditionslogical
unnecessaryContinueslogical
unnecessaryLogicalComparisonslogical
unnecessaryMathClampslogical
unnecessaryNumericFractionslogical
unnecessarySpreadslogical
unnecessaryTemplateExpressionslogical
unnecessaryTypeArgumentslogical
unnecessaryTypeAssertionslogical
unnecessaryTypeConstraintslogical
unnecessaryTypeConversionslogical
unnecessaryTypeParameterslogical
unnecessaryUndefinedDefaultslogical
unnecessaryUseStrictslogical
unsafeDeclarationmerginglogical
unsafeEnumComparisonslogical
unsafeFunctionTypeslogical
unsafeToStringlogical
unsafeTypeAssertionslogical
unsafeUnaryNegationslogical
unusedExpressionslogical
unusedPrivateClassMemberslogical
unusedSwitchStatementslogical
unusedValueslogical
unusedVariableslogical
uselessDefaultAssignmentslogical
wrapperObjectslogical
wrapperObjectTypeslogical
accessorThisRecursionlogical (strict)
awaitInsidePromiseMethodslogical (strict)
caughtErrorCauseslogical (strict)
dateNowTimestampsPrefer the shorter Date.now() to get the number of milliseconds since the Unix Epoch.logical (strict)
directivePairslogical (strict)
errorMessageslogical (strict)
errorSubclassPropertieslogical (strict)
extraneousClasseslogical (strict)
invalidVoidTypeslogical (strict)
nonNullAssertedNullishCoalesceslogical (strict)
nonNullAssertionslogical (strict)
reduceTypeParameterslogical (strict)
regexGraphemeStringLiteralslogical (strict)
returnThisTypeslogical (strict)
selfComparisonsReports comparing a value to itself.logical (strict)
stringCodePointslogical (strict)
unifiedSignatureslogical (strict)
importExtraneousDependenciesnone
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
arrayFlatUnnecessaryDepthsstylistic
arrayIncludesstylistic
arrayLoopsstylistic
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
arrayTypesstylistic
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
emptyModuleAttributesstylistic
emptyStaticBlocksReports empty static initialization blocks within class declarations.stylistic
emptyTypeParameterListsstylistic
exponentiationOperatorsstylistic
exportFromImportsstylistic
forDirectionsReports for loops with counter variables that move in the wrong direction.stylistic
functionApplySpreadsPrefer the spread operator over .apply() calls.stylistic
functionTypeDeclarationsstylistic
genericConstructorCallsstylistic
groupedAccessorPairsstylistic
importCyclesstylistic
importDuplicatesstylistic
importSelfstylistic
importUnnecessaryPathSegmentsstylistic
indexedObjectTypesstylistic
jsdocAccessTagsstylistic
jsdocEmptyBlocksstylistic
jsdocEmptyTagsstylistic
jsdocImplementsTagsstylistic
jsdocParameterNamesstylistic
jsdocPropertyNamesstylistic
jsdocRedundantTypesstylistic
jsdocTemplateNamesstylistic
jsdocTypesSyntaxstylistic
jsdocUnnecessaryReturnsstylistic
jsdocUnnecessaryYieldsstylistic
jsdocValidTypesstylistic
jsdocValuesstylistic
jsdocYieldsstylistic
literalConstructorWrappersstylistic
methodSignatureStylesstylistic
multilineAmbiguitiesReports ambiguous multiline expressions that could be misinterpreted.stylistic
namespaceKeywordsstylistic
nestedStandaloneIfsstylistic
nonNullableTypeAssertionsstylistic
nullishCoalescingOperatorsstylistic
numericLiteralParsingReports parseInt calls with binary, hexadecimal, or octal strings that can be replaced with numeric literals.stylistic
objectAssignSpreadsstylistic
objectHasOwnsPrefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() for checking own properties.stylistic
objectShorthandstylistic
objectTypeDefinitionsstylistic
operatorAssignmentShorthandstylistic
optionalChainOperatorsstylistic
overloadSignaturesAdjacentstylistic
promiseFunctionAsyncstylistic
propertyAccessNotationstylistic
regexCharacterClassRangesstylistic
regexCharacterClassSetOperationsstylistic
regexConciseCharacterClassNegationsstylistic
regexDollarEscapesstylistic
regexPredefinedAssertionsstylistic
regexRepeatQuantifiersstylistic
regexTestMethodsstylistic
regexUnicodeEscapesstylistic
regexUnicodePropertiesstylistic
regexUnnecessaryEscapesstylistic
responseMethodsstylistic
returnAssignmentsReports using assignment expressions in return statements.stylistic
shadowsstylistic
stringStartsEndsWithstylistic
symbolDescriptionsReports Symbol() calls without description arguments.stylistic
tslintCommentsstylistic
typeAssertionsstylistic
typeExportsstylistic
typeImportsstylistic
undefinedInitialValuesstylistic
unicodeBOMsReports files with Unicode Byte Order Marks (BOMs).stylistic
unnecessaryBlocksReports standalone block statements that don't create a meaningful scope.stylistic
unnecessaryBooleanCastsstylistic
unnecessaryComputedKeysstylistic
unnecessaryConcatenationReports string concatenation using the + operator when both operands are string literals.stylistic
unnecessaryConstructorsstylistic
unnecessaryEscapesstylistic
unnecessaryQualifiersstylistic
unnecessaryRenamesstylistic
unnecessaryReturnsstylistic
unnecessaryTypeAnnotationsstylistic
unusedLabelsstylistic
varDeclarationsstylistic
voidOperatorReports using the void operator.stylistic
arrayFilteredFindsstylistic (strict)
arrayFlatMapMethodsstylistic (strict)
arrayFlatMethodsstylistic (strict)
arrayIncludesMethodsstylistic (strict)
arrayIndexOfMethodsstylistic (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)
caughtVariableNamesstylistic (strict)
classMethodsThisstylistic (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)
directiveRequireDescriptionsstylistic (strict)
elseReturnsstylistic (strict)
emptyFilesstylistic (strict)
emptyFunctionsstylistic (strict)
escapeSequenceCasingstylistic (strict)
functionDefinitionScopeConsistencystylistic (strict)
globalThisAliasesstylistic (strict)
jsdocAsterisksstylistic (strict)
jsdocInformativeDocsstylistic (strict)
jsdocMisleadingBlocksstylistic (strict)
jsdocMultilineBlocksstylistic (strict)
jsdocParameterDescriptionHyphensstylistic (strict)
jsdocTagNamesstylistic (strict)
mathMethodsstylistic (strict)
namedDefaultExportsstylistic (strict)
namespaceImplicitAmbientImportsstylistic (strict)
negativeIndexLengthMethodsstylistic (strict)
nonNullAssertionPlacementstylistic (strict)
numberStaticMethodsstylistic (strict)
numericLiteralCasingstylistic (strict)
numericSeparatorGroupsstylistic (strict)
objectEntriesMethodsstylistic (strict)
parameterReassignmentsstylistic (strict)
regexCharacterClassesstylistic (strict)
regexDigitMatchersstylistic (strict)
regexExecutorsstylistic (strict)
regexHexadecimalEscapesstylistic (strict)
regexLetterCasingstylistic (strict)
regexLookaroundAssertionsstylistic (strict)
regexMatchNotationstylistic (strict)
regexNamedBackreferencesstylistic (strict)
regexNamedReplacementsstylistic (strict)
regexPlusQuantifiersstylistic (strict)
regexQuestionQuantifiersstylistic (strict)
regexResultArrayGroupsstylistic (strict)
regexStarQuantifiersstylistic (strict)
regexUnicodeCodepointEscapesstylistic (strict)
regexUnnecessaryNonCapturingGroupsstylistic (strict)
regexWordMatchersstylistic (strict)
setHasExistenceChecksstylistic (strict)
setSizeLengthChecksstylistic (strict)
sizeComparisonOperatorsstylistic (strict)
staticMemberOnlyClassesstylistic (strict)
stringSliceMethodsstylistic (strict)
stringTrimMethodsstylistic (strict)
structuredCloneMethodsstylistic (strict)
topLevelAwaitsstylistic (strict)
undefinedTypeofChecksstylistic (strict)
unnecessaryTernariesstylistic (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
constructorSupersuntyped
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
getterReturnsuntyped
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
importAssignmentsuntyped
invalidThisuntyped
nativeObjectExtensionsuntyped
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
setterReturnsuntyped
shadowedRestrictedNamesReports variable declarations that shadow JavaScript's restricted names.untyped
thisBeforeSuperuntyped
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
unreachableStatementsuntyped
unsafeNegationsReports negating the left operand of in or instanceof relations.untyped
unsafeOptionalChainsuntyped
usageBeforeDefinitionuntyped
useStrictDirectivesuntyped
variableBlockScopeUsageuntyped
variableDeletionsReports attempting to delete variables with the delete operator.untyped
variableRedeclarationsuntyped
withStatementsReports using with statementsuntyped
consoleCalls(none)
importTypeSideEffects(none)
regexUnicodeFlag(none)
restrictedGlobals(none)
restrictedIdentifiers(none)
restrictedImports(none)
restrictedProperties(none)
restrictedSyntax(none)
restrictedTypes(none)

Flint’s TypeScript plugin provides the following file selector:

  • all: **/*.{cjs,js,jsx,mjs,ts,tsx}
Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.