1.0.12 • Published 6 years ago

@ngxrb/rules v1.0.12

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

AngularRB rules

npm version GitHub license Travis

AngularRB linter rules library to enforce a consistent code style.

Installation

You can install @ngxrb/rules, and all its dependencies, using npm.

npm install @ngxrb/rules tslint codelyzer tslint-sonarts tslint-eslint-rules tslint-microsoft-contrib tslint-clean-code --save-dev
  • Codelyzer >= 4.3.0: A set of tslint rules for static code analysis of Angular TypeScript projects.
  • ESLint rules for TSLint >= 5.3.0: Improve your TSLint with the missing ESLint rules.
  • SonarTS >= 1.6.0: Static code analyzer for TypeScript detecting bugs and suspicious patterns in your code.
  • tslint-microsoft-contrib >= 5.0.0: A set of TSLint rules used on some Microsoft projects.
  • tslint-clean-code >= 0.2.7: A set of TSLint rules used to enforce Clean Code practices. Inspired by Clean Code: A Handbook of Agile Software Craftsmanship.

Usage

To use these TSLint rules, use configuration inheritance via the extends keyword.

A sample configuration is shown below, where tslint.json lives adjacent to your node_modules folder:

{
  "extends": ["ngxrb-rules"],
  "rules": {
    // override tslint rules here
  }
}

Rules

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

Class and Member design

Function design

  • MUST NOT allow function declarations in nested blocks [doc]
  • Arrow lambdas MUST prefer return as () => x over () => { return x; } [doc]
  • MUST require arrow functions as callbacks [doc]

Vars

  • MUST NOT allow variable declarations in nested blocks [doc]
  • MUST use an empty newline after variable declarations [doc]

Types

  • MUST ensure that the results of typeof are compared against a valid string [doc]

Collections

  • MUST NOT allow sparse arrays [doc]

Conditional structures

  • MUST avoid a duplicate case label [doc]

Error handling

  • MUST NOT allow assigning to the exception in a catch block [doc]
  • MUST enforce error handling in callbacks [doc]

Conditions

  • MUST NOT use constant expressions in conditions [doc]
  • MUST NOT use double-negation boolean casts in a boolean context [doc]
  • MUST NOT allow comparisons where both sides are exactly the same [doc]

Possible errors / Bug Detection

  • MUST NOT allow the use of __proto__ property [doc]
  • MUST NOT allow use of javascript: urls [doc]

Best practices / Code Smell

  • MUST NOT allow unnecessary semicolons [doc]
  • SHOULD avoid code that looks like two expressions but is actually one [doc]

Comments and documentation

  • MUST enforce valid JSDoc comments [doc]

Regular expression

  • SHOULD NOT use control characters in regular expressions [doc]
  • MUST NOT use empty character classes in regular expressions [doc]
  • MUST NOT allow invalid regular expression strings in the RegExp constructor [doc]
  • MUST NOT allow multiple spaces in a regular expression literal [doc]

Imports

  • MUST enforce sorting import declarations within module [doc]

License

The MIT License (MIT)

Copyright (c) 2018 Ricardo Javier Barrios Díaz

1.0.12

6 years ago

1.0.11

6 years ago

1.0.1

6 years ago