Skip to content

eslint-functional/eslint-plugin-functional

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

eslint-logo

eslint-plugin-functional

npm version Release Coverage Status semantic-release code style: prettier MIT license GitHub Discussions

An ESLint plugin to disable mutation and promote functional programming in JavaScript and TypeScript.

Donate

Any donations would be much appreciated. ๐Ÿ˜„

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.

Getting Started

See our getting started guide.

Rulesets

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.

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.
๐Ÿ’ก Manually fixable by editor suggestions.
๐Ÿ’ญ Requires type information.
โŒ Deprecated.

Currying

Name Description ๐Ÿ’ผ โš ๏ธ ๐Ÿšซ ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ โŒ
functional-parameters Enforce functional parameters. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-currying

No Exceptions

Name Description ๐Ÿ’ผ โš ๏ธ ๐Ÿšซ ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ โŒ
no-promise-reject Disallow rejecting promises.
no-throw-statements Disallow throwing exceptions. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-exceptions
no-try-statements Disallow try-catch[-finally] and try-finally patterns. ๐Ÿ”’ badge-no-exceptions โ˜‘๏ธ โœ…

No Mutations

Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  Description ๐Ÿ’ผ โš ๏ธ ๐Ÿšซ ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ โŒ
immutable-data Enforce treating data as immutable. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-mutations ๐Ÿ’ญ
no-let Disallow mutable variables. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-mutations
prefer-immutable-types Require function parameters to be typed as certain immutability โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-mutations ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ
prefer-readonly-type Prefer readonly types over mutable types. ๐Ÿ”ง ๐Ÿ’ญ โŒ
type-declaration-immutability Enforce the immutability of types based on patterns. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-mutations ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ

No Other Paradigms

Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  Description ๐Ÿ’ผ โš ๏ธ ๐Ÿšซ ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ โŒ
no-classes Disallow classes. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-other-paradigms
no-mixed-types Restrict types so that only members of the same kind are allowed in them. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-other-paradigms ๐Ÿ’ญ
no-this-expressions Disallow this access. ๐Ÿ”’ badge-no-other-paradigms โ˜‘๏ธ โœ…

No Statements

Name Description ๐Ÿ’ผ โš ๏ธ ๐Ÿšซ ๐Ÿ”ง ๐Ÿ’ก ๐Ÿ’ญ โŒ
no-conditional-statements Disallow conditional statements. โœ… ๐Ÿ”’ badge-no-statements โ˜‘๏ธ ๐Ÿ’ญ
no-expression-statements Disallow expression statements. โœ… ๐Ÿ”’ badge-no-statements โ˜‘๏ธ ๐Ÿ’ญ
no-loop-statements Disallow imperative loops. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-statements
no-return-void Disallow functions that don't return anything. โ˜‘๏ธ โœ… ๐Ÿ”’ badge-no-statements ๐Ÿ’ญ

Stylistic

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> ๐ŸŽจ ๐Ÿ”ง ๐Ÿ’ญ

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
    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 Rules

Contributing

See our contributing guide.

Prior work

This project started as a port of tslint-immutable which was originally inspired by eslint-plugin-immutable.