UNPKG

13.1 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 * Security Rules. The following rules should be turned on because they find security issues
9 * or are recommended in the Microsoft Secure Development Lifecycle (SDL)
10 */
11 'insecure-random': true,
12 'no-banned-terms': true,
13 'no-cookies': true,
14 'no-delete-expression': true,
15 'no-disable-auto-sanitization': true,
16 'no-document-domain': true,
17 'no-document-write': true,
18 'no-eval': true,
19 'no-exec-script': true,
20 'no-function-constructor-with-string-args': true,
21 'no-http-string': [true, 'http://www.example.com/?.*', 'http://localhost:?.*'],
22 'no-inner-html': true,
23 'no-octal-literal': true,
24 'no-reserved-keywords': true,
25 'no-string-based-set-immediate': true,
26 'no-string-based-set-interval': true,
27 'no-string-based-set-timeout': true,
28 'non-literal-fs-path': 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', 'error', '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 'use-simple-attributes': true,
100
101 /**
102 * Code Clarity. The following rules should be turned on because they make the code
103 * generally more clear to the reader.
104 */
105 'adjacent-overload-signatures': true,
106 'array-type': [true, 'array'],
107 'arrow-parens': false, // for simple functions the parens on arrow functions are not needed
108 'ban-comma-operator': true, // possibly controversial
109 'binary-expression-operand-order': true,
110 'callable-types': true,
111 'chai-prefer-contains-to-index-of': true,
112 'chai-vague-errors': true,
113 'class-name': true,
114 'comment-format': true,
115 'completed-docs': [true, 'classes'],
116 'export-name': true,
117 'file-name-casing': true,
118 'function-name': true,
119 'import-name': true,
120 'informative-docs': true,
121 'interface-name': true,
122 'jsdoc-format': true,
123 'max-classes-per-file': [true, 3], // we generally recommend making one public class per file
124 'max-file-line-count': true,
125 'max-func-body-length': [true, 100, { 'ignore-parameters-to-function-regex': '^describe$' }],
126 'max-line-length': [true, 140],
127 'member-access': true,
128 'member-ordering': [true, { 'order': 'fields-first' }],
129 'mocha-unneeded-done': true,
130 'new-parens': true,
131 'newline-per-chained-call': true,
132 'no-construct': true,
133 'no-default-export': true,
134 'no-duplicate-imports': true,
135 'no-dynamic-delete': true,
136 'no-empty-interface': true,
137 'no-for-in': true,
138 'no-function-expression': true,
139 'no-inferrable-types': false, // turn no-inferrable-types off in order to make the code consistent in its use of type decorations
140 'no-multiline-string': false,
141 'no-null-keyword': true,
142 'no-parameter-properties': true,
143 'no-redundant-jsdoc': true,
144 'no-relative-imports': true,
145 'no-require-imports': true,
146 'no-return-await': true,
147 'no-shadowed-variable': true,
148 'no-suspicious-comment': true,
149 'no-this-assignment': true,
150 'no-typeof-undefined': true,
151 'no-unnecessary-field-initialization': true,
152 'no-unnecessary-local-variable': true,
153 'no-unnecessary-qualifier': true,
154 'no-unnecessary-type-assertion': true,
155 'no-unsupported-browser-code': true,
156 'no-useless-files': true,
157 'no-var-keyword': true,
158 'no-var-requires': true,
159 'no-void-expression': true,
160 'number-literal-format': true,
161 'object-literal-sort-keys': false, // turn object-literal-sort-keys off and sort keys in a meaningful manner
162 'one-variable-per-declaration': true,
163 'only-arrow-functions': false, // there are many valid reasons to declare a function
164 'ordered-imports': true,
165 'prefer-array-literal': true,
166 'prefer-const': true,
167 'prefer-for-of': true,
168 'prefer-method-signature': true,
169 'prefer-object-spread': true,
170 'prefer-readonly': true,
171 'prefer-template': true,
172 'prefer-while': true,
173 'type-literal-delimiter': true,
174 'typedef': [true, 'call-signature', 'arrow-call-signature', 'parameter', 'arrow-parameter', 'property-declaration', 'variable-declaration', 'member-variable-declaration'],
175 'underscore-consistent-invocation': true,
176 'unified-signatures': true,
177 'use-default-type-parameter': true,
178 'variable-name': true,
179
180 /**
181 * Accessibility. The following rules should be turned on to guarantee the best user
182 * experience for keyboard and screen reader users.
183 */
184 'react-a11y-anchors': true,
185 'react-a11y-aria-unsupported-elements': true,
186 'react-a11y-event-has-role': true,
187 'react-a11y-image-button-has-alt': true,
188 'react-a11y-img-has-alt': true,
189 'react-a11y-input-elements': true,
190 'react-a11y-lang': true,
191 'react-a11y-meta': true,
192 'react-a11y-no-onchange': true,
193 'react-a11y-props': true,
194 'react-a11y-proptypes': true,
195 'react-a11y-required': true,
196 'react-a11y-role': true,
197 'react-a11y-role-has-required-aria-props': true,
198 'react-a11y-role-supports-aria-props': true,
199 'react-a11y-tabindex-no-positive': true,
200 'react-a11y-titles': true,
201
202 /**
203 * Whitespace related rules. The only recommended whitespace strategy is to pick a single format and
204 * be consistent.
205 */
206 'align': [true, 'parameters', 'arguments', 'statements'],
207 'curly': true,
208 'encoding': true,
209 'eofline': true,
210 'import-spacing': true,
211 'indent': [true, 'spaces'],
212 'linebreak-style': true,
213 'newline-before-return': true,
214 'no-consecutive-blank-lines': true,
215 'no-empty-line-after-opening-brace': false,
216 'no-irregular-whitespace': true,
217 'no-single-line-block-comment': true,
218 'no-trailing-whitespace': true,
219 'no-unnecessary-semicolons': true,
220 'object-literal-key-quotes': [true, 'as-needed'],
221 'one-line': [true, 'check-open-brace', 'check-catch', 'check-else', 'check-whitespace'],
222 'quotemark': [true, 'single'],
223 'semicolon': [true, 'always'],
224 'space-within-parens': true,
225 'trailing-comma': [true, { 'singleline': 'never', 'multiline': 'never' }], // forcing trailing commas for multi-line
226 // lists results in lists that are easier to reorder and version control diffs that are more clear.
227 // Many teams like to have multiline be 'always'. There is no clear consensus on this rule but the
228 // internal MS JavaScript coding standard does discourage it.
229 'typedef-whitespace': false,
230 'whitespace': [true, 'check-branch', 'check-decl', 'check-operator', 'check-separator', 'check-type'],
231
232 /**
233 * Controversial/Configurable rules.
234 */
235 'ban': false, // only enable this if you have some code pattern that you want to ban
236 'ban-types': true,
237 'cyclomatic-complexity': true,
238 'deprecation': false, // deprecated APIs are sometimes unavoidable
239 'file-header': false, // enable this rule only if you are legally required to add a file header
240 'import-blacklist': false, // enable and configure this as you desire
241 'interface-over-type-literal': false, // there are plenty of reasons to prefer interfaces
242 'no-angle-bracket-type-assertion': false, // pick either type-cast format and use it consistently
243 'no-inferred-empty-object-type': false, // if the compiler is satisfied then this is probably not an issue
244 'no-internal-module': false, // only enable this if you are not using internal modules
245 'no-magic-numbers': false, // by default it will find too many false positives
246 'no-mergeable-namespace': false, // your project may require mergeable namespaces
247 'no-namespace': false, // only enable this if you are not using modules/namespaces
248 'no-reference': true, // in general you should use a module system and not /// reference imports
249 'no-unexternalized-strings': false, // the VS Code team has a specific localization process that this rule enforces
250 'object-literal-shorthand': false, // object-literal-shorthand offers an abbreviation not an abstraction
251 'prefer-conditional-expression': false, // unnecessarily strict
252 'prefer-switch': false, // more of a style preference
253 'prefer-type-cast': true, // pick either type-cast format and use it consistently
254 'return-undefined': false, // this actually affects the readability of the code
255 'space-before-function-paren': false, // turn this on if this is really your coding standard
256
257 /**
258 * Deprecated rules. The following rules are deprecated for various reasons.
259 */
260 'missing-jsdoc': false,
261 'missing-optional-annotation': false, // now supported by TypeScript compiler
262 'no-duplicate-case': false,
263 'no-duplicate-parameter-names': false, // now supported by TypeScript compiler
264 'no-empty-interfaces': false, // use tslint no-empty-interface rule instead
265 'no-missing-visibility-modifiers': false, // use tslint member-access rule instead
266 'no-multiple-var-decl': false, // use tslint one-variable-per-declaration rule instead
267 'no-stateless-class': false,
268 'no-switch-case-fall-through': false, // now supported by TypeScript compiler
269 'no-unnecessary-class': true,
270 'no-var-self': false,
271 'react-tsx-curly-spacing': false,
272 'typeof-compare': false, // the valid-typeof rule is currently superior to this version
273 'valid-typeof': false,
274 }
275};