A sane tslint style.
These represent sane defaults for a typescript project (file an issue if found insane). The aim of this project is to keep a solid working style for each tslint version, tagged to keep consistancy.
See tslint rules for additional information.
"array-type": [true, "generic"]
Requires using either T[]
or Array
for arrays.
All objects/classes to be referenced capcase.
Example
public test(testSteps: Array<Array<string>>, testName: string): void {}
"arrow-parens": [true]
Requires parentheses around the parameters of arrow function definitions.
"class-name": true
Enforce PascalCased class and interface names. Makes it easy to differentitate classes from regular variables at a glance.
"cyclomatic-complexity": [true, 3]
Complexity based on statements and expressions such as * catch
* if
and ? :
* ||
and &&
due to short-circuit evaluation * for
, for in
and for of
loops * while
and do while
loops.
3 is sane. 4, insane.
"comment-format": [true, "check-space"]
Enforce formatting rules for single-line comments.
"eofline": true
Ensure the file ends with a newline.
"indent": [true, "spaces"]
Enforce indentation with spaces.
"jsdoc-format": true
Enforce basic format rules for JSDoc comments.
"max-classes-per-file": [true, 1]
Ensures that files have a single responsibility so that that classes each exist in their own files and 1 per file keeps everyone sane. Should also name the file the [classname].ts
.
"max-file-line-count": [true, 100]
Ensure a file stays under a certain line count. Most people don't like scrolling more than 300.
"no-default-export": true
Be original, name your import something other than default
.
"no-duplicate-variable": [true, 1]
There’s no good reason to have a duplicate variable declaration.
"no-parameter-properties": true
More verbose and explicit but easier to understand. Example
"no-eval": true
Eval is unsafe. Try .call()
or some other method to achieve your goals.
"no-internal-module": true
Use the namespace
keyword and not module
.
"no-trailing-whitespace": true
No trailing whitespace.
"no-unsafe-finally": true
Disallows control flow statements, such as return
, continue
, break
and throws
in finally
blocks.
"no-var-keyword": true
Use let
or const
instead of var
.
"object-literal-key-quotes": [true, "always"]
Property names should always be quoted.
"object-literal-shorthand": true
Enforce use of ES6 object literal shorthand when possible.
"object-literal-sort-keys": true
Require keys in object literals to be sorted alphabetically.
"one-line": [
true,
"check-open-brace",
"check-whitespace"
]
Require the open brace and whitespace to be on the same line as the expression preceding them.
"ordered-imports": [
true,
{
"import-sources-order": "lowercase-last",
"named-imports-order": "lowercase-first"
}
]
Require that import statements be alphabetized.
"one-variable-per-declaration": [true, "ignore-for-loop"]
No multiline declaration unless in a for
loop.
"one-variable-per-declaration": [true, "double"]
Require double quotes for string literals.
"semicolon": [
true,
"always"
]
Enforce semicolons at the end of every statement including bound class methods and interfaces.
"trailing-comma": [
false,
{
"multiline": "never",
"singleline": "never"
}
]
Disallow trailing commas in array and object literals, destructuring assignments, function and tuple typings, named imports and function parameters.
"triple-equals": true
Requires ===
and !==
, no exceptions.
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
]
No space is required before the colon in a type specifier.
"variable-name": [
true,
"check-format",
"allow-leading-underscore",
"allow-trailing-underscore",
"allow-pascal-case",
"ban-keywords"
]
Checks variable names for various errors.
"check-format"
: allow only camelCased orUPPER_CASED
variable names"allow-leading-underscore"
: allow underscores at the beginning (only has an effect if“check-format”
specified)"allow-trailing-underscore"
: allow underscores at the end. (only has an effect if“check-format”
specified)"allow-pascal-case"
: allow PascalCase in addtion to camelCase.
"ban-keywords"
: Do not allow the use of certain TypeScript keywords (any
,Number
,number
,String
,string
,Boolean
,boolean
,undefined
) as variable or parameter names.
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-type",
"check-typecast"
]
Enforce whitespace style conventions.
"check-branch"
check branching statements (if/else/for/while
) are followed by whitespace."check-decl"
check that variable declarations have whitespace around the equals token."check-operator"
check for whitespace around operator tokens."check-module"
check for whitespace in import & export statements."check-separator"
check for whitespace after separator tokens (,/;
)."check-type"
check for whitespace before a variable type specification."check-typecast"
check for whitespace between a typecast and its target."check-preblock"
check for whitespace before the opening brace of a block