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

tslint-ban-snippets

v3.0.9

Published

A custom tslint rule to ban configurable lists of code snippets.

Downloads

283

Readme

:no_entry_sign: tslint-ban-snippets readme

A custom tslint rule to ban configurable lists of code snippets.

examples: "return void reject", "it.only", "debugger".

status - stable

tslint-ban-snippets is stable and in use every day in CI builds and on dev boxes (Linux, Mac, Windows) for at least one major product.

tslint-ban-snippets WILL be maintained, as long as tslint is around. BUT recommend switching to the eslint equivalent, eslint-plugin-ts-ban-snippets.

Build Status Coveralls Size

Dependencies

npm Package NPM Downloads

styled with prettier semantic-release

License: MIT

ko-fi

dependencies

No special dependencies - just TypeScript and of course tslint.

features

  • a custom tslint rule that can detect code snippets that are not desired
  • configurable for multiple code snippets
  • can include/exclude file paths
  • the error message can also be configured

The rule is quite flexible and could potentially avoid having to create multiple custom tslint rules.

custom tslint rule

The custom rule tsl-ban-snippets can be configured with small snippets of code that should NOT be used by developers.

If tslint finds the snippets of code, it will raise an error for that line of code.

In this way, a code base can be kept clean of unwanted coding practices.

note: the rule name

The rule name is tsl-ban-snippets to avoid using the prefix tslint- which was found to be problematic when other tslint libraries are in use.

note: comparison to the standard ban rule

There is a standard tslint rule named ban. However its scope is quite limited - the tsl-ban-snippets rule applies to any statement in a TypeScript file, and so can be configured to detect most unwanted code snippets.

usage

1 Install via npm (or yarn) into your TypeScript project

npm install tslint-ban-snippets

2 Configure tslint to pick up the custom rule

Edit your tslint.json to have an entry "rulesDirectory" that points to tslint-ban-snippets.

Normally this would be like:

{
    "rulesDirectory": "node_modules/tslint-ban-snippets/dist/lib",
    "rules": {
        "tsl-ban-snippets": [
            // custom banned snippets here...
        ]
    }
}

Alternatively, you can store the custom rules in a separate file:

tslint.json:

{
    "extends": ["./tslint.tslint-ban-snippets.json"],
    // ...
}

`tslint.tslint-ban-snippets.json:`

```json
{
    "rulesDirectory": "node_modules/tslint-ban-snippets/dist/lib",
    "rules": {
        "tsl-ban-snippets": [
            // custom banned snippets here...
        ]
    }
}

3 Configure the custom rule tsl-ban-snippets

Now you can configure the custom rule, to ban whatever code snippets you do NOT want developers to use.

examples

Example of how to ban the use of "return void":

    "rules": {
        // other rules here...
        "tsl-ban-snippets": [
            true,
            {
                "banned": [
                    {
                        "snippets": ["return void"]
                    }
                ]
            }
        ]
    }

Example to ban the disabling of tests:

    "rules": {
        "tsl-ban-snippets": [
            true,
            {
                "banned": [
                    {
                        "snippets": ["it.only", "describe.only"],
                        "message": "Do not enable only some tests."
                    },
                    {
                        "snippets": ["it.skip", "describe.skip"],
                        "message": "Do not skip tests."
                    }
                ]
            }
        ]
    }

Example that uses a regular expression, to ban both return void reject and return void resolve:

    "rules": {
        // other rules here...
        "tsl-ban-snippets": [
            true,
            {
                "banned": [
                    {
                        "regexSnippets": ["return void [reject|resolve]"],
                    }
                ]
            }
        ]
    }

Here is another example, with more options.

This example bans return void aswell as return void reject and return void resolve.

    "rules": {
        // other rules here...
        "tsl-ban-snippets": [
            true,
            {
                "banned": [
                    {
                        "snippets": ["return void"],
                        "message": "Please do not return void - instead place the return statement on the following line.",
                        "includePaths": [".ts", ".tsx"],
                        "excludePaths": ["itest"]
                    },
                    {
                        "regexSnippets": ["return void [reject|resolve]"],
                        "message": "Please do not return void - instead place the return statement on the following line.",
                        "includePaths": [".ts", ".tsx"],
                        "excludePaths": []
                    }
                ]
            }
        ]
    }

For more examples of how to configure, please see tslint.json.

For working tests, please see the unit tests.

For a real code example, see the test harness and in particular the config file.

sites

| site | URL | | -------------------- | ------------------------------------------------- | | source code (github) | https://github.com/mrseanryan/tslint-ban-snippets | | github page | https://mrseanryan.github.io/tslint-ban-snippets/ | | npm | https://www.npmjs.com/package/tslint-ban-snippets |

developing code in this repository

see the contributing readme.

origin

This project is based on the excellent seeder project typescript-library-starter.

The project was started to avoid having to repeatedly fix similar coding issues in large TypeScript code bases.

ORIGINAL readme (from the seeder project)

see here

authors

Original work by Sean Ryan - mr.sean.ryan(at gmail.com)

licence = MIT

This project is licensed under the MIT License - see the LICENSE file for details