menu
5.1k tokens
Rules
Linter rules.
Rules
Correctness16 rules
float-equality-without-absRequire an absolute difference in `Number.EPSILON` comparisonsfor-directionDisallow for loops whose counter moves away from its boundimprecise-float-operationPrefer numerically stable floating-point operationsinconsistent-equality-implementationDisallow mixing derived and written equality or hashing implementationsmanual-midpointPrefer midpoint operations that cannot overflow intermediate arithmeticno-approx-constantDisallow numeric literals that approximate well-known constantsno-compare-neg-zeroDisallow comparisons with negative zerono-float-loop-counterDisallow float loop counters accumulated by repeated additionno-floating-point-equalityDisallow exact equality comparisons between floating-point valuesno-integer-division-in-float-contextDisallow integer division whose result immediately becomes a floatno-invalid-clampDisallow clamp calls with invalid constant boundsno-negated-float-comparisonDisallow negated floating-point ordering comparisons that accept NaNno-overflow-check-after-overflowDisallow overflow tests that perform the overflowing operation firstno-reversed-rangeDisallow constant ranges whose start exceeds their endno-self-compareDisallow comparisons with identical deterministic operandsuse-isnanRequire NaN predicates for equality-based tests
Suspicious47 rules
almost-complete-rangeDisallow character ranges stopping before their conventional endpointalmost-swappedDisallow assignments that overwrite a value before swapping itambiguous-precedenceRequire grouping where operator precedence is easy to misreadineffective-break-in-switchDisallow nonterminal switch breaks inside an enclosing looploop-single-iterationDisallow loops whose control flow cannot reach another iterationmisrefactored-assign-opDisallow compound assignments that repeat the assigned placemixed-read-write-expressionDisallow reading and mutating the same place in one combined expressionno-array-fill-with-reference-typeDisallow Array.fill values that share mutable referencesno-cond-assignDisallow assignment in conditionsno-debuggerDisallow debugger statementsno-diverging-subexpressionDisallow diverging operations inside continuing expressionsno-drop-of-trivial-valueDisallow dropping values without destructorsno-duplicate-codeDisallow repeated nontrivial code regionsno-duplicate-else-ifDisallow else-if conditions made unreachable by earlier conditionsno-duplicate-match-armsDisallow match arms with identical bodiesno-duplicate-test-hookDisallow duplicate lifecycle hooks in one test suiteno-empty-moduleDisallow empty undecorated module declarationsno-empty-patternDisallow empty destructuring patternsno-erasing-operationDisallow operations that erase their operand into a constantno-focused-testDisallow focused tests and suitesno-identity-operationDisallow arithmetic with an operand that cannot change the resultno-mutated-range-boundDisallow mutating range bounds during iteration over that rangeno-negation-in-equality-checkDisallow negation in equality checksno-return-assignDisallow assignment within an explicit or implicit return valueno-self-assignmentDisallow assigning a stable place to itselfno-single-promise-raceDisallow Promise.race over one Promiseno-skipped-testDisallow skipped tests and suitesno-template-curly-in-stringDisallow template interpolation in regular stringsno-todoDisallow calls to the canonical todo functionno-unused-map-resultDisallow unused Array.map and Iterator.map resultsno-useless-concatDisallow concatenating adjacent string literalsno-useless-constructorDisallow constructors that only repeat implicit construction behaviorno-useless-default-assignmentDisallow defaults that cannot be selected by the checked input typeno-useless-length-checkDisallow length checks duplicated by the guarded array operationno-useless-promise-resolveDisallow Promise.resolve calls that preserve the same Promiseno-useless-renameDisallow imports, exports, and destructuring fields renamed to the same nameno-useless-returnDisallow bare returns where the function already endsno-useless-spreadDisallow spreads that have no observable effectno-useless-switch-caseDisallow empty switch cases adjacent to the default casenonminimal-boolSimplify boolean expressions with redundant or contradictory termsnonsensical-open-optionsDisallow contradictory or ineffective file open optionsonly-used-in-recursionDisallow parameters used only to calculate their own recursive argumentredundant-pattern-matchingPrefer canonical result predicates over boolean pattern matchessuspicious-operand-groupingDisallow inconsistent member pairings in comparison chainssuspicious-operator-implementationDisallow direct operator implementations built on a different operatortemporary-assignmentDisallow assignments into discarded struct and tuple constructionswildcard-enum-match-armDisallow wildcard arms when matching nominal enums
Security3 rules
Performance44 rules
clone-on-copyDisallow cloning values whose checked type is Copycloned-instead-of-copiedPrefer copying iterator elements whose type is Copydrain-collectDisallow draining a collection only to collect the same elements againiter-cloned-collectPrefer direct collection copying over iterator collectioniter-overeager-clonedDelay iterator cloning until after operations that discard elementslarge-variantDisallow variants that disproportionately enlarge an inline unionmanual-copyReplace element-by-element copy loops with a bulk copy operationmanual-extendPrefer extend over loops that insert every iterated valuemanual-fillPrefer fill over an index loop assigning one repeated valuemanual-filter-mapPrefer filterMap when removing undefined values from a mapped arraymanual-retainPrefer retain over replacing an owned array with its filtered resultmanual-try-foldPrefer Iterator.tryFold over reducing a propagated Result accumulatormissing-spin-loopRequire a processor hint in atomic busy-wait loopsneedless-borrow-of-copyPrefer passing small Copy scalars by valueneedless-collectDisallow materializing an Iterator before a terminal operationneedless-pass-by-valueDisallow passing parameters by value when they are never consumed or mutatedno-accumulating-spreadDisallow repeated accumulator spreads within iterationsno-allocation-for-comparisonDisallow allocating conversions performed only to compareno-await-in-promise-methodsDisallow awaiting elements passed to Promise concurrency methodsno-zero-iterator-dropDisallow Iterator.drop with a constant zero countprefer-array-searchPrefer direct Array search operationsprefer-clearPrefer clear over discarding a complete drainprefer-clone-fromPrefer Clone.cloneFrom when replacing a cloneable valueprefer-eager-fallbackPrefer eager fallbacks when deferred evaluation cannot avoid workprefer-find-mapPrefer findMap over separate mapping and search operationsprefer-flat-mapPrefer flatMap over a map followed by a one-level flattenprefer-lazy-fallbackPrefer lazy fallbacks when eager arguments perform avoidable workprefer-length-over-countPrefer stored array length over counting an unchanged iteratorprefer-map-entryPrefer one map entry operation over a guarded insertionprefer-map-hasPrefer Map.has over Map.get when only key presence is observedprefer-map-keys-valuesPrefer Map.keys or Map.values when one entry component is unusedprefer-multiplication-over-powerPrefer multiplication over squaring with exponentiationprefer-single-callCombine consecutive Array.push or Array.unshift callsprefer-slice-parameterPrefer slice parameters over borrowed arraysprefer-with-capacityPrefer withCapacity over immediate reservation after constructionredundant-cloneDisallow clones proven unnecessary by ownership and livenessredundant-closureDisallow closures that only forward their arguments to another functionredundant-iter-clonedDisallow cloning iterator elements that are only borrowed afterwardrepeated-string-growthDisallow repeatedly rebuilding a growing string in an iterationsame-item-pushPrefer bulk initialization over repeatedly pushing one invariant valuesuboptimal-float-operationPrefer faster floating-point operations when their precision is sufficientunnecessary-foldPrefer a specialized iterator operation over an equivalent foldunnecessary-sort-comparatorDisallow comparators that reproduce the natural orderingunused-peekableDisallow peekable iterators that are never peeked
Style139 rules
adjacent-overload-signaturesRequire overload signatures for one declaration to be adjacentboolean-prefixRequire predicate prefixes for boolean valuesbranches-sharing-codeExtract identical branch prefixes or suffixescomment-styleRequire canonical style for comments and documentationdecimal-bitwise-operandDisallow opaque decimal masks in bitwise operationsdefault-case-lastRequire the default switch case lastdefault-param-lastRequire optional and defaulted parameters after required parametersdot-notationPrefer dot notation for statically named member accessdouble-comparisonsPrefer one comparison over an equivalent pair of comparisonsexcessive-nestingDisallow control flow nested beyond four levelsfilename-caseRequire lowercase kebab-case source filenamesgrouped-accessor-pairsRequire getter and setter pairs to be adjacentidentifier-caseRequire canonical casing for declared identifiersinconsistent-field-orderRequire nominal literal fields in declaration ordermanual-abs-diffPrefer absDiff over equivalent branching subtractionmanual-ascii-checkPrefer character predicates over ASCII range checksmanual-assertPrefer assertions over conditional panicsmanual-assert-equalPrefer equality assertions over asserting a comparisonmanual-checked-divisionPrefer checked division over manual zero guardsmanual-clampPrefer clamp over nested bound comparisonsmanual-div-ceilPrefer divideCeil over an adjusted integer numeratormanual-euclidean-remainderPrefer remainderEuclidean over its manual double-remainder formmanual-filterPrefer Array.filter over manually collecting matching elementsmanual-findPrefer find over a loop returning the first matching elementmanual-integer-logPrefer integerLog2 over equivalent base-two integer logarithmsmanual-is-finitePrefer `.isFinite()` over equivalent infinity comparisonsmanual-is-infinitePrefer `.isInfinite()` over equivalent infinity comparisonsmanual-is-multiple-ofPrefer isMultipleOf over a remainder comparison with zeromanual-is-power-of-twoPrefer isPowerOfTwo over equivalent unsigned integer testsmanual-isolate-lowest-onePrefer isolateLowestOne over its manual wrapping bitwise formmanual-iterator-inspectPrefer Iterator.inspect when mapping observes and returns each valuemanual-let-elsePrefer let-else over an equivalent match bindingmanual-mapPrefer Array.map over manually collecting transformed elementsmanual-ok-errPrefer Result projection methods over equivalent pattern matchingmanual-pop-ifPrefer Array.popIf over conditionally popping the last elementmanual-range-containsPrefer range membership over equivalent bound comparisonsmanual-range-patternPrefer range patterns over enumerating consecutive valuesmanual-result-tapPrefer Result tap methods when mapping observes and returns its payloadmanual-rotatePrefer integer rotation operations over equivalent shift expressionsmanual-saturating-arithmeticPrefer saturating arithmetic over equivalent manual bounds logicmanual-signumPrefer signum over equivalent sign branchingmanual-strict-comparisonPrefer strict comparison over offsetting an operand by onemanual-stripPrefer prefix or suffix stripping over checking and slicingmanual-struct-conversionPrefer conversions over field-by-field reconstructionmanual-takePrefer take over moving a value and assigning its defaultmanual-unwrap-orPrefer Result fallback methods over equivalent pattern matchingmanual-unwrap-or-defaultPrefer unwrapOrDefault over equivalent Result pattern matchingmap-identityDisallow rebuilding an owned array through an identity mapmissing-docsRequire documentation for named declarationsneedless-borrowDisallow direct borrows that are immediately dereferencedneedless-question-markDisallow propagation immediately wrapped in the same Result typeno-block-in-conditionDisallow block expressions in conditions and scrutineesno-boolean-literal-compareDisallow comparing boolean values to boolean literalsno-collapsible-ifPrefer one condition over nested if statements without alternativesno-collapsible-matchMerge nested matches whose nested pattern fits the enclosing armno-emptyDisallow uncommented empty block statementsno-empty-functionDisallow empty functionsno-empty-static-blockDisallow empty static and compile-time initialization blocksno-explicit-iterator-in-for-ofDisallow explicit iterator calls in for-of loopsno-inferrable-type-annotationDisallow annotations identical to an inferred scalar typeno-literal-unwrapDisallow immediately unwrapping a known successful result variantno-lone-blockDisallow nested blocks with no scoping effectno-lonely-ifDisallow an if statement as the only statement in an else blockno-multi-assignDisallow chained assignmentno-needless-boolean-branchDisallow conditionals that only produce opposite boolean literalsno-needless-continueDisallow continue where control already proceeds to the same iterationno-needless-matchDisallow matches that reconstruct their scrutinee unchangedno-negated-conditionPrefer positive conditions when both branches are presentno-nested-ternaryDisallow nested ternary expressionsno-redundant-closure-callDisallow parameterless lambdas called where they are definedno-redundant-full-sliceDisallow indexing a slice with the complete rangeno-redundant-labelDisallow labels on transfers to the target selected without a labelno-redundant-match-guardPrefer literal patterns over equivalent equality guardsno-redundant-type-constraintDisallow generic constraints equal to the implicit top typeno-single-binding-matchPrefer direct evaluation over a match with one irrefutable armno-static-only-classDisallow classes containing only static membersno-this-aliasDisallow aliasing the receiver into a bindingno-unit-bindingDisallow binding unit valuesno-unnecessary-array-flat-depthDisallow an explicit default array flattening depthno-unnecessary-slice-endDisallow slice end arguments that cannot shorten the resultno-unnecessary-template-expressionDisallow template expressions without text or conversionno-unnecessary-type-parameterDisallow type parameters that add no relationship or precisionno-used-underscore-bindingDisallow using bindings named as unusedobject-shorthandRequire object property shorthand where equivalentoperator-assignmentRequire compound assignment where equivalentprefer-array-literalPrefer an empty array literal over the canonical Array constructorprefer-code-pointPrefer Unicode code-point operations over UTF-16 code-unit operationsprefer-constRequire const for bindings never reassigned after initializationprefer-elsePrefer else in compact terminal value decisionsprefer-enumeratePrefer indexed iteration over manually counting valuesprefer-equality-over-patternPrefer equality over matching one complete scalar constantprefer-exclusive-rangePrefer exclusive ranges over inclusive ranges offset by oneprefer-expect-diagnosticPrefer diagnostic expectations for local suppressionsprefer-exponentiation-operatorPrefer the exponentiation operator to a well-known power functionprefer-expression-initializationPrefer expression initialization over staged assignmentsprefer-first-lastPrefer first and last accessors over equivalent indexingprefer-flatPrefer Array.flat over spreading nested arrays into concatprefer-for-ofPrefer for-of when a loop only indexes one arrayprefer-for-of-over-for-eachPrefer for-of over sequential forEach callbacksprefer-function-typePrefer function types over single-signature structural typesprefer-implicit-returnPrefer expression bodies for lambdas that only return one valueprefer-is-emptyPrefer isEmpty over comparisons with zero lengthprefer-loop-conditionPrefer loop conditions over leading conditional breaksprefer-map-over-and-thenPrefer Result map methods when chaining only rewraps one variantprefer-matchPrefer match over switch statements and repeated equality chainsprefer-maybePrefer the maybe operator over manual propagationprefer-methodPrefer methods when the first parameter establishes a receiverprefer-negative-indexPrefer negative indices in equivalent at callsprefer-nested-or-patternPrefer nesting or-patterns inside their shared nominal patternprefer-nthPrefer nth over drop followed by firstprefer-nullish-coalescingPrefer nullish coalescing when a nullish value selects a fallbackprefer-optional-chainPrefer optional chaining to equivalent nullish conditionalsprefer-readonlyRequire readonly for private fields never mutated after initializationprefer-regex-literalsPrefer regex literals for constant patterns and flagsprefer-regexp-execPrefer `RegExp.exec` when regular-expression match details are consumedprefer-return-this-typePrefer this as the return type when a method only returns its receiverprefer-self-closing-treePrefer self-closing tree elements without childrenprefer-set-over-unit-mapPrefer sets over maps whose values are unitprefer-slice-patternPrefer slice patterns over indexing after a length guardprefer-string-rawPrefer String.raw when backslashes are escaped only to preserve themselvesprefer-string-replace-allPrefer `String.replaceAll` when every occurrence is replacedprefer-string-slicePrefer `String.slice` over the legacy `String.substring` operationprefer-string-starts-ends-withPrefer `startsWith` and `endsWith` for string boundary testsprefer-templatePrefer template literals for string concatenationprefer-tuple-swapPrefer tuple assignment for swapsprefer-unary-negationPrefer unary negation over multiplying or dividing by -1prefer-weakest-accessPrefer the weakest access form required by a value's usesredundant-forwarding-functionDiscourage functions that only forward their parameters unchangedrequire-accessor-pairDisallow setters without a matching getterrequire-array-join-separatorRequire an explicit array join separatorrequire-diagnostic-reasonRequire reasons for diagnostic suppressionsrequire-is-empty-with-lengthRequire isEmpty alongside a length accessorunnecessary-fallible-conversionSimplify fallible integer conversions that cannot failunnecessary-filter-mapDisallow filterMap callbacks with a definitely defined resultunnecessary-unwrapDisallow unwrap after checked control flow proves the Result variantunused-enumerate-indexDisallow indexed iteration when its index is unusedwhile-let-loopPrefer while-let over an unconditional pattern loopwrong-receiver-conventionRequire receiver forms matching the method's name conventionyodaDisallow literal-first comparisons