Home

Awesome

Purpose

This project includes a variety of tslint rules we have found useful for our projects.

Usage

Install from npm to your devDependencies (https://www.npmjs.com/package/vrsource-tslint-rules)

npm install --save-dev vrsource-tslint-rules

Configure tslint to use the vrsource-tslint-rules folder:

Add "vrsource-tslint-rules" to the extends array of your tslint.json file:

{
   "rulesDirectory": ["vrsource-tslint-rules/rules"]
   "rules": {
     ...
   }
}

Now configure some of the new rules.

Rules

conditional-expression-parens

Rule to enforce the use of parentheses each clause of a conditional when they are not simple expressions of a single indentifier or calling expression.

"conditional-expression-parens": true

ext-variable-name

This rule provides extensive support for customizing allowable variable names for a wide variety of variable tags. The rule is configured by setting up a list of sub-rules that specify the tags of variables to check and the checks to perform on the variable's name. The sub-rules are checked in order and the first one that matches the tags of variable being checked is the only one that is used.

An example set of sub-rules for an example coding standard is shown below.

"ext-variable-name": [
   true,
   ["class",                 "pascal"],
   ["interface",             "pascal", {"regex": "^I.*$"}],
   ["parameter",             "camel"],
   ["property", "static",    "camel", {"regex": "^s.*$"}],
   ["property", "private",   "camel", "require-leading-underscore"],
   ["property", "protected", "camel", "allow-leading-underscore"],
   ["variable", "local",     "snake"],
   ["variable", "const",     "upper"],
   ["variable",              "camel", {"regex": "^g.*$"}],
   ["method", "private",     "camel", "require-leading-underscore"],
   ["method", "protected",   "camel", "allow-leading-underscore"],
   ["function",              "camel"],
   ["default",               "camel"]
]

Allowed tags for variables:

note: If any tags is added to a sub-rule then all must match the variable.

Checks allowed:

literal-spacing

Rule to enforce consistent spacing inside array and object literals.

See: eslint: object-curly-spacing and array-bracket-spacing

"literal-spacing": [
    true,
    {
        "array": ["always"],
        "object": ["never"],
        "import": ["always"]
    }
]

max-params

Rule to enforce a maximum number of parameters for functions and methods.

"max-params": [
    true,
    3
]

multiline-arrow

Rule to enforce various checks arrow functions that span multiple lines.

"multiline-arrow": [
    true,
    "require-parens",
    "require-block"
]

prefer-case-blocks

This rule checks to make sure that all case clauses use a block around the statements of the case. This helps to protect against issues with lexcical declarations that would become visible to the entire switch statement.

To maintain consistency, the rule requires a block in all cases.

"prefer-case-blocks": true

prefer-literal

Flags locations where code calls "new Object()", "new Array()", "new Function()""

"prefer-literal": [
    true,
    "object",
    "function",
    "array"
]

Changelog

Contributing

Contributions are greatly appreciated. Please fork the repository and submit a pull request.

Contributors

Development

Development steps

The command npm run test will run tests locally.

To add a new rule:

Notes for how to build new rules and tests:

Resources

Example Rules

Release Process