A set of custom TSLint rules.
Install from npm to your devDependencies:
npm install --save-dev mws-tslint-rules
Configure tslint to use the mws-tslint-rules folder:
Add the following path to the rulesDirectory
setting in your tslint.json
file:
{
"rulesDirectory": [
"node_modules/mws-tslint-rules/dist"
],
"rules": {
...
}
}
Now configure some of the new rules.
TODO
TODO
{
"empty-line-before-return-statement": true
}
Not configurable.
TODO
TODO
{
"empty-lines-at-block-statement": true
}
Not configurable.
TODO
TODO
{
"empty-lines-at-variable-statement": true
}
Not configurable.
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",
"allow-leading-underscore"
],
[
"property",
"protected",
"camel",
"allow-leading-underscore"
],
[
"variable",
"local",
"snake"
],
[
"variable",
"const",
"upper"
],
[
"variable",
"camel",
{
"regex": "^g.*$"
}
],
[
"method",
"private",
"camel",
"allow-leading-underscore"
],
[
"method",
"protected",
"camel",
"allow-leading-underscore"
],
[
"function",
"camel"
],
[
"default",
"camel"
]
]
}
Allowed tags for variables:
- primary (choose one):
- class, interface, parameter, property, method, function, variable
- modifiers (choose zero or more):
- local, const, static, public, protected, private
note: If any tags is added to a sub-rule then all must match the variable.
Checks allowed:
- One of:
- "camel": Require variables to use camelCaseVariables
- "snake": Require variables to use snake_case_variables
- "pascal": Require variables to use PascalCaseVariables
- "upper": Require variables to use UPPER_CASE_VARIABLES
- "allow-leading-underscore": permits the variable to have a leading underscore
- "allow-trailing-underscore": permits the variable to have a trailing underscore
- "ban-keywords": bans a list of language keywords from being used
- {"regex": "^.*$"}: checks the variable name against the given regex
TODO
TODO
{
"sorting-import": [
true,
{
"orderImportType": ["NAMED", "SIDE_EFFECT", "NAMESPACE", "NAMED_WITHOUT_BRACKETS", "EQUALS"],
"orderSortingType": "MAX_TO_MIN_LENGTH"
}
]
}
For orderImportType
, array of all the following in desired order:
"NAMED"
-"SIDE_EFFECT"
-"NAMESPACE"
-"NAMED_WITHOUT_BRACKETS"
-"EQUALS"
-
For orderSortingType
, one of the following:
"MAX_TO_MIN_LENGTH"
-"MIN_TO_MAX_LENGTH"
-
TODO
TODO
{
"types-in-method-declaration": true
}
Not configurable.
TODO
TODO
{
"whitespace-in-method-declaration": true
}
Not configurable.
Issue reports and pull requests are highly welcome! Please make sure to provide sensible tests along with your pull request.
To get started with development, clone the project and run npm install
.
To run the tests execute npm test
.