New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tslint-clean-code

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tslint-clean-code

TSLint rules for enforcing Clean Code

  • 0.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.9K
increased by69.7%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Version 0.1.3 (In-Development)

The Latest Development Version is available online. To use the nightly build set your npm version to git://github.com/Glavin001/tslint-clean-code.git#releases

Installation

npm install tslint-clean-code

Configuration

Configure your Grunt build task

Add the new rulesDirectory to your tslint task:

grunt.initConfig({
  tslint: {
    options: {
      rulesDirectory: 'node_modules/tslint-clean-code',
      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.

Which Rules Should I Turn On?

There certainly are a lot of options! Here are some links to get you started.

  • Easiest Option - Our recommended ruleset is here: recommended_ruleset.js. You can also easily extend the ruleset by adding "extends": "tslint-clean-code" to your configuration. Please note, the default rules require the --type-check and --project TSLint options. Also, please note that adding a rule to the recommended ruleset is considered backwards compatible. If you reply on version ranges in your dependencies then you may find that new rules being added to the product create violations and fail your build.
  • A nice blog post on the MSDN secure development blog can be found here: Automating Secure Development Lifecycle Checks in TypeScript with TSLint
  • A wiki briefly describing the SDL and related rules is here: TSLint and the Microsoft Security Development Lifecycle
  • And our configuration file with all options is available here: tslint.json

Supported Rules

Rule NameDescriptionSince
id-lengthEnforces a minimum and/or maximum identifier length convention.0.1.0
try-catch-firstTry-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-argsLimit the number of input arguments for a function. The ideal number of arguments for a function is zero (niladic).0.1.0
min-class-cohesionThe 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-orderWe 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-argsFunctions 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-pushEnforce using Array.map instead of Array.forEach and Array.push.0.1.0
no-map-without-usageEnsure results of Array.map is either assigned to variable or returned0.1.0
no-complex-conditionalsEnforce the maximum complexity of conditional expressions.0.1.0
prefer-dry-conditionalsDon't-Repeat-Yourself in if statement conditionals, instead use Switch statements.0.1.0

Development

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

git clone git@github.com: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.

Creating a new Release

Refer to the Releases Wiki Page

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

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!

Keywords

FAQs

Package last updated on 21 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc