UNPKG

8.01 kBJavaScriptView Raw
1/**
2 * These rule settings are a broad, general recommendation for a good default configuration.
3 * This file is exported in the npm/nuget package as ./tslint.json.
4 */
5module.exports = {
6 "rules": {
7
8 /**
9 * Security Rules. The following rules should be turned on because they find security issues
10 * or are recommended in the Microsoft Secure Development Lifecycle (SDL)
11 */
12 "no-eval": true,
13
14 /**
15 * Common Bugs and Correctness. The following rules should be turned on because they find
16 * common bug patterns in the code or enforce type safety.
17 */
18 "await-promise": true,
19 "forin": true,
20 "id-length": true,
21 "label-position": true,
22 "match-default-export-name": true,
23 "max-func-args": [true, 3],
24 "min-class-cohesion": [true, 0.5],
25 "newspaper-order": true,
26 "no-any": true,
27 "no-arg": true,
28 "no-bitwise": true,
29 "no-conditional-assignment": true,
30 "no-console": [true, "debug", "info", "log", "time", "timeEnd", "trace"],
31 "no-debugger": true,
32 "no-duplicate-super": true,
33 "no-duplicate-variable": true,
34 "no-empty": true,
35 "no-flag-args": true,
36 "no-floating-promises": true,
37 "no-for-each-push": true,
38 "no-for-in-array": true,
39 "no-import-side-effect": true,
40 "no-invalid-template-strings": true,
41 "no-invalid-this": true,
42 "no-map-without-usage": true,
43 "no-misused-new": true,
44 "no-non-null-assertion": true,
45 "no-reference-import": true,
46 "no-sparse-arrays": true,
47 "no-string-literal": true,
48 "no-string-throw": true,
49 "no-unnecessary-callback-wrapper": true,
50 "no-unnecessary-initializer": true,
51 "no-unsafe-any": true,
52 "no-unsafe-finally": true,
53 "no-unused-expression": true,
54 "no-use-before-declare": true,
55 "promise-function-async": true,
56 "radix": true,
57 "restrict-plus-operands": true, // the plus operand should really only be used for strings and numbers
58 "strict-boolean-expressions": true,
59 "switch-default": true,
60 "triple-equals": [true, "allow-null-check"],
61 "try-catch-first": true,
62 "use-isnan": true,
63
64 /**
65 * Code Clarity. The following rules should be turned on because they make the code
66 * generally more clear to the reader.
67 */
68 "adjacent-overload-signatures": true,
69 "array-type": [true, "array"],
70 "arrow-parens": false, // for simple functions the parens on arrow functions are not needed
71 "callable-types": true,
72 "class-name": true,
73 "comment-format": true,
74 "completed-docs": [true, "classes"],
75 "interface-name": true,
76 "jsdoc-format": true,
77 "max-classes-per-file": [true, 3], // we generally recommend making one public class per file
78 "max-file-line-count": true,
79 "max-line-length": [true, 140],
80 "member-access": true,
81 "member-ordering": [true, { "order": "fields-first" }],
82 "new-parens": true,
83 "no-commented-out-code": true,
84 "no-complex-conditionals": true,
85 "no-construct": true,
86 "no-default-export": true,
87 "no-empty-interface": true,
88 "no-feature-envy": [true, 1, ["_"]],
89 "no-inferrable-types": false, // turn no-inferrable-types off in order to make the code consistent in its use of type decorations
90 "no-null-keyword": false, // turn no-null-keyword off and use undefined to mean not initialized and null to mean without a value
91 "no-parameter-properties": true,
92 "no-require-imports": true,
93 "no-shadowed-variable": true,
94 "no-unnecessary-qualifier": true,
95 "no-var-keyword": true,
96 "no-var-requires": true,
97 "no-void-expression": true,
98 "object-literal-sort-keys": false, // turn object-literal-sort-keys off and sort keys in a meaningful manner
99 "one-variable-per-declaration": true,
100 "only-arrow-functions": false, // there are many valid reasons to declare a function
101 "ordered-imports": true,
102 "prefer-const": true,
103 "prefer-dry-conditionals": true,
104 "prefer-for-of": true,
105 "prefer-method-signature": true,
106 "prefer-template": true,
107 "return-undefined": false, // this actually affect the readability of the code
108 "typedef": [true, "call-signature", "arrow-call-signature", "parameter", "arrow-parameter", "property-declaration", "variable-declaration", "member-variable-declaration"],
109 "unified-signatures": true,
110 "variable-name": true,
111
112 /**
113 * Accessibility. The following rules should be turned on to guarantee the best user
114 * experience for keyboard and screen reader users.
115 */
116
117
118 /**
119 * Whitespace related rules. The only recommended whitespace strategy is to pick a single format and
120 * be consistent.
121 */
122 "align": [true, "parameters", "arguments", "statements"],
123 "curly": true,
124 "eofline": true,
125 "import-spacing": true,
126 "indent": [true, "spaces"],
127 "linebreak-style": true,
128 "newline-before-return": true,
129 "no-consecutive-blank-lines": true,
130 "no-trailing-whitespace": true,
131 "object-literal-key-quotes": [true, "as-needed"],
132 "one-line": [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"],
133 "quotemark": [true, "single"],
134 "semicolon": [true, "always"],
135 "trailing-comma": [true, {"singleline": "never", "multiline": "never"}], // forcing trailing commas for multi-line
136 // lists results in lists that are easier to reorder and version control diffs that are more clear.
137 // Many teams like to have multiline be 'always'. There is no clear consensus on this rule but the
138 // internal MS JavaScript coding standard does discourage it.
139 "typedef-whitespace": false,
140 "whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"],
141
142 /**
143 * Controversial/Configurable rules.
144 */
145 "ban": false, // only enable this if you have some code pattern that you want to ban
146 "ban-types": true,
147 "cyclomatic-complexity": true,
148 "file-header": false, // enable this rule only if you are legally required to add a file header
149 "import-blacklist": false, // enable and configure this as you desire
150 "interface-over-type-literal": false, // there are plenty of reasons to prefer interfaces
151 "no-angle-bracket-type-assertion": false, // pick either type-cast format and use it consistently
152 "no-inferred-empty-object-type": false, // if the compiler is satisfied then this is probably not an issue
153 "no-internal-module": false, // only enable this if you are not using internal modules
154 "no-magic-numbers": false, // by default it will find too many false positives
155 "no-mergeable-namespace": false, // your project may require mergeable namespaces
156 "no-namespace": false, // only enable this if you are not using modules/namespaces
157 "no-reference": true, // in general you should use a module system and not /// reference imports
158 "object-literal-shorthand": false, // object-literal-shorthand offers an abbreviation not an abstraction
159 "space-before-function-paren": false, // turn this on if this is really your coding standard
160
161 /**
162 * Deprecated rules. The following rules are deprecated for various reasons.
163 */
164 "no-switch-case-fall-through": false, // now supported by TypeScript compiler
165 "typeof-compare": false, // the valid-typeof rule is currently superior to this version
166 }
167};
168