eslint-plugin-scats
v0.5.9
Published
ESLint rules for safe scats usage
Maintainers
Readme
eslint-plugin-scats
ESLint plugin with rules for safer and more idiomatic usage of scats.
Installation
npm install --save-dev eslint eslint-plugin-scatsIf you lint TypeScript, also install:
npm install --save-dev @typescript-eslint/parserConfigs
Legacy config
Recommended:
module.exports = {
plugins: ['scats'],
extends: ['plugin:scats/recommended'],
};Strict:
module.exports = {
plugins: ['scats'],
extends: ['plugin:scats/strict'],
};Flat config
const scats = require('eslint-plugin-scats');
module.exports = [
{
plugins: {
scats,
},
rules: {
...scats.configs.recommended.rules,
},
},
];For strict mode use scats.configs.strict.rules.
Rules
Recommended
scats/to-array-terminal: requires.toArrayto be terminal in scats call chainsscats/no-array-option-fallback: disallowsOption#getOrElseValue([]),Option#getOrElse(() => []),Option#getOrElseValue(Nil.toArray), and similar array fallbacks; prefer keeping values as scats collections and usingNilor an appropriate empty collectionscats/no-collection-emptiness-comparison: prefers.isEmptyand.nonEmptyover comparing scats collection.lengthor.sizeto zeroscats/no-collection-get-zero: disallowsCollection#get(0); preferheadorheadOptionto make first-element access explicitscats/no-explicit-empty: disallows creating obviously empty scats collections via constructors/factories whenNilor*.emptyshould be usedscats/no-option-nullish-fallback: disallowsoption(null)/option(undefined)in favor ofnone, disallowsOption#getOrElse(() => null),Option#getOrElseValue(null), the correspondingundefinedfallbacks, and redundant patterns such asoption(existingOption.orNull)oroption(existingOption.orNull).orElse(() => option(fallback.orNull))when the originalOptionshould be used directlyscats/no-option-foreach-assignment: disallowslet result = nonefollowed by mutation insideoption(...).foreach(...); prefer deriving the value withmaporflatMapscats/prefer-get-or-else-value: prefersOption#getOrElseValue(...)overOption#getOrElse(() => ...)when the callback returns an explicit constant such as a literal or static template string, and prefersOption#orElseValue(...)overOption#orElse(() => someOption)when the fallback is already anOptionscats/no-useless-to-array-iteration: disallowsfor...of (... of collection.toArray)for confirmed scats collections and auto-fixes to iterate the scats collection directly
Strict
- includes all
recommendedrules scats/no-array-construction: disallows storing JavaScript arrays in local variables or class fields; inline arrays and object property assignments for external APIs remain allowedscats/no-array-mutation: disallows mutating JavaScript arrays directly via mutating methods, index writes, orlength = ...; this rule uses TypeScript type information to avoid false positives on non-array objects with methods likepushscats/no-array-typed-variable: disallows local variables and class fields typed asArray<T>,ReadonlyArray<T>, orT[]; this catches cases where.toArrayresults are stored explicitly as JavaScript arrays. For DTOs or external contracts, annotate the class with@scatsAllowArrayTypesscats/no-nullish-syntax: disallows?.and??; prefer explicitOptionflows such asoption(x).flatMap(...)andoption(x).getOrElseValue(...)
Development
npm test