Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

tslint-microsoft-contrib

> 编程语言
Open source

A set of TSLint rules used on some Microsoft projects.

699 stars0 likes2 views
WebsiteGitHub

About

A set of TSLint rules used on some Microsoft projects.

tslint-microsoft-contrib

A set of TSLint rules used on some Microsoft projects.

Notice

This project is in read-only and archive mode.

Installation

bash
npm install tslint-microsoft-contrib --save-dev

TSLint and corresponding tslint-microsoft-contrib version

TSLint version tslint-microsoft-contrib version
>= 5.x 5.x and 6.x (supporting TypeScript 2.3.x, >=2.4, 3.x)
>= 4.x 4.x (supporting TypeScript 2.1.x)
>= 3.2.x 2.x
3.1.x unsupported
3.0.x unsupported
2.x 1.x

Configuration

Add "node_modules/tslint-microsoft-contrib" under your "rulesDirectory" configuration to inform TSLint it should look under this package for additional rules in your tslint.json:

json
{
    "rulesDirectory": ["node_modules/tslint-microsoft-contrib"],
    "rules": {
        // ...
    }
}

Which Rules Should I Turn On?

There certainly are a lot of options!

If you extend from one of the following configurations, rulesDirectory will have node_modules/tslint-microsoft-contrib included for you.

Please note, some of the default ruleset rules require the --project TSLint option.

Recommended

To start, you can enable our stable "recommended" defaults that come with tslint-microsoft-contrib (recommended.json) by adding "tslint-microsoft-contrib/recommended" under "extends" in your tslint.json:

json
{
    "extends": ["tslint-microsoft-contrib/recommended"]
    // ...
}

These rules will not be added to in minor or patch releases, but will be in major releases.

Latest

To run with the latest and greatest rules (latest.json), extend from tslint-microsoft-contrib/latest:

json
{
    "extends": ["tslint-microsoft-contrib/latest"]
    // ...
}

These rules will not be added to in patch releases, but will be in minor releases.

Legacy

The old "recommended" ruleset that ships by extending tslint-microsoft-contrib itself contains a list of rules that includes core TSLint rules.

To start, you can enable our recommended defaults (recommended.json) by adding just "tslint-microsoft-contrib" under "extends" in your tslint.json:

json
{
    "extends": ["tslint-microsoft-contrib"]
    // ...
}

This ruleset is considered legacy; it is generally preferable to extend from the 'recommended' or 'latest' rulesets. We recommend you instead explicitly include tslint:recommended, tslint:latest, or tslint:all in your tslint.json rather than enable core rules through this configuration.

In the next major version of TSLint, this will instead be an alias for "tslint-microsoft-contrib/recommended".

Overriding Configurations

You can disable rules you don't find useful.

If you rely on version ranges in your dependencies then you may find that new rules being added to the product create violations and fail your build. We recommend you specify exact versions of lint libraries, including tslint-microsoft-contrib, in your package.json.

Supported Rules

