fp-ts ESLint rules
A collection of ESLint rules for fp-ts
Assuming ESlint is installed locally in your
project:
``shnpm
npm install --save-dev eslint-plugin-fp-ts
Then enable the plugin in your
eslint.config.mjs file`js
import {defineConfig} from 'eslint/config'
import fptsPlugin from 'eslint-plugin-fp-ts'export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}
}
)
`and enable the rules you want, for example
`js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}, rules: {
"fp-ts/no-lib-imports": "error"
}
}
)
`If you want to enable rules that require type information (see the table below),
then you will also need to add some extra info:
`js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}, languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
}
},
rules: {
"fp-ts/no-discarded-pure-expression": "error",
}
}
)
`If your project is a multi-package monorepo, you can follow the instructions
here.
> ā ļø Note that you will need to make the ESLint config file a .js file, due to
> the need of setting
tsconfigRootDir to __dirname. This is necessary to
> make both editor integrations and the CLI work with the correct path. More
> info here: https://github.com/typescript-eslint/typescript-eslint/issues/251List of supported rules
| Rule | Description | Fixable | Requires type-checking |
| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ | :-----: | :--------------------: |
| fp-ts/no-lib-imports | Disallow imports from
fp-ts/lib/ | š§ | |
| fp-ts/no-pipeable | Disallow imports from the pipeable module | š§ | |
| fp-ts/no-module-imports | Disallow imports from fp-ts modules | š§ | |
| fp-ts/no-redundant-flow | Remove redundant uses of flow | š§ | |
| fp-ts/prefer-traverse | Replace map + sequence with traverse | š” | |
| fp-ts/prefer-chain | Replace map + flatten with chain | š” | |
| fp-ts/prefer-bimap | Replace map + mapLeft with bimap | š” | |
| fp-ts/no-discarded-pure-expression | Disallow expressions returning pure data types (like Task or IO) in statement position | š” | š¦ |$3
š§ = auto-fixable via
--fix (or via the appropriate editor configuration)š” = provides in-editor suggestions that need to be applied manually
Configurations
$3
The plugin defines a
recommended configuration with some reasonable defaults.To use it, add it to the
extends clause of your eslint.config.mjs file:`js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}, extends: ["plugin:fp-ts/recommended"]
}
)
`The rules included in this configuration are:
- fp-ts/no-lib-imports
- fp-ts/no-pipeable
$3
We also provide a
recommended-requiring-type-checking which includes
recommended rules which require type information.This configuration needs to be included _in addition_ to the
recommended one:`js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}, extends: [
"fp-ts/recommended",
"fp-ts/recommended-requiring-type-checking"
]
}
)
`> š You can read more about linting with type information, including
> performance considerations
> here
$3
The plugin also defines an
all configuration which includes every available
rule.To use it, add it to the
extends clause of your eslint.config.mjs file:`js
export default defineConfig(
{
plugins: {
'fp-ts': fptsPlugin,
}, extends: ["fp-ts/all",]
}
)
``