.eslintrc.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. "use strict";
  2. module.exports = {
  3. "plugins": [
  4. "react"
  5. ],
  6. "globals": {
  7. "atob": true,
  8. "btoa": true,
  9. "Components": true,
  10. "CSSRule": true,
  11. "clearInterval": true,
  12. "clearTimeout": true,
  13. "console": true,
  14. "CSS": true,
  15. "DocumentFragment": true,
  16. "DOMParser": true,
  17. "dump": true,
  18. "Element": true,
  19. "exports": true,
  20. "isWorker": true,
  21. "indexedDB": true,
  22. "loader": true,
  23. "module": true,
  24. "Node": true,
  25. "reportError": true,
  26. "require": true,
  27. "setInterval": true,
  28. "setTimeout": true,
  29. "uneval": true,
  30. "URL": true,
  31. "WebSocket": true,
  32. "XMLHttpRequest": true,
  33. },
  34. "rules": {
  35. // These are the rules that have been configured so far to match the
  36. // devtools coding style.
  37. // Rules from the mozilla plugin
  38. "mozilla/no-aArgs": "warn",
  39. "mozilla/no-cpows-in-tests": "error",
  40. "mozilla/no-single-arg-cu-import": "error",
  41. // See bug 1224289.
  42. "mozilla/reject-importGlobalProperties": "error",
  43. // devtools/shared/platform is special; see the README.md in that
  44. // directory for details. We reject requires using explicit
  45. // subdirectories of this directory.
  46. "mozilla/reject-some-requires": ["error", "^devtools/shared/platform/(chome|content)/"],
  47. "mozilla/var-only-at-top-level": "warn",
  48. // Rules from the React plugin
  49. "react/display-name": "error",
  50. "react/no-danger": "error",
  51. "react/no-did-mount-set-state": "error",
  52. "react/no-did-update-set-state": "error",
  53. "react/no-direct-mutation-state": "error",
  54. "react/no-unknown-property": "error",
  55. "react/prefer-es6-class": ["warn", "never"],
  56. // Disabled temporarily until errors are fixed.
  57. "react/prop-types": "off",
  58. "react/sort-comp": ["error", {
  59. order: [
  60. "lifecycle",
  61. "everything-else",
  62. "render"
  63. ],
  64. groups: {
  65. lifecycle: [
  66. "displayName",
  67. "propTypes",
  68. "contextTypes",
  69. "childContextTypes",
  70. "mixins",
  71. "statics",
  72. "defaultProps",
  73. "constructor",
  74. "getDefaultProps",
  75. "getInitialState",
  76. "state",
  77. "getChildContext",
  78. "componentWillMount",
  79. "componentDidMount",
  80. "componentWillReceiveProps",
  81. "shouldComponentUpdate",
  82. "componentWillUpdate",
  83. "componentDidUpdate",
  84. "componentWillUnmount"
  85. ]
  86. }
  87. }],
  88. // Disallow using variables outside the blocks they are defined (especially
  89. // since only let and const are used, see "no-var").
  90. "block-scoped-var": "error",
  91. // Enforce one true brace style (opening brace on the same line) and avoid
  92. // start and end braces on the same line.
  93. "brace-style": ["error", "1tbs", {"allowSingleLine": false}],
  94. // Require camel case names
  95. "camelcase": "error",
  96. // Allow trailing commas for easy list extension. Having them does not
  97. // impair readability, but also not required either.
  98. "comma-dangle": "off",
  99. // Enforce spacing before and after comma
  100. "comma-spacing": ["error", {"before": false, "after": true}],
  101. // Enforce one true comma style.
  102. "comma-style": ["error", "last"],
  103. // Warn about cyclomatic complexity in functions.
  104. "complexity": ["error", 35],
  105. // Require return statements to either always or never specify values.
  106. "consistent-return": "error",
  107. // Don't warn for inconsistent naming when capturing this (not so important
  108. // with auto-binding fat arrow functions).
  109. "consistent-this": "off",
  110. // Enforce curly brace conventions for all control statements.
  111. "curly": "error",
  112. // Don't require a default case in switch statements. Avoid being forced to
  113. // add a bogus default when you know all possible cases are handled.
  114. "default-case": "off",
  115. // Enforce dots on the next line with property name.
  116. "dot-location": ["error", "property"],
  117. // Encourage the use of dot notation whenever possible.
  118. "dot-notation": "error",
  119. // Enforce newline at the end of file, with no multiple empty lines.
  120. "eol-last": "error",
  121. // Allow using == instead of ===, in the interest of landing something since
  122. // the devtools codebase is split on convention here.
  123. "eqeqeq": "off",
  124. // Don't require function expressions to have a name.
  125. // This makes the code more verbose and hard to read. Our engine already
  126. // does a fantastic job assigning a name to the function, which includes
  127. // the enclosing function name, and worst case you have a line number that
  128. // you can just look up.
  129. "func-names": "off",
  130. // Allow use of function declarations and expressions.
  131. "func-style": "off",
  132. // Deprecated, will be removed in 1.0.
  133. "generator-star": "off",
  134. // Enforce the spacing around the * in generator functions.
  135. "generator-star-spacing": ["error", "after"],
  136. // Deprecated, will be removed in 1.0.
  137. "global-strict": "off",
  138. // Only useful in a node environment.
  139. "handle-callback-err": "off",
  140. // Tab width.
  141. "indent": ["error", 2, {"SwitchCase": 1}],
  142. // Enforces spacing between keys and values in object literal properties.
  143. "key-spacing": ["error", {"beforeColon": false, "afterColon": true}],
  144. // Enforces unix style line breaks.
  145. "linebreak-style": ["error", "unix"],
  146. // Don't enforce the maximum depth that blocks can be nested. The complexity
  147. // rule is a better rule to check this.
  148. "max-depth": "off",
  149. // Maximum length of a line.
  150. "max-len": ["error", 90, 2, {
  151. "ignoreUrls": true,
  152. "ignorePattern": "data:image\/|\\s*require\\s*\\(|^\\s*loader\\.lazy|-\\*-"
  153. }],
  154. // Maximum depth callbacks can be nested.
  155. "max-nested-callbacks": ["error", 3],
  156. // Don't limit the number of parameters that can be used in a function.
  157. "max-params": "off",
  158. // Don't limit the maximum number of statement allowed in a function. We
  159. // already have the complexity rule that's a better measurement.
  160. "max-statements": "off",
  161. // Require a capital letter for constructors, only check if all new
  162. // operators are followed by a capital letter. Don't warn when capitalized
  163. // functions are used without the new operator.
  164. "new-cap": ["error", {"capIsNew": false}],
  165. // Disallow the omission of parentheses when invoking a constructor with no
  166. // arguments.
  167. "new-parens": "error",
  168. // Disallow use of the Array constructor.
  169. "no-array-constructor": "error",
  170. // Allow use of bitwise operators.
  171. "no-bitwise": "off",
  172. // Disallow use of arguments.caller or arguments.callee.
  173. "no-caller": "error",
  174. // Disallow the catch clause parameter name being the same as a variable in
  175. // the outer scope, to avoid confusion.
  176. "no-catch-shadow": "error",
  177. // Deprecated, will be removed in 1.0.
  178. "no-comma-dangle": "off",
  179. // Disallow assignment in conditional expressions.
  180. "no-cond-assign": "error",
  181. // Allow using the console API.
  182. "no-console": "off",
  183. // Allow using constant expressions in conditions like while (true)
  184. "no-constant-condition": "off",
  185. // Allow use of the continue statement.
  186. "no-continue": "off",
  187. // Disallow control characters in regular expressions.
  188. "no-control-regex": "error",
  189. // Disallow use of debugger.
  190. "no-debugger": "error",
  191. // Disallow deletion of variables (deleting properties is fine).
  192. "no-delete-var": "error",
  193. // Allow division operators explicitly at beginning of regular expression.
  194. "no-div-regex": "off",
  195. // Disallow duplicate arguments in functions.
  196. "no-dupe-args": "error",
  197. // Disallow duplicate keys when creating object literals.
  198. "no-dupe-keys": "error",
  199. // Disallow a duplicate case label.
  200. "no-duplicate-case": "error",
  201. // Disallow else after a return in an if. The else around the second return
  202. // here is useless:
  203. // if (something) { return false; } else { return true; }
  204. "no-else-return": "error",
  205. // Disallow empty statements. This will report an error for:
  206. // try { something(); } catch (e) {}
  207. // but will not report it for:
  208. // try { something(); } catch (e) { /* Silencing the error because ...*/ }
  209. // which is a valid use case.
  210. "no-empty": "error",
  211. // Disallow the use of empty character classes in regular expressions.
  212. "no-empty-character-class": "error",
  213. // Disallow use of eval(). We have other APIs to evaluate code in content.
  214. "no-eval": "error",
  215. // Disallow assigning to the exception in a catch block.
  216. "no-ex-assign": "error",
  217. // Disallow adding to native types
  218. "no-extend-native": "error",
  219. // Disallow unnecessary function binding.
  220. "no-extra-bind": "error",
  221. // Disallow double-negation boolean casts in a boolean context.
  222. "no-extra-boolean-cast": "error",
  223. // Allow unnecessary parentheses, as they may make the code more readable.
  224. "no-extra-parens": "off",
  225. // Disallow unnecessary semicolons.
  226. "no-extra-semi": "error",
  227. // Deprecated, will be removed in 1.0.
  228. "no-extra-strict": "off",
  229. // Disallow fallthrough of case statements, except if there is a comment.
  230. "no-fallthrough": "error",
  231. // Allow the use of leading or trailing decimal points in numeric literals.
  232. "no-floating-decimal": "off",
  233. // Disallow comments inline after code.
  234. "no-inline-comments": "error",
  235. // Disallow if as the only statement in an else block.
  236. "no-lonely-if": "error",
  237. // Allow mixing regular variable and require declarations (not a node env).
  238. "no-mixed-requires": "off",
  239. // Disallow mixed spaces and tabs for indentation.
  240. "no-mixed-spaces-and-tabs": "error",
  241. // Disallow use of multiple spaces (sometimes used to align const values,
  242. // array or object items, etc.). It's hard to maintain and doesn't add that
  243. // much benefit.
  244. "no-multi-spaces": "error",
  245. // Disallow use of multiline strings (use template strings instead).
  246. "no-multi-str": "error",
  247. // Disallow multiple empty lines.
  248. "no-multiple-empty-lines": ["error", {"max": 1}],
  249. // Disallow reassignments of native objects.
  250. "no-native-reassign": "error",
  251. // Disallow nested ternary expressions, they make the code hard to read.
  252. "no-nested-ternary": "error",
  253. // Allow use of new operator with the require function.
  254. "no-new-require": "off",
  255. // Disallow use of octal literals.
  256. "no-octal": "error",
  257. // Allow reassignment of function parameters.
  258. "no-param-reassign": "off",
  259. // Allow string concatenation with __dirname and __filename (not a node env).
  260. "no-path-concat": "off",
  261. // Allow use of unary operators, ++ and --.
  262. "no-plusplus": "off",
  263. // Allow using process.env (not a node environment).
  264. "no-process-env": "off",
  265. // Allow using process.exit (not a node environment).
  266. "no-process-exit": "off",
  267. // Disallow usage of __proto__ property.
  268. "no-proto": "error",
  269. // Disallow declaring the same variable more than once (we use let anyway).
  270. "no-redeclare": "error",
  271. // Disallow multiple spaces in a regular expression literal.
  272. "no-regex-spaces": "error",
  273. // Allow reserved words being used as object literal keys.
  274. "no-reserved-keys": "off",
  275. // Don't restrict usage of specified node modules (not a node environment).
  276. "no-restricted-modules": "off",
  277. // Disallow use of assignment in return statement. It is preferable for a
  278. // single line of code to have only one easily predictable effect.
  279. "no-return-assign": "error",
  280. // Allow use of javascript: urls.
  281. "no-script-url": "off",
  282. // Disallow comparisons where both sides are exactly the same.
  283. "no-self-compare": "error",
  284. // Disallow use of comma operator.
  285. "no-sequences": "error",
  286. // Warn about declaration of variables already declared in the outer scope.
  287. // This isn't an error because it sometimes is useful to use the same name
  288. // in a small helper function rather than having to come up with another
  289. // random name.
  290. // Still, making this a warning can help people avoid being confused.
  291. "no-shadow": "error",
  292. // Disallow shadowing of names such as arguments.
  293. "no-shadow-restricted-names": "error",
  294. // Deprecated, will be removed in 1.0.
  295. "no-space-before-semi": "off",
  296. // Disallow space between function identifier and application.
  297. "no-spaced-func": "error",
  298. // Disallow sparse arrays, eg. let arr = [,,2].
  299. // Array destructuring is fine though:
  300. // for (let [, breakpointPromise] of aPromises)
  301. "no-sparse-arrays": "error",
  302. // Allow use of synchronous methods (not a node environment).
  303. "no-sync": "off",
  304. // Allow the use of ternary operators.
  305. "no-ternary": "off",
  306. // Disallow throwing literals (eg. throw "error" instead of
  307. // throw new Error("error")).
  308. "no-throw-literal": "error",
  309. // Disallow trailing whitespace at the end of lines.
  310. "no-trailing-spaces": "error",
  311. // Disallow use of undeclared variables unless mentioned in a /*global */
  312. // block. Note that globals from head.js are automatically imported in tests
  313. // by the import-headjs-globals rule form the mozilla eslint plugin.
  314. "no-undef": "error",
  315. // Allow dangling underscores in identifiers (for privates).
  316. "no-underscore-dangle": "off",
  317. // Allow use of undefined variable.
  318. "no-undefined": "off",
  319. // Disallow the use of Boolean literals in conditional expressions.
  320. "no-unneeded-ternary": "error",
  321. // Disallow unreachable statements after a return, throw, continue, or break
  322. // statement.
  323. "no-unreachable": "error",
  324. // Disallow global and local variables that aren't used, but allow unused
  325. // function arguments.
  326. "no-unused-vars": ["error", {"vars": "all", "args": "none"}],
  327. // Allow using variables before they are defined.
  328. "no-use-before-define": "off",
  329. // We use var-only-at-top-level instead of no-var as we allow top level
  330. // vars.
  331. "no-var": "off",
  332. // Allow using TODO/FIXME comments.
  333. "no-warning-comments": "off",
  334. // Disallow use of the with statement.
  335. "no-with": "error",
  336. // Don't require method and property shorthand syntax for object literals.
  337. // We use this in the code a lot, but not consistently, and this seems more
  338. // like something to check at code review time.
  339. "object-shorthand": "off",
  340. // Allow more than one variable declaration per function.
  341. "one-var": "off",
  342. // Disallow padding within blocks.
  343. "padded-blocks": ["error", "never"],
  344. // Don't require quotes around object literal property names.
  345. "quote-props": "off",
  346. // Double quotes should be used. Other quote characters can be used around strings
  347. // with embedded double quotes to avoid escaping them. Template literals are allowed
  348. // mainly for building multi-line messages where only some lines use substitution.
  349. "quotes": ["error", "double", {"avoidEscape": true, "allowTemplateLiterals": true}],
  350. // Require use of the second argument for parseInt().
  351. "radix": "error",
  352. // Always require use of semicolons wherever they are valid.
  353. "semi": ["error", "always"],
  354. // Enforce spacing after semicolons.
  355. "semi-spacing": ["error", {"before": false, "after": true}],
  356. // Don't require to sort variables within the same declaration block.
  357. // Anyway, one-var is disabled.
  358. "sort-vars": "off",
  359. // Deprecated, will be removed in 1.0.
  360. "space-after-function-name": "off",
  361. // Require a space around all keywords.
  362. "keyword-spacing": "error",
  363. // Require a space before the start brace of a block.
  364. "space-before-blocks": ["error", "always"],
  365. // Deprecated, will be removed in 1.0.
  366. "space-before-function-parentheses": "off",
  367. // Require space after keyword for anonymous functions, but disallow space
  368. // after name of named functions.
  369. "space-before-function-paren": ["error", {"anonymous": "always", "named": "never"}],
  370. // Disable the rule that checks if spaces inside {} and [] are there or not.
  371. // Our code is split on conventions, and it'd be nice to have "error" rules
  372. // instead, one for [] and one for {}. So, disabling until we write them.
  373. "space-in-brackets": "off",
  374. // Disallow spaces inside parentheses.
  375. "space-in-parens": ["error", "never"],
  376. // Require spaces around operators, except for a|"off".
  377. "space-infix-ops": ["error", {"int32Hint": true}],
  378. // Require spaces before/after unary operators (words on by default,
  379. // nonwords off by default).
  380. "space-unary-ops": ["error", { "words": true, "nonwords": false }],
  381. // Deprecated, will be removed in 1.0.
  382. "space-unary-word-ops": "off",
  383. // Require a space immediately following the // in a line comment.
  384. "spaced-comment": ["error", "always"],
  385. // Require "use strict" to be defined globally in the script.
  386. "strict": ["error", "global"],
  387. // Disallow comparisons with the value NaN.
  388. "use-isnan": "error",
  389. // Warn about invalid JSDoc comments.
  390. // Disabled for now because of https://github.com/eslint/eslint/issues/2270
  391. // The rule fails on some jsdoc comments like in:
  392. // devtools/client/webconsole/console-output.js
  393. "valid-jsdoc": "off",
  394. // Ensure that the results of typeof are compared against a valid string.
  395. "valid-typeof": "error",
  396. // Allow vars to be declared anywhere in the scope.
  397. "vars-on-top": "off",
  398. // Don't require immediate function invocation to be wrapped in parentheses.
  399. "wrap-iife": "off",
  400. // Don't require regex literals to be wrapped in parentheses (which
  401. // supposedly prevent them from being mistaken for division operators).
  402. "wrap-regex": "off",
  403. // Disallow Yoda conditions (where literal value comes first).
  404. "yoda": "error",
  405. // And these are the rules that haven't been discussed so far, and that are
  406. // disabled for now until we introduce them, one at a time.
  407. // Require for-in loops to have an if statement.
  408. "guard-for-in": "off",
  409. // allow/disallow an empty newline after var statement
  410. "newline-after-var": "off",
  411. // disallow the use of alert, confirm, and prompt
  412. "no-alert": "off",
  413. // disallow comparisons to null without a type-checking operator
  414. "no-eq-null": "off",
  415. // disallow overwriting functions written as function declarations
  416. "no-func-assign": "off",
  417. // disallow use of eval()-like methods
  418. "no-implied-eval": "off",
  419. // disallow function or variable declarations in nested blocks
  420. "no-inner-declarations": "off",
  421. // disallow invalid regular expression strings in the RegExp constructor
  422. "no-invalid-regexp": "off",
  423. // disallow irregular whitespace outside of strings and comments
  424. "no-irregular-whitespace": "off",
  425. // disallow usage of __iterator__ property
  426. "no-iterator": "off",
  427. // disallow labels that share a name with a variable
  428. "no-label-var": "off",
  429. // disallow use of labeled statements
  430. "no-labels": "error",
  431. // disallow unnecessary nested blocks
  432. "no-lone-blocks": "off",
  433. // disallow creation of functions within loops
  434. "no-loop-func": "off",
  435. // disallow negation of the left operand of an in expression
  436. "no-negated-in-lhs": "off",
  437. // disallow use of new operator when not part of the assignment or
  438. // comparison
  439. "no-new": "off",
  440. // disallow use of new operator for Function object
  441. "no-new-func": "off",
  442. // disallow use of the Object constructor
  443. "no-new-object": "off",
  444. // disallows creating new instances of String,Number, and Boolean
  445. "no-new-wrappers": "off",
  446. // disallow the use of object properties of the global object (Math and
  447. // JSON) as functions
  448. "no-obj-calls": "off",
  449. // disallow use of octal escape sequences in string literals, such as
  450. // var foo = "Copyright \251";
  451. "no-octal-escape": "off",
  452. // disallow use of undefined when initializing variables
  453. "no-undef-init": "off",
  454. // disallow usage of expressions in statement position
  455. "no-unused-expressions": "off",
  456. // disallow use of void operator
  457. "no-void": "off",
  458. // disallow wrapping of non-IIFE statements in parens
  459. "no-wrap-func": "off",
  460. // require assignment operator shorthand where possible or prohibit it
  461. // entirely
  462. "operator-assignment": "off",
  463. // enforce operators to be placed before or after line breaks
  464. "operator-linebreak": "off",
  465. }
  466. };