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-clean-code

v0.2.10

Published

TSLint rules for enforcing Clean Code

Downloads

27,386

Readme

tslint-clean-code Build Status Build status

A set of TSLint rules used to enforce Clean Code practices. Inspired by Clean Code: A Handbook of Agile Software Craftsmanship.

:point_right: Sign up for CodePass, the Quickest Way To Solve Your Coding Errors! :boom:

Installation

npm install tslint-clean-code

Configuration

Configure tslint.json

In your tslint.json file, extend this package. For example:

{
  "extends": [
    "tslint-clean-code"
  ],
  "rules": {
    "newspaper-order": true
  }
}

You can also extend other tslint config packages to combine this plugin with other community custom rules.

Configure your Grunt build task

Add the new rulesDirectory to your tslint task:

grunt.initConfig({
  tslint: {
    options: {
      rulesDirectory: 'node_modules/tslint-clean-code/dist/src',
      configuration: grunt.file.readJSON("tslint.json")
    },
    files: {
      src: ['src/file1.ts', 'src/file2.ts']
    }
  }
})

The tslint.json file does not change format when using this package. Just add our rule definitions to your existing tslint.json file.

Supported Rules

Rule Name | Description | Since :---------- | :------------ | ------------- id-length | Enforces a minimum and/or maximum identifier length convention. | 0.1.0 try-catch-first | Try-catch blocks must be first within the scope. Try-catch blocks are transactions and should leave your program in a consistent state, no matter what happens in the try. | 0.1.0 max-func-args | Limit the number of input arguments for a function. The ideal number of arguments for a function is zero (niladic). | 0.1.0 min-class-cohesion | The more variables a method manipulates the more cohesive that method is to its class. A class in which each variable is used by each method is maximally cohesive. We would like cohesion to be high. When cohesion is high, it means that the methods and variables of the class are co-dependent and hang together as a logical whole. | 0.1.0 newspaper-order | We would like a source file to be like a newspaper article. Detail should increase as we move downward, until at the end we find the lowest level functions and details in the source file. | 0.1.0 no-flag-args | Functions should only do one thing, therefore passing a boolean into a function is a bad practice. The function does one thing if the flag is true and another if the flag is false! | 0.1.0 no-for-each-push | Enforce using Array.prototype.map instead of Array.prototype.forEach and Array.prototype.push. | 0.1.0 no-feature-envy | A method accesses the data of another object more than its own data. | 0.1.8 no-map-without-usage | Ensure results of Array.prototype.map is either assigned to variable or returned | 0.1.0 no-complex-conditionals | Enforce the maximum complexity of conditional expressions. | 0.1.0 prefer-dry-conditionals | Don't-Repeat-Yourself in if statement conditionals, instead use Switch statements. | 0.1.0 no-commented-out-code | Code must not be commented out. | 0.2.0

Development

To develop tslint-clean-code simply clone the repository, install dependencies and run grunt:

git clone [email protected]:Glavin001/tslint-clean-code.git --config core.autocrlf=input --config core.eol=lf
cd tslint-clean-code
npm install
grunt all
grunt create-rule --rule-name=no-something-or-other

Debug code

If command fails because of file access permissions, prefix it with sudo.

npm install -g node-inspector

Then run:

node-debug grunt mochaTest

The node-debug command will load Node Inspector in your default browser (works in Chrome and Opera only).

Set a breakpoint somewhere in your code and resume execution. Your breakpoint should be hit.

Thank you

Thank you to maintainers of tslint-microsoft-contrib, from which this repository was forked. The initial structure was kept and new rules were added, this would not have been possible without Microsoft's awesome work!