123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright 2017 Palantir Technologies, Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. var path_1 = require("path");
  20. var ruleLoader_1 = require("../ruleLoader");
  21. var utils_1 = require("../utils");
  22. // tslint:disable object-literal-sort-keys
  23. // tslint:disable object-literal-key-quotes
  24. exports.rules = {
  25. // TypeScript Specific
  26. "adjacent-overload-signatures": true,
  27. "ban-types": {
  28. options: [
  29. ["Object", "Avoid using the `Object` type. Did you mean `object`?"],
  30. ["Function", "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."],
  31. ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
  32. ["Number", "Avoid using the `Number` type. Did you mean `number`?"],
  33. ["String", "Avoid using the `String` type. Did you mean `string`?"],
  34. ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"],
  35. ],
  36. },
  37. "member-access": [true, "check-accessor", "check-constructor", "check-parameter-property"],
  38. "member-ordering": [true, {
  39. "order": "statics-first",
  40. "alphabetize": true,
  41. }],
  42. "no-any": true,
  43. "no-empty-interface": true,
  44. "no-import-side-effect": true,
  45. // Technically this is not the strictest setting, but don't want to conflict with "typedef"
  46. "no-inferrable-types": [true, "ignore-params"],
  47. "no-internal-module": true,
  48. "no-magic-numbers": true,
  49. "no-namespace": true,
  50. "no-non-null-assertion": true,
  51. "no-reference": true,
  52. "no-this-assignment": true,
  53. "no-var-requires": true,
  54. "only-arrow-functions": true,
  55. "prefer-for-of": true,
  56. "prefer-readonly": true,
  57. "promise-function-async": true,
  58. "typedef": [
  59. true,
  60. "call-signature",
  61. "arrow-call-signature",
  62. "parameter",
  63. "arrow-parameter",
  64. "property-declaration",
  65. "variable-declaration",
  66. "member-variable-declaration",
  67. ],
  68. "typedef-whitespace": [
  69. true,
  70. {
  71. "call-signature": "nospace",
  72. "index-signature": "nospace",
  73. "parameter": "nospace",
  74. "property-declaration": "nospace",
  75. "variable-declaration": "nospace",
  76. },
  77. {
  78. "call-signature": "onespace",
  79. "index-signature": "onespace",
  80. "parameter": "onespace",
  81. "property-declaration": "onespace",
  82. "variable-declaration": "onespace",
  83. },
  84. ],
  85. "unified-signatures": true,
  86. // Functionality
  87. "await-promise": true,
  88. // "ban": no sensible default
  89. "ban-comma-operator": true,
  90. "curly": true,
  91. "forin": true,
  92. // "import-blacklist": no sensible default
  93. "label-position": true,
  94. "no-arg": true,
  95. "no-bitwise": true,
  96. "no-conditional-assignment": true,
  97. "no-console": true,
  98. "no-construct": true,
  99. "no-debugger": true,
  100. "no-duplicate-super": true,
  101. "no-duplicate-switch-case": true,
  102. "no-duplicate-variable": [
  103. true,
  104. "check-parameters",
  105. ],
  106. "no-dynamic-delete": true,
  107. "no-empty": true,
  108. "no-eval": true,
  109. "no-floating-promises": true,
  110. "no-for-in-array": true,
  111. "no-implicit-dependencies": true,
  112. "no-inferred-empty-object-type": true,
  113. "no-invalid-template-strings": true,
  114. // "no-invalid-this": Won't this be deprecated?
  115. "no-misused-new": true,
  116. "no-null-keyword": true,
  117. "no-object-literal-type-assertion": true,
  118. "no-return-await": true,
  119. "no-shadowed-variable": true,
  120. "no-string-literal": true,
  121. "no-string-throw": true,
  122. "no-sparse-arrays": true,
  123. "no-submodule-imports": true,
  124. "no-unbound-method": true,
  125. "no-unnecessary-class": [true, "allow-empty-class"],
  126. "no-unsafe-any": true,
  127. "no-unsafe-finally": true,
  128. "no-unused-expression": true,
  129. "no-unused-variable": true,
  130. "no-use-before-declare": true,
  131. "no-var-keyword": true,
  132. "no-void-expression": true,
  133. "prefer-conditional-expression": true,
  134. "radix": true,
  135. "restrict-plus-operands": true,
  136. "strict-boolean-expressions": true,
  137. "strict-type-predicates": true,
  138. "switch-default": true,
  139. "triple-equals": true,
  140. "use-default-type-parameter": true,
  141. "use-isnan": true,
  142. // Maintainability
  143. "cyclomatic-complexity": true,
  144. "eofline": true,
  145. "indent": [true, "spaces"],
  146. "linebreak-style": [true, "LF"],
  147. "max-classes-per-file": [true, 1],
  148. "max-file-line-count": [true, 1000],
  149. "max-line-length": [true, 120],
  150. "no-default-export": true,
  151. "no-duplicate-imports": true,
  152. "no-irregular-whitespace": true,
  153. "no-mergeable-namespace": true,
  154. "no-parameter-reassignment": true,
  155. "no-require-imports": true,
  156. "no-trailing-whitespace": true,
  157. "object-literal-sort-keys": true,
  158. "prefer-const": true,
  159. "trailing-comma": [true, {
  160. "multiline": "always",
  161. "singleline": "never",
  162. }],
  163. // Style
  164. "align": [
  165. true,
  166. "parameters",
  167. "arguments",
  168. "statements",
  169. "elements",
  170. "members",
  171. ],
  172. "array-type": [true, "array-simple"],
  173. "arrow-parens": true,
  174. "arrow-return-shorthand": [true, "multiline"],
  175. "binary-expression-operand-order": true,
  176. "callable-types": true,
  177. "class-name": true,
  178. "comment-format": [
  179. true,
  180. "check-space",
  181. "check-uppercase",
  182. ],
  183. "completed-docs": true,
  184. // "file-header": No sensible default
  185. "deprecation": true,
  186. "encoding": true,
  187. "import-spacing": true,
  188. "interface-name": true,
  189. "interface-over-type-literal": true,
  190. "jsdoc-format": [true, "check-multiline-start"],
  191. "match-default-export-name": true,
  192. "new-parens": true,
  193. "newline-before-return": true,
  194. "newline-per-chained-call": true,
  195. "no-angle-bracket-type-assertion": true,
  196. "no-boolean-literal-compare": true,
  197. "no-consecutive-blank-lines": true,
  198. "no-parameter-properties": true,
  199. "no-redundant-jsdoc": true,
  200. "no-reference-import": true,
  201. "no-unnecessary-callback-wrapper": true,
  202. "no-unnecessary-initializer": true,
  203. "no-unnecessary-qualifier": true,
  204. "no-unnecessary-type-assertion": true,
  205. "number-literal-format": true,
  206. "object-literal-key-quotes": [true, "consistent-as-needed"],
  207. "object-literal-shorthand": true,
  208. "one-line": [
  209. true,
  210. "check-catch",
  211. "check-else",
  212. "check-finally",
  213. "check-open-brace",
  214. "check-whitespace",
  215. ],
  216. "one-variable-per-declaration": true,
  217. "ordered-imports": [true, {
  218. "import-sources-order": "case-insensitive",
  219. "named-imports-order": "case-insensitive",
  220. "module-source-path": "full",
  221. }],
  222. "prefer-function-over-method": true,
  223. "prefer-method-signature": true,
  224. "prefer-object-spread": true,
  225. "prefer-switch": true,
  226. "prefer-template": true,
  227. "prefer-while": true,
  228. "quotemark": [
  229. true,
  230. "double",
  231. "avoid-escape",
  232. "avoid-template",
  233. ],
  234. "return-undefined": true,
  235. "semicolon": [true, "always"],
  236. "space-before-function-paren": [true, {
  237. "anonymous": "never",
  238. "asyncArrow": "always",
  239. "constructor": "never",
  240. "method": "never",
  241. "named": "never",
  242. }],
  243. "space-within-parens": [true, 0],
  244. "switch-final-break": true,
  245. "type-literal-delimiter": true,
  246. "variable-name": [
  247. true,
  248. "ban-keywords",
  249. "check-format",
  250. ],
  251. "whitespace": [
  252. true,
  253. "check-branch",
  254. "check-decl",
  255. "check-operator",
  256. "check-module",
  257. "check-separator",
  258. "check-type",
  259. "check-typecast",
  260. "check-preblock",
  261. "check-type-operator",
  262. "check-rest-spread",
  263. ],
  264. };
  265. exports.RULES_EXCLUDED_FROM_ALL_CONFIG = ["ban", "fileHeader", "importBlacklist", "noInvalidThis", "noSwitchCaseFallThrough", "typeofCompare"];
  266. // Exclude typescript-only rules from jsRules, otherwise it's identical.
  267. exports.jsRules = {};
  268. for (var key in exports.rules) {
  269. if (!utils_1.hasOwnProperty(exports.rules, key)) {
  270. continue;
  271. }
  272. var Rule = ruleLoader_1.findRule(key, path_1.join(__dirname, "..", "rules"));
  273. if (Rule === undefined) {
  274. throw new Error("Couldn't find rule '" + key + "'.");
  275. }
  276. if (!Rule.metadata.typescriptOnly) {
  277. exports.jsRules[key] = exports.rules[key];
  278. }
  279. }