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-fp
Advanced tools
eslint-plugin-fp is an ESLint plugin that enforces functional programming best practices. It helps developers write more predictable and maintainable code by avoiding side effects, mutations, and other non-functional programming patterns.
No Mutating Methods
This rule disallows the use of mutating array methods like push, pop, shift, unshift, etc., to encourage the use of immutable operations.
/* eslint fp/no-mutating-methods: 'error' */
const arr = [1, 2, 3];
arr.push(4); // This will trigger an ESLint error
No Mutating Assign
This rule prevents the mutation of object properties, promoting the use of immutable data structures.
/* eslint fp/no-mutation: 'error' */
let obj = { a: 1 };
obj.a = 2; // This will trigger an ESLint error
No Let
This rule disallows the use of `let` and `var` to encourage the use of `const` for variable declarations, promoting immutability.
/* eslint fp/no-let: 'error' */
let x = 1; // This will trigger an ESLint error
No This
This rule disallows the use of `this` to avoid issues related to context and state, encouraging the use of pure functions.
/* eslint fp/no-this: 'error' */
class MyClass {
constructor() {
this.value = 1; // This will trigger an ESLint error
}
}
eslint-plugin-immutable enforces immutability rules in JavaScript code. It is similar to eslint-plugin-fp but focuses more on preventing mutations and ensuring data immutability.
eslint-plugin-functional is another ESLint plugin that enforces functional programming principles. It provides a broader set of rules compared to eslint-plugin-fp, including rules for immutability, pure functions, and function composition.
eslint-plugin-prefer-let enforces the use of `let` over `var` and `const` where appropriate. While it does not focus on functional programming, it helps in writing cleaner and more predictable code by avoiding the pitfalls of `var`.
ESLint rules for functional programming
$ npm install --save-dev eslint eslint-plugin-fp
Configure it in package.json
.
{
"name": "my-awesome-project",
"eslintConfig": {
"env": {
"es6": true
},
"plugins": [
"fp"
],
"rules": {
"fp/no-arguments": "error",
"fp/no-class": "error",
"fp/no-delete": "error",
"fp/no-events": "error",
"fp/no-get-set": "error",
"fp/no-let": "error",
"fp/no-loops": "error",
"fp/no-mutating-assign": "error",
"fp/no-mutating-methods": "error",
"fp/no-mutation": "error",
"fp/no-nil": "error",
"fp/no-proxy": "error",
"fp/no-rest-parameters": "error",
"fp/no-this": "error",
"fp/no-throw": "error",
"fp/no-unused-expression": "error",
"fp/no-valueof-field": "error",
"no-var": "error"
}
}
}
arguments
.class
.delete
.events
module.let
.Object.assign()
with a variable as first argument.null
and undefined
.Proxy
.this
.throw
.valueOf
fields.This plugin exports a recommended
configuration that enforces good practices.
To enable this configuration, use the extends
property in your package.json
.
{
"name": "my-awesome-project",
"eslintConfig": {
"plugins": [
"fp"
],
"extends": "plugin:fp/recommended"
}
}
See ESLint documentation for more information about extending configuration files.
MIT © Jeroen Engels
FAQs
ESLint rules for functional programming
We found that eslint-plugin-fp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.