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

@hokla/eslint-plugin-bug-shield

v0.6.1

Published

Kill your bugs for good accross all projects with custom ESLint rules and configurations

Downloads

5,891

Readme

Bug Shield (ESLint plugin)

A team can build its own shield to kill bugs for good

Shield your project :

Install

npm install @hokla/eslint-plugin-bug-shield --save-dev

Choose the configs made for your project

In your .eslintrc.json file :

{
  "extends": [
    // [...],
    "plugin:@hokla/bug-shield/recommended",
    "plugin:@hokla/bug-shield/react"
  ],
  // In case you want to opt-out from specific rules:
  "rules": {
    "@hokla/bug-shield/react-query-specify-typing": "off" // "off" | "warn"
  }
}

Kill bugs across many projects by crafting the shield :

Ensure a shield does not already exist in the open-source world

Generate a new rule

yarn rule:generate <your-rule-name>

Write unit tests

Implement the rule

  • Find a good AST selector :
  • Debug the test in live to check the nature of the selected node:
    • In your rule implementation, set a large AST node selector (like "VariableDeclarator")
    • Add a break point inside your rule
    • Run the VSCode launch config "Tests Debugger" (optionnaly, modify the launch command by adding a file selector)
  • Implement the rule
    • Get inspiration from other existing rules in this plugin
    • https://typescript-eslint.io/developers/custom-rules

Test your rule on the playground

  • Build yarn build
  • Restart your eslint server
  • Paste some wrong code in ./src/playground.tsx
  • Assess that the working behavior

Generate the rule documentation

  • Run yarn create:eslint-docs if you just created the rule, otherwise run yarn update:eslint-docs

Ask for a review !

Let the world know the shield is tougher !

  • Let the world know they can improve their protection by running yarn upgrade @hokla/eslint-plugin-bug-shield or npm update @hokla/eslint-plugin-bug-shield.

Configs

Create a new config

[TO BE IMPROVED]

  • Create a [CONFIG_NAME].config.ts file in the config folder
  • In this file, copy the following block
import {
  RuleListener,
  RuleModule,
} from "@typescript-eslint/utils/dist/ts-eslint";
import { Config, PLUGIN_NAME, getConfigCustomRules } from "../utils/config";

export const CONFIG_NAME = ...; // Use the same config name as your file name

export const getConfig: CustomConfig<typeof CONFIG_NAME> = (allRules) => {
  return {
    [CONFIG_NAME]: {
      plugins: [PLUGIN_NAME],
      rules: { ...getConfigCustomRules(CONFIG_NAME, allRules) },
    },
  };
};
  • Modify the config as you please
  • Add your config in .eslint-doc-generator.js
  • Build yarn build
  • Generate the documentation with the new config : yarn update:eslint-docs

Rules

💼 Configurations enabled in.
⚠️ Configurations set to warn in.
🦅 Set in the nestjs configuration.
🌐 Set in the react configuration.
⚛️ Set in the react-native configuration.
☑️ Set in the recommended configuration.
🔄 Set in the redux configuration.
📦 Set in the typeorm configuration.
💡 Manually fixable by editor suggestions.

| Name                                             | Description | 💼 | ⚠️ | 💡 | | :----------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---- | :- | :- | | forbid-lowercase-jsx-tags | To be used in a React Native project: this rule forbids JSX tags that don't begin with a capital letter | ⚛️ | | | | forbid-nestjs-cron-jobs | Don't use NestJS cron jobs, as they can entail performance problems for your server, as well as concurrency issues (your job might run several times in parallel). Instead, define a CLI command to run your job in your NestJS project (for example with nest-commander) and call it from a cron job defined at the infrastructure level (e.g. in your Kubernetes cluster, or on the platform that hosts your server: Scalingo, Vercel…). | 🦅 | | | | luxon-force-zone-in-datetime | force timezone option in DateTime object instantiation | | ☑️ | | | mandatory-attributes-for-svg-elements | Enforces the declaration of properties width, height for svg elements to prevent non-desired display | 🌐 ⚛️ | | | | max-params-but-better | Enforce a maximum number of parameters in function definitions | | | | | mutation-decorator-return-type-mismatch | Parameter of Mutation Decorator should match the method's return type | ☑️ | | | | no-async-in-foreach | Array.prototype.forEach is not designed for asynchronous code | ☑️ | | | | no-key-or-ref-prop | This rule forbids using props named key or ref in React function components, as they are reserved words and will not act as intended | 🌐 | | | | no-useless-expression-statement | A statement that only calls a variable does nothing. Usually, the developer meant to call a function but forgot the parentheses. | ☑️ | | | | no-value-export-in-declaration-file | This rule forbids exporting values from TypeScript declaration files (ending in ".d.ts"), which can lead to bugs since these files are dropped during transpilation. | ☑️ | | | | property-decorator-type-mismatch | Parameter of Type Decorator should match the property type | ☑️ | | | | react-hook-form-specify-typing | Type parameters should always be specified when calling useForm and useFormContext from react-hook-form | | 🌐 | | | react-query-specify-typing | Type parameters should always be specified when calling useQuery and useMutation from react-query | | 🌐 | | | react-routes-must-be-wrapped-in-router | enforce encapsulation of <...Routes> in <...Router> provider and explicit naming of components returning <...Routes> element | 🌐 | | | | redux-saga-no-sequential-actions | forbid multiple sequential action calls in redux dispatcher | | 🔄 | | | typeorm-enforce-column-type | The SQL column type in a TypeORM entity column must be specified to ensure the control of types in the database match your needs. | 📦 | | 💡 | | typeorm-enforce-repository-generic-method-typing | enforce calls to repository generic methods (save, softRemove and recover) without type specification | | 📦 | | | typeorm-query-runner-release | Any statement calling a queryRunner should be followed by a try/catch/finally block that ensures that the connection pool is released in any case by calling queryRunner.release(). | | 📦 | |