Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eslint-functional/eslint-plugin-functional
ESLint rules to disable mutation and promote fp in JavaScript and TypeScript.
https://github.com/eslint-functional/eslint-plugin-functional
eslint eslint-plugin eslint-rules fp functional functional-programming immutability javascript typescript
Last synced: 4 days ago
JSON representation
ESLint rules to disable mutation and promote fp in JavaScript and TypeScript.
- Host: GitHub
- URL: https://github.com/eslint-functional/eslint-plugin-functional
- Owner: eslint-functional
- License: mit
- Created: 2019-07-01T10:08:43.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-01-14T09:38:43.000Z (12 days ago)
- Last Synced: 2025-01-20T11:06:19.619Z (5 days ago)
- Topics: eslint, eslint-plugin, eslint-rules, fp, functional, functional-programming, immutability, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 5.88 MB
- Stars: 875
- Watchers: 10
- Forks: 30
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-ccamel - eslint-functional/eslint-plugin-functional - ESLint rules to disable mutation and promote fp in JavaScript and TypeScript. (TypeScript)
README
![eslint-logo](docs/assets/eslint-functional-logo.png?sanitize=true)
# eslint-plugin-functional
[![npm version](https://img.shields.io/npm/v/eslint-plugin-functional.svg?style=flat)](https://www.npmjs.com/package/eslint-plugin-functional)
[![Release](https://github.com/eslint-functional/eslint-plugin-functional/actions/workflows/release.yml/badge.svg)](https://github.com/eslint-functional/eslint-plugin-functional/actions/workflows/release.yml)
[![Coverage Status](https://codecov.io/gh/eslint-functional/eslint-plugin-functional/branch/main/graph/badge.svg)](https://codecov.io/gh/eslint-functional/eslint-plugin-functional)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat)](https://github.com/semantic-release/semantic-release)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)
[![MIT license](https://img.shields.io/github/license/eslint-functional/eslint-plugin-functional.svg?style=flat)](https://opensource.org/licenses/MIT)
[![GitHub Discussions](https://img.shields.io/github/discussions/eslint-functional/eslint-plugin-functional)](https://github.com/eslint-functional/eslint-plugin-functional/discussions)An [ESLint](http://eslint.org) plugin to disable mutation and promote functional programming in JavaScript and TypeScript.
## Donate
[Any donations would be much appreciated](./DONATIONS.md). π
### Enterprise Users
`eslint-plugin-functional` is available as part of the Tidelift Subscription.
Tidelift is working with the maintainers of `eslint-plugin-functional` and a growing network of open source maintainers
to ensure your open source software supply chain meets enterprise standards now and into the future.
[Learn more.](https://tidelift.com/subscription/pkg/npm-eslint-plugin-functional?utm_source=npm-eslint-plugin-functional&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)## Getting Started
[See our getting started guide](./GETTING_STARTED.md).
## Rulesets
The following rulesets are made available by this plugin.
Presets:
- **Strict** (`configs.strict`)\
Enforce recommended rules designed to strictly enforce functional programming.- **Recommended** (`configs.recommended`)\
Has the same goal as the `strict` preset but a little more lenient, allowing for functional-like coding styles and
nicer integration with non-functional 3rd-party libraries.- **Lite** (`configs.lite`)\
Good if you're new to functional programming or are converting a large codebase.Categorized:
- **Currying** (`configs.currying`)\
JavaScript functions support syntax that is not compatible with curried functions. To enforce currying, this syntax
should be prevented.- **No Exceptions** (`configs.noExceptions`)\
Functional programming style does not use run-time exceptions. Instead expressions produces values to indicate errors.- **No Mutations** (`configs.noMutations`)\
Prevent mutating any data as that's not functional- **No Other Paradigms** (`configs.noOtherParadigms`)\
JavaScript is multi-paradigm, allowing not only functional, but object-oriented as well as other programming styles.
To promote a functional style, prevent the use of other paradigm styles.- **No Statements** (`configs.noStatements`)\
In functional programming everything is an expression that produces a value.
JavaScript has a lot of syntax that is just statements that does not produce a value.
That syntax has to be prevented to promote a functional style.- **Stylistic** (`configs.stylistic`)\
Enforce code styles that can be considered to be more functional.Other:
- **All** (`configs.all`)\
Enables all rules defined in this plugin.- **Off** (`configs.off`)\
Disable all rules defined in this plugin.- **Disable Type Checked** (`configs.disableTypeChecked`)\
Disable all rules that require type information.- **External Vanilla Recommended** (`configs.externalVanillaRecommended`)\
Configures recommended [vanilla ESLint](https://www.npmjs.com/package/eslint) rules.- **External TypeScript Recommended** (`configs.externalTypeScriptRecommended`)\
Configures recommended [TypeScript ESLint](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin) rules.
Enabling this ruleset will also enable the vanilla one.The [below section](#rules) gives details on which rules are enabled by each ruleset.
## Rules
πΌ Configurations enabled in.\
β οΈ Configurations set to warn in.\
π« Configurations disabled in.\
βοΈ Set in the `lite` configuration.\
β Set in the `recommended` configuration.\
π Set in the `strict` configuration.\
π¨ Set in the `stylistic` configuration.\
π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).\
π Requires [type information](https://typescript-eslint.io/linting/typed-linting).\
β Deprecated.### Currying
| Name | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
| :----------------------------------------------------------- | :----------------------------- | :--------------------------- | :-- | :---------------------------- | :-- | :-- | :-- | :-- |
| [functional-parameters](docs/rules/functional-parameters.md) | Enforce functional parameters. | βοΈ β π ![badge-currying][] | | ![badge-disableTypeChecked][] | | | π | |### No Exceptions
| Name | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
| :------------------------------------------------------- | :----------------------------------------------------- | :------------------------------- | :-- | :---- | :-- | :-- | :-- | :-- |
| [no-promise-reject](docs/rules/no-promise-reject.md) | Disallow rejecting promises. | | | | | | | |
| [no-throw-statements](docs/rules/no-throw-statements.md) | Disallow throwing exceptions. | βοΈ β π ![badge-noExceptions][] | | | | | | |
| [no-try-statements](docs/rules/no-try-statements.md) | Disallow try-catch[-finally] and try-finally patterns. | π ![badge-noExceptions][] | | βοΈ β | | | | |### No Mutations
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
| :--------------------------------------------------------------------------- | :-------------------------------------------------------------- | :------------------------------ | :-- | :---------------------------- | :-- | :-- | :-- | :-- |
| [immutable-data](docs/rules/immutable-data.md) | Enforce treating data as immutable. | βοΈ β π ![badge-noMutations][] | | ![badge-disableTypeChecked][] | | | π | |
| [no-let](docs/rules/no-let.md) | Disallow mutable variables. | βοΈ β π ![badge-noMutations][] | | | | | | |
| [prefer-immutable-types](docs/rules/prefer-immutable-types.md) | Require function parameters to be typed as certain immutability | βοΈ β π ![badge-noMutations][] | | ![badge-disableTypeChecked][] | π§ | π‘ | π | |
| [prefer-readonly-type](docs/rules/prefer-readonly-type.md) | Prefer readonly types over mutable types. | | | ![badge-disableTypeChecked][] | π§ | | π | β |
| [type-declaration-immutability](docs/rules/type-declaration-immutability.md) | Enforce the immutability of types based on patterns. | βοΈ β π ![badge-noMutations][] | | ![badge-disableTypeChecked][] | π§ | π‘ | π | |### No Other Paradigms
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
| :--------------------------------------------------------- | :------------------------------------------------------------------------ | :----------------------------------- | :-- | :---------------------------- | :-- | :-- | :-- | :-- |
| [no-class-inheritance](docs/rules/no-class-inheritance.md) | Disallow inheritance in classes. | βοΈ β π ![badge-noOtherParadigms][] | | | | | | |
| [no-classes](docs/rules/no-classes.md) | Disallow classes. | β π ![badge-noOtherParadigms][] | | βοΈ | | | | |
| [no-mixed-types](docs/rules/no-mixed-types.md) | Restrict types so that only members of the same kind are allowed in them. | βοΈ β π ![badge-noOtherParadigms][] | | ![badge-disableTypeChecked][] | | | π | |
| [no-this-expressions](docs/rules/no-this-expressions.md) | Disallow this access. | π ![badge-noOtherParadigms][] | | βοΈ β | | | | |### No Statements
| Name | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
| :------------------------------------------------------------------- | :--------------------------------------------- | :------------------------------- | :-- | :------------------------------- | :-- | :-- | :-- | :-- |
| [no-conditional-statements](docs/rules/no-conditional-statements.md) | Disallow conditional statements. | β π ![badge-noStatements][] | | βοΈ ![badge-disableTypeChecked][] | | | π | |
| [no-expression-statements](docs/rules/no-expression-statements.md) | Disallow expression statements. | β π ![badge-noStatements][] | | βοΈ ![badge-disableTypeChecked][] | | | π | |
| [no-loop-statements](docs/rules/no-loop-statements.md) | Disallow imperative loops. | βοΈ β π ![badge-noStatements][] | | | | | | |
| [no-return-void](docs/rules/no-return-void.md) | Disallow functions that don't return anything. | βοΈ β π ![badge-noStatements][] | | ![badge-disableTypeChecked][] | | | π | |### Stylistic
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
| :--------------------------------------------------------------------- | :--------------------------------------------------------------------- | :-- | :-- | :---------------------------- | :-- | :-- | :-- | :-- |
| [prefer-property-signatures](docs/rules/prefer-property-signatures.md) | Prefer property signatures over method signatures. | π¨ | | ![badge-disableTypeChecked][] | | | π | |
| [prefer-tacit](docs/rules/prefer-tacit.md) | Replaces `x => f(x)` with just `f`. | | π¨ | ![badge-disableTypeChecked][] | | π‘ | π | |
| [readonly-type](docs/rules/readonly-type.md) | Require consistently using either `readonly` keywords or `Readonly` | π¨ | | ![badge-disableTypeChecked][] | π§ | | π | |[badge-currying]: https://img.shields.io/badge/-currying-red.svg
[badge-noExceptions]: https://img.shields.io/badge/-noExceptions-blue.svg
[badge-noMutations]: https://img.shields.io/badge/-noMutations-orange.svg
[badge-noOtherParadigms]: https://img.shields.io/badge/-noOtherParadigms-yellow.svg
[badge-noStatements]: https://img.shields.io/badge/-noStatements-purple.svg
[badge-disableTypeChecked]: https://img.shields.io/badge/-disableTypeChecked-navy.svg## External Recommended Rules
In addition to the above rules, there are a few other rules we recommended.
These rules are what are included in the _external recommended_ rulesets.
### Vanilla Rules
- [no-var](https://eslint.org/docs/rules/no-var)\
Without this rule, it is still possible to create mutable `var` variables.- [no-param-reassign](https://eslint.org/docs/rules/no-param-reassign)\
Don't allow function parameters to be reassigned, they should be treated as constants.- [prefer-const](https://eslint.org/docs/rules/prefer-const)\
This rule provides a helpful fixer when converting from an imperative code style to a functional one.### TypeScript Rules
- [@typescript-eslint/prefer-readonly](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-readonly.mdx)\
This rule is helpful when working with classes.- [@typescript-eslint/switch-exhaustiveness-check](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.mdx)\
Although our [no-conditional-statements](./docs/rules/no-conditional-statements.md) rule also performs this check,
this rule has a fixer that will implement the unimplemented cases which can be useful.## Contributing
[See our contributing guide](./CONTRIBUTING.md).
## Prior work
This project started as a port of [tslint-immutable](https://github.com/jonaskello/tslint-immutable)
which was originally inspired by [eslint-plugin-immutable](https://github.com/jhusain/eslint-plugin-immutable).