Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
eslint-plugin-functional
Advanced tools
ESLint rules to promote functional programming in TypeScript.
eslint-plugin-functional is an ESLint plugin that enforces functional programming best practices. It helps developers write code that is more predictable, easier to test, and less prone to bugs by discouraging side effects, mutable data, and other non-functional programming patterns.
No Mutations
This feature enforces immutability by disallowing the use of `let`, `this`, and `class`. This ensures that variables and data structures remain constant throughout the code.
module.exports = {
rules: {
'functional/no-let': 'error',
'functional/no-this-expression': 'error',
'functional/no-class': 'error'
}
};
No Expressions with Side Effects
This feature prevents the use of expressions that produce side effects, such as assignments and conditionals. This helps in maintaining pure functions that are easier to test and reason about.
module.exports = {
rules: {
'functional/no-expression-statement': 'error',
'functional/no-conditional-statement': 'error'
}
};
No Loops
This feature disallows the use of loop statements like `for`, `while`, and `do-while`. Instead, it encourages the use of higher-order functions like `map`, `filter`, and `reduce` for iteration.
module.exports = {
rules: {
'functional/no-loop-statement': 'error'
}
};
eslint-plugin-immutable is an ESLint plugin that enforces immutability rules in JavaScript code. It is similar to eslint-plugin-functional in that it discourages the use of mutable data structures and promotes the use of immutable patterns. However, it is more focused on immutability rather than a broader range of functional programming principles.
eslint-plugin-fp is an ESLint plugin that enforces functional programming best practices. It is similar to eslint-plugin-functional but has a different set of rules and focuses more on preventing side effects and promoting pure functions. It also includes rules for avoiding certain JavaScript features that are considered non-functional.
eslint-plugin-no-loops is an ESLint plugin that disallows the use of loop statements in JavaScript code. It is similar to the 'No Loops' feature of eslint-plugin-functional but is more specialized, focusing solely on preventing loops and encouraging the use of higher-order functions for iteration.
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 (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.
💼 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. | ☑️ ✅ 🔒 | ![badge-disableTypeChecked][] | 💭 |
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][] | ☑️ ✅ |
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][] | 🔧 | 💡 | 💭 |
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][] | ☑️ ✅ |
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][] | 💭 |
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][] | 🔧 | 💭 |
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.
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 0 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.