Skip to content

ESLint rules to disable mutation and promote fp in JavaScript and TypeScript.

License

Notifications You must be signed in to change notification settings

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 (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 rules.

  • External TypeScript Recommended (configs.externalTypeScriptRecommended)
    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 badge-disableTypeChecked πŸ’­

No Exceptions

Name Description πŸ’Ό ⚠️ 🚫 πŸ”§ πŸ’‘ πŸ’­ ❌
no-promise-reject Disallow rejecting promises.
no-throw-statements Disallow throwing exceptions. β˜‘οΈ βœ… πŸ”’ badge-noExceptions
no-try-statements Disallow try-catch[-finally] and try-finally patterns. πŸ”’ badge-noExceptions β˜‘οΈ βœ…

No Mutations

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ 🚫 πŸ”§ πŸ’‘ πŸ’­ ❌
immutable-data Enforce treating data as immutable. β˜‘οΈ βœ… πŸ”’ badge-noMutations badge-disableTypeChecked πŸ’­
no-let Disallow mutable variables. β˜‘οΈ βœ… πŸ”’ badge-noMutations
prefer-immutable-types Require function parameters to be typed as certain immutability β˜‘οΈ βœ… πŸ”’ badge-noMutations badge-disableTypeChecked πŸ”§ πŸ’‘ πŸ’­
prefer-readonly-type Prefer readonly types over mutable types. badge-disableTypeChecked πŸ”§ πŸ’­ ❌
type-declaration-immutability Enforce the immutability of types based on patterns. β˜‘οΈ βœ… πŸ”’ badge-noMutations badge-disableTypeChecked πŸ”§ πŸ’‘ πŸ’­

No Other Paradigms

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ 🚫 πŸ”§ πŸ’‘ πŸ’­ ❌
no-class-inheritance Disallow inheritance in classes. β˜‘οΈ βœ… πŸ”’ badge-noOtherParadigms
no-classes Disallow classes. βœ… πŸ”’ badge-noOtherParadigms β˜‘οΈ
no-mixed-types Restrict types so that only members of the same kind are allowed in them. β˜‘οΈ βœ… πŸ”’ badge-noOtherParadigms badge-disableTypeChecked πŸ’­
no-this-expressions Disallow this access. πŸ”’ badge-noOtherParadigms β˜‘οΈ βœ…

No Statements

Name Description πŸ’Ό ⚠️ 🚫 πŸ”§ πŸ’‘ πŸ’­ ❌
no-conditional-statements Disallow conditional statements. βœ… πŸ”’ badge-noStatements β˜‘οΈ badge-disableTypeChecked πŸ’­
no-expression-statements Disallow expression statements. βœ… πŸ”’ badge-noStatements β˜‘οΈ badge-disableTypeChecked πŸ’­
no-loop-statements Disallow imperative loops. β˜‘οΈ βœ… πŸ”’ badge-noStatements
no-return-void Disallow functions that don't return anything. β˜‘οΈ βœ… πŸ”’ badge-noStatements badge-disableTypeChecked πŸ’­

Stylistic

NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  Description πŸ’Ό ⚠️ 🚫 πŸ”§ πŸ’‘ πŸ’­ ❌
prefer-property-signatures Prefer property signatures over method signatures. 🎨 badge-disableTypeChecked πŸ’­
prefer-tacit Replaces x => f(x) with just f. 🎨 badge-disableTypeChecked πŸ’‘ πŸ’­
readonly-type Require consistently using either readonly keywords or Readonly<T> 🎨 badge-disableTypeChecked πŸ”§ πŸ’­

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.