package
Extension rules for tslint
npm install vrsource-tslint-rulesGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
182.9 kB
Includes dependencies.
This project includes a variety of tslint rules we have found useful for our projects.
Install from npm to your devDependencies (https://www.npmjs.com/package/vrsource-tslint-rules)
npm install --save-dev vrsource-tslint-rulesConfigure 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.
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": trueThis 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"
Allowed tags for variables:
note: If any tags is added to a sub-rule then all must match the variable.
Checks allowed:
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"]
}
]Rule to enforce a maximum number of parameters for functions and methods.
"max-params": [
true,
3
]Rule to enforce various checks arrow functions that span multiple lines.
"multiline-arrow": [
true,
"require-parens",
"require-block"
]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": trueFlags locations where code calls "new Object()", "new Array()", "new Function()""
"prefer-literal": [
true,
"object",
"function",
"array"
]prefer-const rule as tslint now supports itContributions are greatly appreciated. Please fork the repository and submit a pull request.
The command npm run test will run tests locally.
To add a new rule:
Notes for how to build new rules and tests: