.eslintrc.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // 2015 December 1
  2. // https://github.com/bevry/base
  3. // http://eslint.org
  4. /* eslint no-warning-comments: 0 */
  5. 'use strict'
  6. const IGNORE = 0, WARN = 1, ERROR = 2, MAX_PARAMS = 4
  7. module.exports = {
  8. // parser: 'babel-eslint',
  9. // ^ the bundled ESLINT parser is now actually quite good, and supports the ecmaFeatures property
  10. ecmaFeatures: {
  11. // this property only works with the bundled ESLINT parser, not babel-eslint
  12. arrowFunctions: true,
  13. binaryLiterals: true,
  14. blockBindings: true,
  15. classes: true,
  16. defaultParams: true,
  17. destructuring: true,
  18. forOf: true,
  19. generators: true,
  20. modules: false, // Disabled due to https://twitter.com/balupton/status/671519915795345410
  21. objectLiteralComputedProperties: true,
  22. objectLiteralDuplicateProperties: true,
  23. objectLiteralShorthandMethods: true,
  24. objectLiteralShorthandProperties: true,
  25. octalLiterals: true,
  26. regexUFlag: true,
  27. regexYFlag: true,
  28. restParams: true,
  29. spread: true,
  30. superInFunctions: true,
  31. templateStrings: true,
  32. unicodeCodePointEscapes: true,
  33. globalReturn: true,
  34. jsx: true,
  35. experimentalObjectRestSpread: true
  36. },
  37. env: {
  38. browser: true,
  39. node: true,
  40. es6: true,
  41. commonjs: true,
  42. amd: true
  43. },
  44. rules: {
  45. // ----------------------------
  46. // Problems with these rules
  47. // If we can figure out how to enable the following, that would be great
  48. // Two spaces after one line if or else:
  49. // if ( blah ) return
  50. // Insead of one space:
  51. // if ( blah ) return
  52. // No spaces on embedded function:
  53. // .forEach(function(key, value){
  54. // instead of:
  55. // .forEach(function (key, value) {
  56. // Else and catch statements on the same line as closing brace:
  57. // } else {
  58. // } catch (e) {
  59. // instead of:
  60. // }
  61. // else {
  62. // --------------------------------------
  63. // Possible Errors
  64. // The following rules point out areas where you might have made mistakes.
  65. // ES6 supports dangling commas
  66. 'comma-dangle': IGNORE,
  67. // Don't allow assignments in conditional statements (if, while, etc.)
  68. 'no-cond-assign': [ERROR, 'always'],
  69. // Warn but don't error about console statements
  70. 'no-console': WARN,
  71. // Allow while(true) loops
  72. 'no-constant-condition': IGNORE,
  73. // Seems like a good idea to error about this
  74. 'no-control-regex': ERROR,
  75. // Warn but don't error about console statements
  76. 'no-debugger': WARN,
  77. // Don't allow duplicate arguments in a function, they can cause errors
  78. 'no-dupe-args': ERROR,
  79. // Disallow duplicate keys in an object, they can cause errors
  80. 'no-dupe-keys': ERROR,
  81. // Disallow duplicate case statements in a switch
  82. 'no-duplicate-case': ERROR,
  83. // Disallow empty [] in regular expressions as they cause unexpected behaviour
  84. 'no-empty-character-class': ERROR,
  85. // Allow empty block statements, they are useful for clarity
  86. 'no-empty': IGNORE,
  87. // Overwriting the exception argument in a catch statement can cause memory leaks in some browsers
  88. 'no-ex-assign': ERROR,
  89. // Disallow superflous boolean casts, they offer no value
  90. 'no-extra-boolean-cast': ERROR,
  91. // Allow superflous parenthesis as they offer clarity in some cases
  92. 'no-extra-parens': IGNORE,
  93. // Disallow superflous semicolons, they offer no value
  94. 'no-extra-semi': IGNORE,
  95. // Seems like a good idea to error about this
  96. 'no-func-assign': ERROR,
  97. // Seems like a good idea to error about this
  98. 'no-inner-declarations': ERROR,
  99. // Seems like a good idea to error about this
  100. 'no-invalid-regexp': ERROR,
  101. // Seems like a good idea to error about this
  102. 'no-irregular-whitespace': ERROR,
  103. // Seems like a good idea to error about this
  104. 'no-negated-in-lhs': ERROR,
  105. // Seems like a good idea to error about this
  106. 'no-obj-calls': ERROR,
  107. // Seems like a good idea to error about this
  108. // Instead of / / used / {ERROR}/ instead
  109. 'no-regex-spaces': ERROR,
  110. // Seems like a good idea to error about this
  111. 'no-sparse-arrays': ERROR,
  112. // Seems like a good idea to error about this
  113. 'no-unexpected-multiline': ERROR,
  114. // Seems like a good idea to error about this
  115. 'no-unreachable': ERROR,
  116. // Seems like a good idea to error about this
  117. 'use-isnan': ERROR,
  118. // We use YUIdoc, not JSDoc
  119. 'valid-jsdoc': IGNORE,
  120. // Seems like a good idea to error about this
  121. 'valid-typeof': ERROR,
  122. // --------------------------------------
  123. // Best Practices
  124. // These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
  125. // Meh
  126. 'accessor-pairs': IGNORE,
  127. // This rule seems buggy
  128. 'block-scoped-var': IGNORE,
  129. // Disable complexity checks, they are annoying and not that useful in detecting actual complexity
  130. 'complexity': IGNORE,
  131. // We use blank returns for break statements
  132. 'consistent-return': IGNORE,
  133. // Always require curly braces unless the statement is all on a single line
  134. 'curly': [ERROR, 'multi-line'],
  135. // If we don't have a default cause, it probably means we should throw an error
  136. 'default-case': ERROR,
  137. // Dots should be on the newlines
  138. // chainableThingy
  139. // .doSomething()
  140. // .doSomethingElse()
  141. 'dot-location': [ERROR, 'property'],
  142. // Use dot notation where possible
  143. 'dot-notation': ERROR,
  144. // Unless you are doing == null, then force === to avoid truthy/falsey mistakes
  145. 'eqeqeq': [ERROR, 'allow-null'],
  146. // Always use hasOwnProperty when doing for in
  147. 'guard-for-in': ERROR,
  148. // Warn about alert statements in our code
  149. // Use one of the suggested alternatives instead
  150. // Reasoning is they could be mistaken for left over debugging statements
  151. 'no-alert': WARN,
  152. // They are very slow
  153. 'no-caller': ERROR,
  154. // Wow...
  155. 'no-case-declarations': ERROR,
  156. // Seems like a good idea to error about this
  157. 'no-div-regex': ERROR,
  158. // Returns in else statements offer code clarity, so disable this rule
  159. 'no-else-return': IGNORE,
  160. // Seems like a good idea to error about this
  161. 'no-empty-label': ERROR,
  162. // Seems sensible
  163. 'no-empty-pattern': ERROR,
  164. // We know that == null is a null and undefined check
  165. 'no-eq-null': IGNORE,
  166. // Eval is slow and unsafe, use vm's instead
  167. 'no-eval': ERROR,
  168. // There is never a good reason for this
  169. 'no-extend-native': ERROR,
  170. // Don't allow useless binds
  171. 'no-extra-bind': ERROR,
  172. // Don't allow switch case statements to follow through, use continue keyword instead
  173. 'no-fallthrough': ERROR,
  174. // Use zero when doing decimals, otherwise it is confusing
  175. 'no-floating-decimal': ERROR,
  176. // Cleverness is unclear
  177. 'no-implicit-coercion': ERROR,
  178. // A sneaky way to do evals
  179. 'no-implied-eval': ERROR,
  180. // This throws for a lot of senseless things, like chainy functions
  181. 'no-invalid-this': IGNORE,
  182. // Use proper iterators instead
  183. 'no-iterator': ERROR,
  184. // We never use this, it seems silly to allow this
  185. 'no-labels': ERROR,
  186. // We never use this, it seems silly to allow this
  187. 'no-lone-blocks': ERROR,
  188. // Loop functions always cause problems, as the scope isn't clear through iterations
  189. 'no-loop-func': ERROR,
  190. // This is a great idea
  191. // Although ignore -1 and 0 as it is common with indexOf
  192. 'no-magic-numbers': [WARN, { ignore: [-1, 0] }],
  193. // We like multi spaces for clarity
  194. // E.g. We like
  195. // if ( blah ) return foo
  196. // Instead of:
  197. // if ( blah ) return foo
  198. // @TODO would be great to enforce the above
  199. 'no-multi-spaces': IGNORE,
  200. // Use ES6 template strings instead
  201. 'no-multi-str': ERROR,
  202. // Would be silly to allow this
  203. 'no-native-reassign': ERROR,
  204. // We never use this, it seems silly to allow this
  205. 'no-new-func': ERROR,
  206. // We never use this, it seems silly to allow this
  207. 'no-new-wrappers': ERROR,
  208. // We never use this, it seems silly to allow this
  209. 'no-new': ERROR,
  210. // We never use this, it seems silly to allow this
  211. 'no-octal-escape': ERROR,
  212. // We never use this, it seems silly to allow this
  213. 'no-octal': ERROR,
  214. // We got to be pretty silly if we don't realise we are doing this
  215. // As such, take any usage as intentional and aware
  216. 'no-param-reassign': IGNORE,
  217. // We use process.env wisely
  218. 'no-process-env': IGNORE,
  219. // We never use this, it seems silly to allow this
  220. 'no-proto': ERROR,
  221. // We never use this, it seems silly to allow this
  222. 'no-redeclare': ERROR,
  223. // We never use this, it seems silly to allow this
  224. 'no-return-assign': ERROR,
  225. // We never use this, it seems silly to allow this
  226. 'no-script-url': ERROR,
  227. // We never use this, it seems silly to allow this
  228. 'no-self-compare': ERROR,
  229. // We never use this, it seems silly to allow this
  230. 'no-sequences': ERROR,
  231. // We always want proper error objects as they have stack traces and respond to instanceof Error checks
  232. 'no-throw-literal': ERROR,
  233. // We never use this, it seems silly to allow this
  234. 'no-unused-expressions': ERROR,
  235. // Seems sensible
  236. 'no-useless-call': ERROR,
  237. // Seems sensible
  238. 'no-useless-concat': ERROR,
  239. // We never use this, it seems silly to allow this
  240. 'no-void': ERROR,
  241. // Warn about todos
  242. 'no-warning-comments': [WARN, { terms: ['todo', 'fixme'], location: 'anywhere' }],
  243. // We never use this, it seems silly to allow this
  244. 'no-with': ERROR,
  245. // Always specify a radix to avoid errors
  246. 'radix': ERROR,
  247. // We appreciate the clarity late defines offer
  248. 'vars-on-top': IGNORE,
  249. // Wrap instant called functions in parenthesis for clearer intent
  250. 'wrap-iife': ERROR,
  251. // Because we force === and never allow assignments in conditions
  252. // we have no need for yoda statements, so disable them
  253. 'yoda': [ERROR, 'never'],
  254. // --------------------------------------
  255. // Strict Mode
  256. // These rules relate to using strict mode.
  257. // Ensure that use strict is specified to prevent the runtime erorr:
  258. // SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
  259. 'strict': [ERROR, 'global'],
  260. // --------------------------------------
  261. // Variables
  262. // These rules have to do with variable declarations.
  263. // We don't care
  264. 'init-declaration': IGNORE,
  265. // Don't allow the catch method to shadow objects as browsers handle this differently
  266. // Update: We don't care for IE8
  267. 'no-catch-shadow': IGNORE,
  268. // Don't use delete, it disables optimisations
  269. 'no-delete-var': ERROR,
  270. // We never use this, it seems silly to allow this
  271. 'no-label-var': ERROR,
  272. // We never use this, it seems silly to allow this
  273. 'no-shadow-restricted-names': ERROR,
  274. // We use shadowing
  275. 'no-shadow': IGNORE,
  276. // Makes sense
  277. 'no-undef-init': ERROR,
  278. // Error when an undefined variable is used
  279. 'no-undef': ERROR,
  280. // typeof blah === 'undefined' should always be used
  281. 'no-undefined': ERROR,
  282. // Warn us when we don't use something
  283. 'no-unused-vars': WARN,
  284. // Error when we try and use something before it is defined
  285. 'no-use-before-define': ERROR,
  286. // --------------------------------------
  287. // Node.js and CommonJS
  288. // These rules are specific to JavaScript running on Node.js or using CommonJS in the browser.
  289. // Seems to difficult to enforce
  290. 'callback-return': IGNORE,
  291. // We use require where it is appropriate to use it
  292. 'global-require': IGNORE,
  293. // Force handling of callback errors
  294. 'handle-callback-err': ERROR,
  295. // @TODO decide if this is good or not
  296. 'no-mixed-requires': ERROR,
  297. // Disallow error prone syntax
  298. 'no-new-require': ERROR,
  299. // Always use path.join for windows support
  300. 'no-path-concat': ERROR,
  301. // We know what we are doing
  302. 'no-process-exit': IGNORE,
  303. // No need to disallow any modules
  304. 'no-restricted-modules': IGNORE,
  305. // Sometimes sync methods are useful, so warn but don't error
  306. 'no-sync': WARN,
  307. // --------------------------------------
  308. // Stylistic
  309. // These rules are purely matters of style and are quite subjective.
  310. // We don't use spaces with brackets
  311. 'array-bracket-spacing': [ERROR, 'never'],
  312. // Disallow or enforce spaces inside of single line blocks
  313. 'block-spacing': [ERROR, 'always'],
  314. // Opening brace on same line, closing brace on its own line, except when statement is a single line
  315. 'brace-style': [ERROR, 'stroustrup', { allowSingleLine: true }],
  316. // Use camel case
  317. 'camelcase': ERROR,
  318. // Require a comma after always
  319. 'comma-spacing': [ERROR, { before: false, after: true }],
  320. // Commas go last, we have tooling to detect if we forget a comma
  321. 'comma-style': [ERROR, 'last'],
  322. // Require or disallow padding inside computed properties
  323. 'computed-property-spacing': [ERROR, 'never'],
  324. // Enabling this was incredibly annoying when doing layers of nesting
  325. 'consistent-this': IGNORE,
  326. // Enable to make UNIX people's lives easier
  327. 'eol-last': ERROR,
  328. // We like anonymous functions
  329. 'func-names': IGNORE,
  330. // Prefer to define functions via variables
  331. 'func-style': [WARN, 'declaration'],
  332. // Sometimes short names are appropriate
  333. 'id-length': IGNORE,
  334. // Camel case handles this for us
  335. 'id-match': IGNORE,
  336. // Use tabs and indent case blocks
  337. 'indent': [ERROR, 'tab', { SwitchCase: WARN }],
  338. // Prefer double qoutes for JSX properties: <a b="c" />, <a b='"' />
  339. 'jsx-quotes': [ERROR, 'prefer-double'],
  340. // Space after the colon
  341. 'key-spacing': [ERROR, {
  342. beforeColon: false,
  343. afterColon: true
  344. }],
  345. // Enforce unix line breaks
  346. 'linebreak-style': [ERROR, 'unix'],
  347. // Enforce new lines before block comments
  348. 'lines-around-comment': [ERROR, { beforeBlockComment: true, allowBlockStart: true }],
  349. // Disabled to ensure consistency with complexity option
  350. 'max-depth': IGNORE,
  351. // We use soft wrap
  352. 'max-len': IGNORE,
  353. // We are smart enough to know if this is bad or not
  354. 'max-nested-callbacks': IGNORE,
  355. // Sometimes we have no control over this for compat reasons, so just warn
  356. 'max-params': [WARN, MAX_PARAMS],
  357. // We should be able to use whatever feels right
  358. 'max-statements': IGNORE,
  359. // Constructors should be CamelCase
  360. 'new-cap': ERROR,
  361. // Always use parens when instantiating a class
  362. 'new-parens': ERROR,
  363. // Too difficult to enforce correctly as too many edge-cases
  364. 'newline-after-var': IGNORE,
  365. // Don't use the array constructor when it is not needed
  366. 'no-array-constructor': ERROR,
  367. // We never use bitwise, they are too clever
  368. 'no-bitwise': ERROR,
  369. // We use continue
  370. 'no-continue': IGNORE,
  371. // We like inline comments
  372. 'no-inline-comments': IGNORE,
  373. // The code could be optimised if this error occurs
  374. 'no-lonely-if': ERROR,
  375. // Don't mix spaces and tabs
  376. // @TODO maybe [ERROR, 'smart-tabs'] will be better, we will see
  377. 'no-mixed-spaces-and-tabs': ERROR,
  378. // We use multiple empty lines for styling
  379. 'no-multiple-empty-lines': IGNORE,
  380. // Sometimes it is more understandable with a negated condition
  381. 'no-negated-condition': IGNORE,
  382. // Sometimes these are useful
  383. 'no-nested-ternary': IGNORE,
  384. // Use {} instead of new Object()
  385. 'no-new-object': ERROR,
  386. // We use plus plus
  387. 'no-plusplus': IGNORE,
  388. // Handled by other rules
  389. 'no-restricted-syntax': IGNORE,
  390. // We never use this, it seems silly to allow this
  391. 'no-spaced-func': ERROR,
  392. // Sometimes ternaries are useful
  393. 'no-ternary': IGNORE,
  394. // Disallow trailing spaces
  395. 'no-trailing-spaces': ERROR,
  396. // Sometimes this is useful when avoiding shadowing
  397. 'no-underscore-dangle': IGNORE,
  398. // Sensible
  399. 'no-unneeded-ternary': ERROR,
  400. // Desirable, but too many edge cases it turns out where it is actually preferred
  401. 'object-curly-spacing': IGNORE, // [ERROR, 'always'],
  402. // We like multiple var statements
  403. 'one-var': IGNORE,
  404. // Force use of shorthands when available
  405. 'operator-assignment': [ERROR, 'always'],
  406. // Should be before, but not with =, *=, /=, += lines
  407. // @TODO figure out how to enforce
  408. 'operator-linebreak': IGNORE,
  409. // This rule doesn't appear to work correclty
  410. 'padded-blocks': IGNORE,
  411. // Seems like a good idea to error about this
  412. 'quote-props': [ERROR, 'consistent-as-needed'],
  413. // Use single quotes where escaping isn't needed
  414. 'quotes': [ERROR, 'single', 'avoid-escape'],
  415. // We use YUIdoc
  416. 'require-jsdoc': IGNORE,
  417. // If semi's are used, then add spacing after
  418. 'semi-spacing': [ERROR, { before: false, after: true }],
  419. // Never use semicolons
  420. 'semi': [ERROR, 'never'],
  421. // We don't care if our vars are alphabetical
  422. 'sort-vars': IGNORE,
  423. // Always force a space after a keyword
  424. 'space-after-keywords': [ERROR, 'always'],
  425. // Always force a space before a {
  426. 'space-before-blocks': [ERROR, 'always'],
  427. // function () {, get blah () {
  428. 'space-before-function-paren': [ERROR, 'always'],
  429. // We do this
  430. 'space-before-keywords': [ERROR, 'always'],
  431. // This is for spacing between [], so [ WARN, ERROR, 3 ] which we don't want
  432. 'space-in-brackets': IGNORE,
  433. // This is for spacing between (), so doSomething( WARN, ERROR, 3 ) or if ( WARN === 3 )
  434. // which we want for ifs, but don't want for calls
  435. 'space-in-parens': IGNORE,
  436. // We use this
  437. 'space-infix-ops': ERROR,
  438. // We use this
  439. 'space-return-throw-case': ERROR,
  440. // We use this
  441. 'space-unary-ops': ERROR,
  442. // We use this
  443. // 'spaced-line-comment': ERROR,
  444. 'spaced-comment': ERROR,
  445. // We use this
  446. // @TODO revise this
  447. 'wrap-regex': ERROR,
  448. // --------------------------------------
  449. // ECMAScript 6
  450. // Sensible to create more informed and clear code
  451. 'arrow-body-style': [ERROR, 'as-needed'],
  452. // We do this, no reason why, just what we do
  453. 'arrow-parens': [ERROR, 'always'],
  454. // Require consistent spacing for arrow functions
  455. 'arrow-spacing': ERROR,
  456. // Makes sense as otherwise runtime error will occur
  457. 'constructor-super': ERROR,
  458. // Seems the most consistent location for it
  459. 'generator-star-spacing': [ERROR, 'before'],
  460. // Seems sensible
  461. 'no-arrow-condition': ERROR,
  462. // Seems sensible
  463. 'no-class-assign': ERROR,
  464. // Makes sense as otherwise runtime error will occur
  465. 'no-const-assign': ERROR,
  466. // Makes sense as otherwise runtime error will occur
  467. 'no-dupe-class-members': ERROR,
  468. // Makes sense as otherwise runtime error will occur
  469. 'no-this-before-super': ERROR,
  470. // @TODO This probably should be an error
  471. // however it is useful for: for ( var key in obj ) {
  472. // which hopefully is more performant than let (@TODO check if it actually is more performant)
  473. 'no-var': WARN,
  474. // Enforce ES6 object shorthand
  475. 'object-shorthand': ERROR,
  476. // Better performance when running native
  477. // but horrible performance if not running native as could fallback to bind
  478. // https://travis-ci.org/bevry/es6-benchmarks
  479. 'prefer-arrow-callback': IGNORE,
  480. // Sure, why not
  481. 'prefer-const': WARN,
  482. // Controversial change, but makes sense to move towards to reduce the risk of bad people overwriting apply and call
  483. // https://github.com/eslint/eslint/issues/ERROR939
  484. 'prefer-reflect': WARN,
  485. // Sure, why not
  486. 'prefer-spread': ERROR,
  487. // Too annoying to enforce
  488. 'prefer-template': IGNORE,
  489. // Makes sense
  490. 'require-yield': ERROR
  491. }
  492. }