Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
eslint-plugin-functional
Advanced tools
Changelog
Readme
An ESLint plugin to disable mutation and promote functional programming in JavaScript and TypeScript.
Any donations would be much appreciated. π
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.
See our getting started guide.
The following rulesets are made available by this plugin.
Presets:
Strict (plugin:functional/strict
)
Enforce recommended rules designed to strictly enforce functional programming.
Recommended (plugin:functional/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 (plugin:functional/lite
)
Good if you're new to functional programming or are converting a large codebase.
Categorized:
Currying (plugin:functional/currying
)
JavaScript functions support syntax that is not compatible with curried functions. To enforce currying, this syntax should be prevented.
No Exceptions (plugin:functional/no-exceptions
)
Functional programming style does not use run-time exceptions. Instead expressions produces values to indicate errors.
No Mutations (plugin:functional/no-mutations
)
Prevent mutating any data as that's not functional
No Other Paradigms (plugin:functional/no-other-paradigms
)
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 (plugin:functional/no-statements
)
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 (plugin:functional/stylistic
)
Enforce code styles that can be considered to be more functional.
Other:
All (plugin:functional/all
)
Enables all rules defined in this plugin.
Off (plugin:functional/off
)
Disable all rules defined in this plugin.
Disable Type Checked (plugin:functional/disable-type-checked
)
Disable all rules that require type information.
External Vanilla Recommended (plugin:functional/external-vanilla-recommended
)
Configures recommended vanilla ESLint rules.
External Typescript Recommended (plugin:functional/external-typescript-recommended
)
Configures recommended TypeScript ESLint rules.
Enabling this ruleset will also enable the vanilla one.
The below section gives details on which rules are enabled by each ruleset.
πΌ 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.
π‘ Manually fixable by editor suggestions.
π Requires type information.
β Deprecated.
Name | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
---|---|---|---|---|---|---|---|---|
functional-parameters | Enforce functional parameters. | βοΈ β π |
Name | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
---|---|---|---|---|---|---|---|---|
no-promise-reject | Disallow rejecting promises. | |||||||
no-throw-statements | Disallow throwing exceptions. | βοΈ β π | ||||||
no-try-statements | Disallow try-catch[-finally] and try-finally patterns. | π | βοΈ β |
NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
---|---|---|---|---|---|---|---|---|
immutable-data | Enforce treating data as immutable. | βοΈ β π | π | |||||
no-let | Disallow mutable variables. | βοΈ β π | ||||||
prefer-immutable-types | Require function parameters to be typed as certain immutability | βοΈ β π | π§ | π‘ | π | |||
prefer-readonly-type | Prefer readonly types over mutable types. | π§ | π | β | ||||
type-declaration-immutability | Enforce the immutability of types based on patterns. | βοΈ β π | π§ | π‘ | π |
NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
---|---|---|---|---|---|---|---|---|
no-classes | Disallow classes. | βοΈ β π | ||||||
no-mixed-types | Restrict types so that only members of the same kind are allowed in them. | βοΈ β π | π | |||||
no-this-expressions | Disallow this access. | π | βοΈ β |
Name | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
---|---|---|---|---|---|---|---|---|
no-conditional-statements | Disallow conditional statements. | β π | βοΈ | π | ||||
no-expression-statements | Disallow expression statements. | β π | βοΈ | π | ||||
no-loop-statements | Disallow imperative loops. | βοΈ β π | ||||||
no-return-void | Disallow functions that don't return anything. | βοΈ β π | π |
NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π« | π§ | π‘ | π | β |
---|---|---|---|---|---|---|---|---|
prefer-property-signatures | Prefer property signatures over method signatures. | π¨ | π | |||||
prefer-tacit | Replaces x => f(x) with just f . | π¨ | π‘ | π | ||||
readonly-type | Require consistently using either readonly keywords or Readonly<T> | π¨ | π§ | π |
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.
no-var
Without this rule, it is still possible to create mutable var
variables.
no-param-reassign
Don't allow function parameters to be reassigned, they should be treated as constants.
prefer-const
This rule provides a helpful fixer when converting from an imperative code style to a functional one.
@typescript-eslint/prefer-readonly
This rule is helpful when working with classes.
@typescript-eslint/switch-exhaustiveness-check
Although our no-conditional-statements rule also performs this check,
this rule has a fixer that will implement the unimplemented cases which can be useful.
This project started as a port of tslint-immutable which was originally inspired by eslint-plugin-immutable.
FAQs
ESLint rules to promote functional programming in TypeScript.
The npm package eslint-plugin-functional receives a total of 111,900 weekly downloads. As such, eslint-plugin-functional popularity was classified as popular.
We found that eslint-plugin-functional demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.