npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-functional-core

v1.7.1

Published

An Eslint plugin to help enforce functional principles and increase the 'functional core' of your code base.

Downloads

23

Readme

npm version

eslint-plugin-functional-core

A plugin to help enforce functional principles and increase the "functional core" of your code base.

Motivation

The driving motivation behind this ESLint plugin is the concept of "Functional Core, Imperative Shell" where:

  • Functional Core is the central part of your application where core logic resides. It should be as functionally pure as possible and its dependencies should also be functionally pure.
  • Imperative Shell is the outer layer containing impure code, interacting with the outer world e.g. external systems, user inputs, libraries.

By embracing functional principles in your Functional Core, you'll achieve:

  1. Easier-to-reason-about code: Deterministic and side effect-free logic.
  2. Improved testability: Simplified unit tests with minimal mocking due to functional purity.
  3. Increased reliability: Greater predictability in code execution and bugs are easier to reproduce for a known input.

The Imperative Shell on the other hand is where you'll find the "messy" code, where you'll have to deal with side effects, impure functions, and interfacing with other "imperative" code. This will be the likely source of bugs as it is harder to test (usually requiring complicated integration tests) and maintain.

Although the Imperative Shell may introduce challenges, it plays a crucial role in actually delivering value to the external world, where the Functional Core does not affect anything by design.

The goal is to minimize the Imperative Shell while maximizing the Functional Core for an optimal balance between reliability, maintainability, and practical application and this plugin aims to help you achieve that.

Benefits of doing this well are:

  • A smaller surface area to focus on when debugging complex mutation related bugs
  • A smaller surface area to consider when making changes to exposed functionality
  • Having many fast unit tests (for a large Functional Core) and few slow integration tests (for a small Imperative Shell)

Read more about this idea here:

  • https://github.com/kbilsted/Functional-core-imperative-shell/blob/master/README.md
  • https://medium.com/@magnusjt/functional-core-imperative-shell-in-javascript-29bef2353ac2

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-functional-core:

npm install eslint-plugin-functional-core --save-dev

Usage

Add functional-core to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["functional-core"]
}

Either add a config to the extends section of your .eslintrc configuration file, e.g. to add the recommended config do:

{
  "extends": ["plugin:functional-core/recommended"]
}

Or you can manually configure the rules you want to use under the rules section. NOTE Rule options are loose/relaxed by default so you need to explicitly change them if you want to be more strict. See Rules below for a list of available rules and options.

Example:

{
  "rules": {
    "functional-core/purity": ["error", { "allowThrow": false }]
  }
}

Rules

💼 Configurations enabled in.
⚠️ Configurations set to warn in.
✅ Set in the recommended configuration.
🔒 Set in the strict configuration.

| Name   | Description | 💼 | ⚠️ | | :------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------- | :-- | :-- | | purity | This rule warns about aspects of code that may be impure, and offers options to adjust how strict this is | 🔒 | ✅ |

Settings

Settings can be configured in your .eslintrc file under the functional-core key.

purePaths

This setting allows you to specify an array of RegEx patterns to match file/module/dependency paths that are considered "pure" and will trigger rules to check for impure code. The same patterns are used to determine if imports in a pure file are also pure.

By default any file or folder with the ".pure" suffix is considered pure (e.g. src/utils.pure/ or src/utils/common.pure.ts), regardless of the custom configuration, so you can use this to mark files as pure without having to configure anything.

Default: ["\\.pure\\b"]

Example

{
  "settings": {
    "functional-core": {
      "purePaths": [".*"] // All files and imports are considered pure
    }
  }
}

Contributing

Contributions are welcome!

This plugin is still in development so any examples of cases not being handled properly are welcome to accommodate different styles.