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

@productboard/tslint-pb

v4.1.2

Published

These are highly experimental rules we are trying to use in our daily life to help maintain code more effectively. Because the rules are tied to our codebase, it will probably be very difficult to use them in your project. However, you can definitely take

Downloads

906

Readme

Productboard's TSlint Rules

These are highly experimental rules we are trying to use in our daily life to help maintain code more effectively. Because the rules are tied to our codebase, it will probably be very difficult to use them in your project. However, you can definitely take a look! 💪

Rules

💡 All the rules consume reference: string configuration for custom message

check-unused-flux-dependencies

This rule checks if our connect (Flux) or selector implementation has all required dependencies, or if there is some dependency unused. If you are wondering, how this works in real life just ping us – we are hiring. 🤓

Configuration

{
  "rules": {
    "check-unused-flux-dependencies": [
      true,
      {
        "reference": "Optional text to explain the error"
      }
    ]
  }
}

Example

import { show, hide } from 'selectors/some';

export default compose(connect([show], () => ({
  a: show(),
  b: hide(),
     ~~~~    [You forgot to listen for the "hide" dependency!]
})))(component);

import-group-order

💡 This rule has fixer

This rule needs configuration for proper usage. Basically, you are able to set convention on how to group and sort imports based on the naming convention of imports. Check it out tests for the real-case usage.

Configuration

{
  "rules": {
    "import-group-order": [
      true,
      {
        "convention": [
          "react",
          "node_modules",
          "libs",
          null,
          "actions",
          "stores",
          "selectors",
          null,
          "components",
          null,
          "constants",
          null,
          "styles",
          null,
          "undefined"
        ],
        "recognizer": {
          "react": "^react$",
          "node_modules": "^[^/]*$",
          "libs": "libs/.*",
          "actions": { "regex": "actions?", "flags": "i" },
          "stores": { "regex": "stores?", "flags": "i" },
          "selectors": { "regex": "selectors?", "flags": "i" },
          "components": ["components?/", ".*\\.react$"],
          "constants": "constants?.*",
          "styles": ".*\\.styles$"
        },
        "reference": "Optional text to explain the error"
      }
    ]
  }
}

Example

import a from "libs/flux/r";
import { b } from "libs/flux/r";
import { c, d, f, g } from "modules/views/libs/v";

import { h } from "stores/u";

import { i } from "constants/b";
import * as j from "constants/b";
import { k, l } from "constants/b";
import { m } from "constants/m";
import { n } from "constants/p";
import { o } from "modules/views/constants/v";

sort-flux-dependencies

This rule checks if all connect (Flux) or selector dependencies are sorted alphabetically.

Configuration

{
  "rules": {
    "sort-flux-dependencies": [
      true,
      {
        "maxLineLength": "For formatting purposes",
        "reference": "Optional text to explain the error"
      }
    ]
  }
}

Example

connect(
  [
    AlonglonglongStore,
    getLongLongLongA,
    ~~~~~~~~~~~~~~~~  [Dependency array is not sorted correctly!]
    BlonglonglongStore,
    getLongLongLongB,
    getLongLongLongC,
  ],
  () => {},
)

flux-action-dipatch

This rule checks if all AppDispatcher.handleViewAction calls are typed.

Configuration

{
  "rules": {
    "flux-action-dispatch": true
  }
}

Example

AppDispatcher.handleViewAction({
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  type: 'SIMPLE_ACTION',
~~~~~~~~~~~~~~~~~~~~~~~~
  value: 123,
~~~~~~~~~~~~~
});
~~ [handleViewAction must be typed or called with action object containing "type" property only.]

selectors-format

To enforce some rules to our selectors.

  1. Dependency array must be defined as array literal. It's better practice to have the list of dependencies inlined rather than in some variable outside of selector definition.

  2. Dependency array must contain at least one dependency. Otherwise it's probably misused selector and developer should use plain (possibly memoized) function.

  3. Function in selector must be defined as arrow literal. First for readability we want the function to be inlined and not defined outside of selector definition. Also, we don't wanna use function definition, to avoid possible this abuse.

  4. Default/optional arguments in selector function are forbidden. Unfortunately, JavaScript doesn't play well with default/optional arguments when using memoization on dynamic number of arguments. Therefore we have to disable it to prevent nasty bugs.

    This is only forbidden for the default select with auto-memoization.

  5. All arguments in selector function must be typed. Unfortunately if you skip types on arguments, it just uses implicit any (probably because of generics used in select definition). It's potentially error-prone, so it's good idea to enforce it.

Configuration

{
  "rules": {
    "selectors-format": [
      true,
      {
        "importsPaths": {
          "select": ["libs/flux", "libs/flux/select"]
        },
        "reference": "Optional text to explain the error"
      }
    ]
  }
}

Example

select(
  FLUX_DEPENDENCIES,
  ~~~~~~~~~~~~~~~~~  [Dependencies must be defined as array literal.]
  () => {},
);

select(
  [Store],
  func,
  ~~~~  [Function must be defined as arrow function literal.]
);

select(
  [Store],
  (a: number = 10) => false,
   ~~~~~~~~~~~~~~            [Default arguments are forbidden.]
);

select(
  [Store],
  (a?: number) => false,
   ~~~~~~~~~~                [Optional arguments are forbidden.]
);

select(
  [Store],
  (abc, xyz) => false,
   ~~~             [All arguments must be typed.]
        ~~~        [All arguments must be typed.]
);

correct-react-import

Ensure that React is consistently imported without asterisk import.

Configuration

{
  "rules": {
    "correct-react-import": true
  }
}

Example

import * as React from 'react';
       ~~~~~~~~~~               [Don't import React with asterisk, use `import React from 'react';`]
import React from 'react';

Install

yarn add -D @productboard/tslint-pb

tslint.json

{
  "extends": ["@productboard/tslint-pb"],
  "rules": {}
}

Contribution

There are test provided, just run yarn run test. For quick prototyping use http://astexplorer.net – it's a great tool! Any contribution welcomed! 🙏

License

MIT