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-fp-ts-strict

v0.1.1

Published

ESLint plugin for typescript to enforce fp-ts functions to avoid the most common javascript problems

Downloads

6,345

Readme

fp-ts-strict


fp-ts can help you write safer code, but nothing stops you (or your teammates!) to write unsafe code. Well, it shouldn't be so!

ESLint plugin used to enforce functional programming types and patterns using fp-ts.

npm install --save-dev eslint-plugin-fp-ts-strict
// .eslintrc.js
module.exports = {
  parser: "@typescript-eslint/parser",
  plugins: ["fp-ts-strict"],
  extends: ["plugin:fp-ts-strict/recommended"],
};

Motivation

fp-ts is awesome. Using functional programming, you can make your code safer and easier to read. Nonetheless, it's always javascript we are talking about! Therefore, nothing stops a distracted version of yourself from writing unsafe code!

ESLint can help! ESLint can look at your code and point out your typing mistakes. Well, it's time to use ESLint in its full power to enforce functional programming with fp-ts.

Welcome fp-ts-strict!

Rules

option-over-undefined

Avoid using undefined in your type unions. Instead of using Type | undefined, use Option<Type>.

/** Example of invalid code 👎 */

export const undefinedOption1 = (): string | undefined => {
  return "abc";
};

export function undefinedOption2(): number | undefined {
  return 1;
}

export function undefinedOption3(): number {
  const a: number | undefined = 10;
  return a ?? 0;
}
/** Example of valid code 👍 */

export const undefinedOption1 = (): Option<string> => {
  return "abc";
};

export function undefinedOption2(): Option<number> {
  return 1;
}

export function undefinedOption3(): number {
  const a: Option<number> = some(10);
  return pipe(
    a,
    getOrElse((): number => 0)
  );
}

option-over-null

Avoid using null in your type unions. Instead of using Type | null, use Option<Type>.

/** Example of invalid code 👎 */

export const nullOption1 = (): string | null => {
  return "abc";
};

export function nullOption2(): number | null {
  return 1;
}

export function nullOption3(): number {
  const a: number | null = 10;
  return a ?? 0;
}
/** Example of valid code 👍 */

export const nullOption1 = (): Option<string> => {
  return "abc";
};

export function nullOption2(): Option<number> {
  return 1;
}

export function nullOption3(): number {
  const a: Option<number> = some(10);
  return pipe(
    a,
    getOrElse((): number => 0)
  );
}

array-head

Accessing the first element of an array using array[0] is unsafe, what if the array is empty?. Use head from fp-ts instead.

/** Example of invalid code 👎 */

const list = [1, 2, 3, 4, 5];
export const headAccess = list[0];
/** Example of valid code 👍 */

const list = [1, 2, 3, 4, 5];
export const headAccess = pipe(list, head);

array-lookup

Accessing an element of an array using array[1] is unsafe, what if the element is undefined?. Use lookup from fp-ts instead.

/** Example of invalid code 👎 */

const list = [1, 2, 3, 4, 5];
export const headAccess = list[1];
/** Example of valid code 👍 */

const list = [1, 2, 3, 4, 5];
export const headAccess = pipe(list, lookup(1));

record-lookup

Accessing an element of a record (map) using record['a'] or record.a is unsafe, what if the element is undefined?. Use lookup from fp-ts instead.

/** Example of invalid code 👎 */

const record: Record<string, number> = { a: 1, b: 2, c: 3 };
export const recordLookup1 = record["ma"];
export const recordLookup2 = record.ma;
/** Example of valid code 👍 */

const record: Record<string, number> = { a: 1, b: 2, c: 3 };
export const recordLookup = pipe(record, lookup("ma"));

💡 More rules?

Of course! If you have any other rule in mind that you would like to propose, feel free to report an issue. Make typescript safe again, together!

📃 Versioning

  • v0.1.0 - 13 October 2021

😀 Support

Currently the best way to support me would be to follow me on my Twitter.

Another option (or Option) would be to buy me a coffee.

👀 License

MIT License, see the LICENSE.md file for details.