Rule Name
Description
Since




  
    chai-prefer-contains-to-index-of
  
  
    Avoid Chai assertions that invoke indexOf and compare for a -1 result.
    It is better to use the chai .contain() assertion API instead because the failure message will be clearer if the test fails.
  
  2.0.10




  
    chai-vague-errors
  
  
    Avoid Chai assertions that result in vague errors.
    For example, asserting expect(something).to.be.true will result in the failure message "Expected true received false".
    This is a vague error message that does not reveal the underlying problem.
    It is especially vague in TypeScript because stack trace line numbers often do not match the source code.
    A better pattern to follow is the xUnit Patterns Assertion Message pattern.
    The previous code sample could be better written as expect(something).to.equal(true, 'expected something to have occurred');
  
  1.0




  
    detect-child-process
  
  
    Detects usages of child_process and especially child_process.exec() with a non-literal first argument.
    It is dangerous to pass a string constructed at runtime as the first argument to the child_process.exec().
    child_process.exec(cmd) runs cmd as a shell command which could allow an attacker to execute malicious code injected into cmd.
    Instead of child_process.exec(cmd) you should use child_process.spawn(cmd) or specify the command as a literal, e.g. child_process.exec('ls').
  
  6.2.0-beta




  
    export-name
  
  
    The name of the exported module must match the filename of the source file.
    This is case-insensitive by default but ignores file extension.
    It can be configured to be case-insensitive or to allow names matching a regex.
    For example, to allow names that differ only in case and an exported name like myChartOptions, then configure the rule like this: "export-name": [true, { "ignore-case": true, "allow": ["myChartOptions"] }].
    You can also just give a list of allowed names, like "export-name": [true, "myChartOptions"].
  
  0.0.3




  
    function-name
  
  
    Applies a naming convention to function names and method names.
    You can configure the naming convention by passing parameters.
    Please note, the private-method-regex does take precedence over the static-method-regex, so a private static method must match the private-method-regex.
    The default values are:
    
      [ true, {
        "method-regex": "^[a-z][\\w\\d]+$",
        "private-method-regex": "^[a-z][\\w\\d]+$",
        "protected-method-regex": "^[a-z][\\w\\d]+$",
        "static-method-regex": "^[A-Z_\\d]+$",
        "function-regex": "^[a-z][\\w\\d]+$"
      } ]
    
    This rule has some overlap with the [tslint variable-name rule](https://palantir.github.io/tslint/rules/variable-name/); however, the rule here is more configurable.
  
  2.0.7, 2.0.14




  
    import-name
  
  
    The name of the imported module must match the name of the thing being imported. For special characters (-, ., _) remove them and make the following character uppercase.
    For example, it is valid to name imported modules the same as the module name: import Service = require('x/y/z/Service') and import Service from 'x/y/z/Service'.
    But it is invalid to change the name being imported, such as: import MyCoolService = require('x/y/z/Service') and import MyCoolService from 'x/y/z/Service'.
    When containing special characters such as import $$ from 'my-awesome_library'; the corresponding configuration would look like 'import-name': [true, { 'myAwesomeLibrary': '$$' }].
    Since version 2.0.9 it is possible to configure this rule with a list of exceptions.
    For example, to allow underscore to be imported as _, add this configuration: 'import-name': [ true, { 'underscore': '_' }]
  
  2.0.5




  
    informative-docs
  
  
    Enforces that comments do more than just reiterate names of objects.
    Either be informative with comments or don't include a comment.
    You can override the default list of "useless" words ignored by the comment checker like "informative-docs": [true, { "useless-words": ["a", "an", "the", "text" ] } ].
    You can indicate words as synonyms (aliases) of each other like "informative-docs": [true, { "aliases": { text: ["emoji", "smiley"] } ].
  
  6.0.0-beta




  
    insecure-random
  
  
    Do not use insecure sources for random bytes.
    Use a secure random number generator instead.
    Bans all uses of Math.random and crypto.pseudoRandomBytes.
    Better alternatives are crypto.randomBytes and window.crypto.getRandomValues.
    

    References:

CWE 330

MDN Math.random

Node.js crypto.randomBytes()

window.crypto.getRandomValues()

  2.0.11




  
    jquery-deferred-must-complete
  
  
    When a JQuery Deferred instance is created, then either reject() or resolve() must be called on it within all code branches in the scope.
    For more examples see the feature request.
  
  1.0




  
    max-func-body-length
  
  
    Avoid long functions.
    The line count of a function body must not exceed the value configured within this rule's options.
    

    You can set up a general max function body length applied for every function/method/arrow function e.g. [true, 30] or set different maximum length for every type e.g. [true, { "func-body-length": 10 , "func-expression-body-length": 10 , "arrow-body-length": 5, "method-body-length": 15, "ctor-body-length": 5 }].
    To specify a function name whose parameters you can ignore for this rule, pass a regular expression as a string(this can be useful for Mocha users to ignore the describe() function).
    Since version 2.0.9, you can also ignore single- and multi-line comments from the total function length, eg. [true, { "ignore-comments": true }].
  
  2.0.3




  
  missing-jsdoc
  
  
    Deprecated - This rule can be replaced with TSLint's file-header rule.
    All files must have a top level [JSDoc](http://usejsdoc.org/) comment.
    A JSDoc comment starts with /** (not one more or one less asterisk) and a JSDoc at the 'top-level' appears without leading spaces.
    Trailing spaces are acceptable but not recommended
  
  1.0




  
    missing-optional-annotation
  
  
    Deprecated - This rule is now enforced by the TypeScript compiler.
    A parameter that follows one or more parameters marked as optional is not itself marked optional.
  
  0.0.1




  
    mocha-avoid-only
  
  
    Do not invoke Mocha's describe.only, it.only, or context.only functions.
    These functions are useful ways to run a single unit test or a single test case during your build, but please be careful to not push these methods calls to your version control repository because it will turn off any of the other tests.
  
  1.0




  
    mocha-no-side-effect-code
  
  
    All test logic in a Mocha test case should be within Mocha lifecycle method and not defined statically to execute when the module loads.
    Put all assignments and initialization statements in a before(), beforeEach(), beforeAll(), after(), afterEach(), afterAll(), or it() function.
    Code executed outside of these lifecycle methods can throw exceptions before the test runner is initialized and can result in errors or even test runner crashes.
    This rule can be configured with a regex to ignore certain initializations.
    For example, to ignore any calls to RestDataFactory configure the rule with: [true, { ignore: '^RestDataFactory\\..*' }]
  
  2.0.10




  
    mocha-unneeded-don

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言