UNPKG

12.7 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 "insecure-random": true,
13 "no-banned-terms": true,
14 "no-cookies": true,
15 "no-delete-expression": true,
16 "no-disable-auto-sanitization": true,
17 "no-document-domain": true,
18 "no-document-write": true,
19 "no-eval": true,
20 "no-exec-script": true,
21 "no-function-constructor-with-string-args": true,
22 "no-http-string": [true, "http://www.example.com/?.*", "http://www.examples.com/?.*"],
23 "no-inner-html": true,
24 "no-octal-literal": true,
25 "no-reserved-keywords": true,
26 "no-string-based-set-immediate": true,
27 "no-string-based-set-interval": true,
28 "no-string-based-set-timeout": true,
29 "non-literal-require": true,
30 "possible-timing-attack": true,
31 "react-anchor-blank-noopener": true,
32 "react-iframe-missing-sandbox": true,
33 "react-no-dangerous-html": true,
34
35 /**
36 * Common Bugs and Correctness. The following rules should be turned on because they find
37 * common bug patterns in the code or enforce type safety.
38 */
39 "await-promise": true,
40 "forin": true,
41 "jquery-deferred-must-complete": true,
42 "label-position": true,
43 "match-default-export-name": true,
44 "mocha-avoid-only": true,
45 "mocha-no-side-effect-code": true,
46 "no-any": true,
47 "no-arg": true,
48 "no-backbone-get-set-outside-model": true,
49 "no-bitwise": true,
50 "no-conditional-assignment": true,
51 "no-console": [true, "debug", "info", "log", "time", "timeEnd", "trace"],
52 "no-constant-condition": true,
53 "no-control-regex": true,
54 "no-debugger": true,
55 "no-duplicate-super": true,
56 "no-duplicate-switch-case": true,
57 "no-duplicate-variable": true,
58 "no-empty": true,
59 "no-floating-promises": true,
60 "no-for-in-array": true,
61 "no-implicit-dependencies": true,
62 "no-import-side-effect": true,
63 "no-increment-decrement": true,
64 "no-invalid-regexp": true,
65 "no-invalid-template-strings": true,
66 "no-invalid-this": true,
67 "no-jquery-raw-elements": true,
68 "no-misused-new": true,
69 "no-non-null-assertion": true,
70 "no-object-literal-type-assertion": true,
71 "no-parameter-reassignment": true,
72 "no-reference-import": true,
73 "no-regex-spaces": true,
74 "no-sparse-arrays": true,
75 "no-string-literal": true,
76 "no-string-throw": true,
77 "no-submodule-imports": true,
78 "no-unnecessary-bind": true,
79 "no-unnecessary-callback-wrapper": true,
80 "no-unnecessary-initializer": true,
81 "no-unnecessary-override": true,
82 "no-unsafe-any": true,
83 "no-unsafe-finally": true,
84 "no-unused-expression": true,
85 "no-use-before-declare": true,
86 "no-with-statement": true,
87 "promise-function-async": true,
88 "promise-must-complete": true,
89 "radix": true,
90 "react-this-binding-issue": true,
91 "react-unused-props-and-state": true,
92 "restrict-plus-operands": true, // the plus operand should really only be used for strings and numbers
93 "strict-boolean-expressions": true,
94 "switch-default": true,
95 "switch-final-break": true,
96 "triple-equals": [true, "allow-null-check"],
97 "use-isnan": true,
98 "use-named-parameter": true,
99
100 /**
101 * Code Clarity. The following rules should be turned on because they make the code
102 * generally more clear to the reader.
103 */
104 "adjacent-overload-signatures": true,
105 "array-type": [true, "array"],
106 "arrow-parens": false, // for simple functions the parens on arrow functions are not needed
107 "ban-comma-operator": true, // possibly controversial
108 "binary-expression-operand-order": true,
109 "callable-types": true,
110 "chai-prefer-contains-to-index-of": true,
111 "chai-vague-errors": true,
112 "class-name": true,
113 "comment-format": true,
114 "completed-docs": [true, "classes"],
115 "export-name": true,
116 "function-name": true,
117 "import-name": true,
118 "interface-name": true,
119 "jsdoc-format": true,
120 "max-classes-per-file": [true, 3], // we generally recommend making one public class per file
121 "max-file-line-count": true,
122 "max-func-body-length": [true, 100, {"ignore-parameters-to-function-regex": "describe"}],
123 "max-line-length": [true, 140],
124 "member-access": true,
125 "member-ordering": [true, { "order": "fields-first" }],
126 "missing-jsdoc": true,
127 "mocha-unneeded-done": true,
128 "new-parens": true,
129 "no-construct": true,
130 "no-default-export": true,
131 "no-duplicate-imports": true,
132 "no-empty-interface": true,
133 "no-for-in": true,
134 "no-function-expression": true,
135 "no-inferrable-types": false, // turn no-inferrable-types off in order to make the code consistent in its use of type decorations
136 "no-multiline-string": true, // multiline-strings often introduce unnecessary whitespace into the string literals
137 "no-null-keyword": false, // turn no-null-keyword off and use undefined to mean not initialized and null to mean without a value
138 "no-parameter-properties": true,
139 "no-redundant-jsdoc": true,
140 "no-relative-imports": true,
141 "no-require-imports": true,
142 "no-return-await": true,
143 "no-shadowed-variable": true,
144 "no-suspicious-comment": true,
145 "no-this-assignment": true,
146 "no-typeof-undefined": true,
147 "no-unnecessary-class": true,
148 "no-unnecessary-field-initialization": true,
149 "no-unnecessary-local-variable": true,
150 "no-unnecessary-qualifier": true,
151 "no-unnecessary-type-assertion": true,
152 "no-unsupported-browser-code": true,
153 "no-useless-files": true,
154 "no-var-keyword": true,
155 "no-var-requires": true,
156 "no-void-expression": true,
157 "number-literal-format": true,
158 "object-literal-sort-keys": false, // turn object-literal-sort-keys off and sort keys in a meaningful manner
159 "one-variable-per-declaration": true,
160 "only-arrow-functions": false, // there are many valid reasons to declare a function
161 "ordered-imports": true,
162 "prefer-array-literal": true,
163 "prefer-const": true,
164 "prefer-for-of": true,
165 "prefer-method-signature": true,
166 "prefer-object-spread": true,
167 "prefer-template": true,
168 "type-literal-delimiter": true,
169 "typedef": [true, "call-signature", "arrow-call-signature", "parameter", "arrow-parameter", "property-declaration", "variable-declaration", "member-variable-declaration"],
170 "underscore-consistent-invocation": true,
171 "unified-signatures": true,
172 "use-default-type-parameter": true,
173 "variable-name": true,
174
175 /**
176 * Accessibility. The following rules should be turned on to guarantee the best user
177 * experience for keyboard and screen reader users.
178 */
179 "react-a11y-anchors": true,
180 "react-a11y-aria-unsupported-elements": true,
181 "react-a11y-event-has-role": true,
182 "react-a11y-image-button-has-alt": true,
183 "react-a11y-img-has-alt": true,
184 "react-a11y-lang": true,
185 "react-a11y-meta": true,
186 "react-a11y-props": true,
187 "react-a11y-proptypes": true,
188 "react-a11y-role": true,
189 "react-a11y-role-has-required-aria-props": true,
190 "react-a11y-role-supports-aria-props": true,
191 "react-a11y-tabindex-no-positive": true,
192 "react-a11y-titles": true,
193
194 /**
195 * Whitespace related rules. The only recommended whitespace strategy is to pick a single format and
196 * be consistent.
197 */
198 "align": [true, "parameters", "arguments", "statements"],
199 "curly": true,
200 "encoding": true,
201 "eofline": true,
202 "import-spacing": true,
203 "indent": [true, "spaces"],
204 "linebreak-style": true,
205 "newline-before-return": true,
206 "no-consecutive-blank-lines": true,
207 "no-empty-line-after-opening-brace": false,
208 "no-irregular-whitespace": true,
209 "no-single-line-block-comment": true,
210 "no-trailing-whitespace": true,
211 "no-unnecessary-semicolons": true,
212 "object-literal-key-quotes": [true, "as-needed"],
213 "one-line": [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"],
214 "quotemark": [true, "single"],
215 "semicolon": [true, "always"],
216 "space-within-parens": true,
217 "trailing-comma": [true, {"singleline": "never", "multiline": "never"}], // forcing trailing commas for multi-line
218 // lists results in lists that are easier to reorder and version control diffs that are more clear.
219 // Many teams like to have multiline be 'always'. There is no clear consensus on this rule but the
220 // internal MS JavaScript coding standard does discourage it.
221 "typedef-whitespace": false,
222 "whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"],
223
224 /**
225 * Controversial/Configurable rules.
226 */
227 "ban": false, // only enable this if you have some code pattern that you want to ban
228 "ban-types": true,
229 "cyclomatic-complexity": true,
230 "deprecation": false, // deprecated APIs are sometimes unavoidable
231 "file-header": false, // enable this rule only if you are legally required to add a file header
232 "import-blacklist": false, // enable and configure this as you desire
233 "interface-over-type-literal": false, // there are plenty of reasons to prefer interfaces
234 "no-angle-bracket-type-assertion": false, // pick either type-cast format and use it consistently
235 "no-inferred-empty-object-type": false, // if the compiler is satisfied then this is probably not an issue
236 "no-internal-module": false, // only enable this if you are not using internal modules
237 "no-magic-numbers": false, // by default it will find too many false positives
238 "no-mergeable-namespace": false, // your project may require mergeable namespaces
239 "no-namespace": false, // only enable this if you are not using modules/namespaces
240 "no-reference": true, // in general you should use a module system and not /// reference imports
241 "no-unexternalized-strings": false, // the VS Code team has a specific localization process that this rule enforces
242 "object-literal-shorthand": false, // object-literal-shorthand offers an abbreviation not an abstraction
243 "prefer-conditional-expression": false, // unnecessarily strict
244 "prefer-switch": false, // more of a style preference
245 "prefer-type-cast": true, // pick either type-cast format and use it consistently
246 "return-undefined": false, // this actually affect the readability of the code
247 "space-before-function-paren": false, // turn this on if this is really your coding standard
248
249 /**
250 * Deprecated rules. The following rules are deprecated for various reasons.
251 */
252 "missing-optional-annotation": false, // now supported by TypeScript compiler
253 "no-duplicate-case": true,
254 "no-duplicate-parameter-names": false, // now supported by TypeScript compiler
255 "no-empty-interfaces": false, // use tslint no-empty-interface rule instead
256 "no-missing-visibility-modifiers": false, // use tslint member-access rule instead
257 "no-multiple-var-decl": false, // use tslint one-variable-per-declaration rule instead
258 "no-stateless-class": true,
259 "no-switch-case-fall-through": false, // now supported by TypeScript compiler
260 "no-var-self": true,
261 "react-tsx-curly-spacing": true,
262 "typeof-compare": false, // the valid-typeof rule is currently superior to this version
263 "valid-typeof": true,
264 }
265};
266