ESLint rules for pragmatic Ramda usage, refactoring and simplification
$ npm install --save-dev eslint eslint-plugin-ramda
Configure it in package.json
.
{
"name": "my-awesome-project",
"eslintConfig": {
"env": {
"es6": true
},
"plugins": [
"ramda"
],
"rules": {
"ramda/always-simplification": "error",
"ramda/any-pass-simplification": "error",
"ramda/both-simplification": "error",
"ramda/complement-simplification": "error",
"ramda/compose-pipe-style": "error",
"ramda/compose-simplification": "error",
"ramda/cond-simplification": "error",
"ramda/either-simplification": "error",
"ramda/eq-by-simplification": "error",
"ramda/filter-simplification": "error",
"ramda/if-else-simplification": "error",
"ramda/map-simplification": "error",
"ramda/merge-simplification": "error",
"ramda/no-redundant-and": "error",
"ramda/no-redundant-not": "error",
"ramda/no-redundant-or": "error",
"ramda/pipe-simplification": "error",
"ramda/prefer-both-either": "error",
"ramda/prefer-complement": "error",
"ramda/prefer-ramda-boolean": "error",
"ramda/prop-satisfies-simplification": "error",
"ramda/reduce-simplification": "error",
"ramda/reject-simplification": "error",
"ramda/set-simplification": "error",
"ramda/unless-simplification": "error",
"ramda/when-simplification": "error"
}
}
}
-
always-simplification
- Detects whenalways
usage can be replaced by a Ramda function -
any-pass-simplification
- Suggests simplifying list of negations inanyPass
by single negation inallPass
-
both-simplification
- Suggests transforming negatedboth
conditions on negatedeither
-
complement-simplification
- Forbids confusingcomplement
, suggesting a better one -
compose-pipe-style
- Enforcescompose
for single line expression andpipe
for multiline -
compose-simplification
- Detects when a function that has the same behavior already exists -
cond-simplification
- Forbids usingcond
whenifElse
,either
orboth
fits -
either-simplification
- Suggests transforming negatedeither
conditions on negatedboth
-
eq-by-simplification
- ForbidseqBy(prop(_))
and suggestseqProps
-
filter-simplification
- Forbids using negatedfilter
and suggestsreject
-
if-else-simplification
- Suggestswhen
andunless
when it is possible to replace -
map-simplification
- Forbidsmap(prop(_))
and suggestspluck
-
merge-simplification
- Forbidsmerge
whenassoc
fits -
no-redundant-and
- Forbidsand
with 2 parameters in favor of&&
-
no-redundant-not
- Forbidsnot
with 1 parameter in favor of!
-
no-redundant-or
- Forbidsor
with 2 parameters in favor of||
-
pipe-simplification
- Detects when a function that has the same behavior already exists -
prefer-both-either
- Enforces usingboth
/either
instead ofallPass
/anyPass
with a list of only two predicates -
prefer-complement
- Enforces usingcomplement
instead of compositions usingnot
-
prefer-ramda-boolean
- Enforces usingR.T
andR.F
instead of explicit functions -
prop-satisfies-simplification
- Detects when can replacepropSatisfies
by more simple functions -
reduce-simplification
- Detects when can replacereduce
bysum
orproduct
-
reject-simplification
- Forbids using negatedreject
and suggestsfilter
-
set-simplification
- Forbids usingset
withlensProp
in favor ofassoc
-
unless-simplification
- Forbids using negatedunless
and suggestswhen
-
when-simplification
- Forbids using negatedwhen
and suggestsunless
This plugin exports a recommended
configuration that enforces good practices.
To enable this configuration, use the extends
property in your package.json
.
{
"name": "my-awesome-project",
"eslintConfig": {
"plugins": [
"ramda"
],
"extends": "plugin:ramda/recommended"
}
}
See ESLint documentation for more information about extending configuration files.
MIT © @haskellcamargo and @lo1tuma