style.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. const semver = require('semver');
  2. const eslintPkg = require('eslint/package.json');
  3. module.exports = {
  4. rules: {
  5. // enforce line breaks after opening and before closing array brackets
  6. // https://eslint.org/docs/rules/array-bracket-newline
  7. // TODO: enable? semver-major
  8. 'array-bracket-newline': ['off', 'consistent'], // object option alternative: { multiline: true, minItems: 3 }
  9. // enforce line breaks between array elements
  10. // https://eslint.org/docs/rules/array-element-newline
  11. // TODO: enable? semver-major
  12. 'array-element-newline': ['off', { multiline: true, minItems: 3 }],
  13. // enforce spacing inside array brackets
  14. 'array-bracket-spacing': ['error', 'never'],
  15. // enforce spacing inside single-line blocks
  16. // https://eslint.org/docs/rules/block-spacing
  17. 'block-spacing': ['error', 'always'],
  18. // enforce one true brace style
  19. 'brace-style': ['error', '1tbs', { allowSingleLine: true }],
  20. // require camel case names
  21. camelcase: ['error', { properties: 'never', ignoreDestructuring: false }],
  22. // enforce or disallow capitalization of the first letter of a comment
  23. // https://eslint.org/docs/rules/capitalized-comments
  24. 'capitalized-comments': ['off', 'never', {
  25. line: {
  26. ignorePattern: '.*',
  27. ignoreInlineComments: true,
  28. ignoreConsecutiveComments: true,
  29. },
  30. block: {
  31. ignorePattern: '.*',
  32. ignoreInlineComments: true,
  33. ignoreConsecutiveComments: true,
  34. },
  35. }],
  36. // require trailing commas in multiline object literals
  37. 'comma-dangle': ['error', {
  38. arrays: 'always-multiline',
  39. objects: 'always-multiline',
  40. imports: 'always-multiline',
  41. exports: 'always-multiline',
  42. functions: 'always-multiline',
  43. }],
  44. // enforce spacing before and after comma
  45. 'comma-spacing': ['error', { before: false, after: true }],
  46. // enforce one true comma style
  47. 'comma-style': ['error', 'last', {
  48. exceptions: {
  49. ArrayExpression: false,
  50. ArrayPattern: false,
  51. ArrowFunctionExpression: false,
  52. CallExpression: false,
  53. FunctionDeclaration: false,
  54. FunctionExpression: false,
  55. ImportDeclaration: false,
  56. ObjectExpression: false,
  57. ObjectPattern: false,
  58. VariableDeclaration: false,
  59. NewExpression: false,
  60. }
  61. }],
  62. // disallow padding inside computed properties
  63. 'computed-property-spacing': ['error', 'never'],
  64. // enforces consistent naming when capturing the current execution context
  65. 'consistent-this': 'off',
  66. // enforce newline at the end of file, with no multiple empty lines
  67. 'eol-last': ['error', 'always'],
  68. // https://eslint.org/docs/rules/function-call-argument-newline
  69. 'function-call-argument-newline': ['error', 'consistent'],
  70. // enforce spacing between functions and their invocations
  71. // https://eslint.org/docs/rules/func-call-spacing
  72. 'func-call-spacing': ['error', 'never'],
  73. // requires function names to match the name of the variable or property to which they are
  74. // assigned
  75. // https://eslint.org/docs/rules/func-name-matching
  76. 'func-name-matching': ['off', 'always', {
  77. includeCommonJSModuleExports: false,
  78. considerPropertyDescriptor: true,
  79. }],
  80. // require function expressions to have a name
  81. // https://eslint.org/docs/rules/func-names
  82. 'func-names': 'warn',
  83. // enforces use of function declarations or expressions
  84. // https://eslint.org/docs/rules/func-style
  85. // TODO: enable
  86. 'func-style': ['off', 'expression'],
  87. // require line breaks inside function parentheses if there are line breaks between parameters
  88. // https://eslint.org/docs/rules/function-paren-newline
  89. 'function-paren-newline': ['error', semver.satisfies(eslintPkg.version, '>= 6') ? 'multiline-arguments' : 'consistent'],
  90. // disallow specified identifiers
  91. // https://eslint.org/docs/rules/id-denylist
  92. 'id-denylist': 'off',
  93. // this option enforces minimum and maximum identifier lengths
  94. // (variable names, property names etc.)
  95. 'id-length': 'off',
  96. // require identifiers to match the provided regular expression
  97. 'id-match': 'off',
  98. // Enforce the location of arrow function bodies with implicit returns
  99. // https://eslint.org/docs/rules/implicit-arrow-linebreak
  100. 'implicit-arrow-linebreak': ['error', 'beside'],
  101. // this option sets a specific tab width for your code
  102. // https://eslint.org/docs/rules/indent
  103. indent: ['error', 2, {
  104. SwitchCase: 1,
  105. VariableDeclarator: 1,
  106. outerIIFEBody: 1,
  107. // MemberExpression: null,
  108. FunctionDeclaration: {
  109. parameters: 1,
  110. body: 1
  111. },
  112. FunctionExpression: {
  113. parameters: 1,
  114. body: 1
  115. },
  116. CallExpression: {
  117. arguments: 1
  118. },
  119. ArrayExpression: 1,
  120. ObjectExpression: 1,
  121. ImportDeclaration: 1,
  122. flatTernaryExpressions: false,
  123. // list derived from https://github.com/benjamn/ast-types/blob/HEAD/def/jsx.js
  124. ignoredNodes: ['JSXElement', 'JSXElement > *', 'JSXAttribute', 'JSXIdentifier', 'JSXNamespacedName', 'JSXMemberExpression', 'JSXSpreadAttribute', 'JSXExpressionContainer', 'JSXOpeningElement', 'JSXClosingElement', 'JSXFragment', 'JSXOpeningFragment', 'JSXClosingFragment', 'JSXText', 'JSXEmptyExpression', 'JSXSpreadChild'],
  125. ignoreComments: false
  126. }],
  127. // specify whether double or single quotes should be used in JSX attributes
  128. // https://eslint.org/docs/rules/jsx-quotes
  129. 'jsx-quotes': ['off', 'prefer-double'],
  130. // enforces spacing between keys and values in object literal properties
  131. 'key-spacing': ['error', { beforeColon: false, afterColon: true }],
  132. // require a space before & after certain keywords
  133. 'keyword-spacing': ['error', {
  134. before: true,
  135. after: true,
  136. overrides: {
  137. return: { after: true },
  138. throw: { after: true },
  139. case: { after: true }
  140. }
  141. }],
  142. // enforce position of line comments
  143. // https://eslint.org/docs/rules/line-comment-position
  144. // TODO: enable?
  145. 'line-comment-position': ['off', {
  146. position: 'above',
  147. ignorePattern: '',
  148. applyDefaultPatterns: true,
  149. }],
  150. // disallow mixed 'LF' and 'CRLF' as linebreaks
  151. // https://eslint.org/docs/rules/linebreak-style
  152. 'linebreak-style': ['error', 'unix'],
  153. // require or disallow an empty line between class members
  154. // https://eslint.org/docs/rules/lines-between-class-members
  155. 'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: false }],
  156. // enforces empty lines around comments
  157. 'lines-around-comment': 'off',
  158. // require or disallow newlines around directives
  159. // https://eslint.org/docs/rules/lines-around-directive
  160. 'lines-around-directive': ['error', {
  161. before: 'always',
  162. after: 'always',
  163. }],
  164. // specify the maximum depth that blocks can be nested
  165. 'max-depth': ['off', 4],
  166. // specify the maximum length of a line in your program
  167. // https://eslint.org/docs/rules/max-len
  168. 'max-len': ['error', 100, 2, {
  169. ignoreUrls: true,
  170. ignoreComments: false,
  171. ignoreRegExpLiterals: true,
  172. ignoreStrings: true,
  173. ignoreTemplateLiterals: true,
  174. }],
  175. // specify the max number of lines in a file
  176. // https://eslint.org/docs/rules/max-lines
  177. 'max-lines': ['off', {
  178. max: 300,
  179. skipBlankLines: true,
  180. skipComments: true
  181. }],
  182. // enforce a maximum function length
  183. // https://eslint.org/docs/rules/max-lines-per-function
  184. 'max-lines-per-function': ['off', {
  185. max: 50,
  186. skipBlankLines: true,
  187. skipComments: true,
  188. IIFEs: true,
  189. }],
  190. // specify the maximum depth callbacks can be nested
  191. 'max-nested-callbacks': 'off',
  192. // limits the number of parameters that can be used in the function declaration.
  193. 'max-params': ['off', 3],
  194. // specify the maximum number of statement allowed in a function
  195. 'max-statements': ['off', 10],
  196. // restrict the number of statements per line
  197. // https://eslint.org/docs/rules/max-statements-per-line
  198. 'max-statements-per-line': ['off', { max: 1 }],
  199. // enforce a particular style for multiline comments
  200. // https://eslint.org/docs/rules/multiline-comment-style
  201. 'multiline-comment-style': ['off', 'starred-block'],
  202. // require multiline ternary
  203. // https://eslint.org/docs/rules/multiline-ternary
  204. // TODO: enable?
  205. 'multiline-ternary': ['off', 'never'],
  206. // require a capital letter for constructors
  207. 'new-cap': ['error', {
  208. newIsCap: true,
  209. newIsCapExceptions: [],
  210. capIsNew: false,
  211. capIsNewExceptions: ['Immutable.Map', 'Immutable.Set', 'Immutable.List'],
  212. }],
  213. // disallow the omission of parentheses when invoking a constructor with no arguments
  214. // https://eslint.org/docs/rules/new-parens
  215. 'new-parens': 'error',
  216. // allow/disallow an empty newline after var statement
  217. 'newline-after-var': 'off',
  218. // https://eslint.org/docs/rules/newline-before-return
  219. 'newline-before-return': 'off',
  220. // enforces new line after each method call in the chain to make it
  221. // more readable and easy to maintain
  222. // https://eslint.org/docs/rules/newline-per-chained-call
  223. 'newline-per-chained-call': ['error', { ignoreChainWithDepth: 4 }],
  224. // disallow use of the Array constructor
  225. 'no-array-constructor': 'error',
  226. // disallow use of bitwise operators
  227. // https://eslint.org/docs/rules/no-bitwise
  228. 'no-bitwise': 'error',
  229. // disallow use of the continue statement
  230. // https://eslint.org/docs/rules/no-continue
  231. 'no-continue': 'error',
  232. // disallow comments inline after code
  233. 'no-inline-comments': 'off',
  234. // disallow if as the only statement in an else block
  235. // https://eslint.org/docs/rules/no-lonely-if
  236. 'no-lonely-if': 'error',
  237. // disallow un-paren'd mixes of different operators
  238. // https://eslint.org/docs/rules/no-mixed-operators
  239. 'no-mixed-operators': ['error', {
  240. // the list of arithmetic groups disallows mixing `%` and `**`
  241. // with other arithmetic operators.
  242. groups: [
  243. ['%', '**'],
  244. ['%', '+'],
  245. ['%', '-'],
  246. ['%', '*'],
  247. ['%', '/'],
  248. ['/', '*'],
  249. ['&', '|', '<<', '>>', '>>>'],
  250. ['==', '!=', '===', '!=='],
  251. ['&&', '||'],
  252. ],
  253. allowSamePrecedence: false
  254. }],
  255. // disallow mixed spaces and tabs for indentation
  256. 'no-mixed-spaces-and-tabs': 'error',
  257. // disallow use of chained assignment expressions
  258. // https://eslint.org/docs/rules/no-multi-assign
  259. 'no-multi-assign': ['error'],
  260. // disallow multiple empty lines, only one newline at the end, and no new lines at the beginning
  261. // https://eslint.org/docs/rules/no-multiple-empty-lines
  262. 'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
  263. // disallow negated conditions
  264. // https://eslint.org/docs/rules/no-negated-condition
  265. 'no-negated-condition': 'off',
  266. // disallow nested ternary expressions
  267. 'no-nested-ternary': 'error',
  268. // disallow use of the Object constructor
  269. 'no-new-object': 'error',
  270. // disallow use of unary operators, ++ and --
  271. // https://eslint.org/docs/rules/no-plusplus
  272. 'no-plusplus': 'error',
  273. // disallow certain syntax forms
  274. // https://eslint.org/docs/rules/no-restricted-syntax
  275. 'no-restricted-syntax': [
  276. 'error',
  277. {
  278. selector: 'ForInStatement',
  279. message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
  280. },
  281. {
  282. selector: 'ForOfStatement',
  283. message: 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
  284. },
  285. {
  286. selector: 'LabeledStatement',
  287. message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
  288. },
  289. {
  290. selector: 'WithStatement',
  291. message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
  292. },
  293. ],
  294. // disallow space between function identifier and application
  295. 'no-spaced-func': 'error',
  296. // disallow tab characters entirely
  297. 'no-tabs': 'error',
  298. // disallow the use of ternary operators
  299. 'no-ternary': 'off',
  300. // disallow trailing whitespace at the end of lines
  301. 'no-trailing-spaces': ['error', {
  302. skipBlankLines: false,
  303. ignoreComments: false,
  304. }],
  305. // disallow dangling underscores in identifiers
  306. // https://eslint.org/docs/rules/no-underscore-dangle
  307. 'no-underscore-dangle': ['error', {
  308. allow: [],
  309. allowAfterThis: false,
  310. allowAfterSuper: false,
  311. enforceInMethodNames: true,
  312. }],
  313. // disallow the use of Boolean literals in conditional expressions
  314. // also, prefer `a || b` over `a ? a : b`
  315. // https://eslint.org/docs/rules/no-unneeded-ternary
  316. 'no-unneeded-ternary': ['error', { defaultAssignment: false }],
  317. // disallow whitespace before properties
  318. // https://eslint.org/docs/rules/no-whitespace-before-property
  319. 'no-whitespace-before-property': 'error',
  320. // enforce the location of single-line statements
  321. // https://eslint.org/docs/rules/nonblock-statement-body-position
  322. 'nonblock-statement-body-position': ['error', 'beside', { overrides: {} }],
  323. // require padding inside curly braces
  324. 'object-curly-spacing': ['error', 'always'],
  325. // enforce line breaks between braces
  326. // https://eslint.org/docs/rules/object-curly-newline
  327. 'object-curly-newline': ['error', {
  328. ObjectExpression: { minProperties: 4, multiline: true, consistent: true },
  329. ObjectPattern: { minProperties: 4, multiline: true, consistent: true },
  330. ImportDeclaration: { minProperties: 4, multiline: true, consistent: true },
  331. ExportDeclaration: { minProperties: 4, multiline: true, consistent: true },
  332. }],
  333. // enforce "same line" or "multiple line" on object properties.
  334. // https://eslint.org/docs/rules/object-property-newline
  335. 'object-property-newline': ['error', {
  336. allowAllPropertiesOnSameLine: true,
  337. }],
  338. // allow just one var statement per function
  339. 'one-var': ['error', 'never'],
  340. // require a newline around variable declaration
  341. // https://eslint.org/docs/rules/one-var-declaration-per-line
  342. 'one-var-declaration-per-line': ['error', 'always'],
  343. // require assignment operator shorthand where possible or prohibit it entirely
  344. // https://eslint.org/docs/rules/operator-assignment
  345. 'operator-assignment': ['error', 'always'],
  346. // Requires operator at the beginning of the line in multiline statements
  347. // https://eslint.org/docs/rules/operator-linebreak
  348. 'operator-linebreak': ['error', 'before', { overrides: { '=': 'none' } }],
  349. // disallow padding within blocks
  350. 'padded-blocks': ['error', {
  351. blocks: 'never',
  352. classes: 'never',
  353. switches: 'never',
  354. }, {
  355. allowSingleLineBlocks: true,
  356. }],
  357. // Require or disallow padding lines between statements
  358. // https://eslint.org/docs/rules/padding-line-between-statements
  359. 'padding-line-between-statements': 'off',
  360. // Disallow the use of Math.pow in favor of the ** operator
  361. // https://eslint.org/docs/rules/prefer-exponentiation-operator
  362. 'prefer-exponentiation-operator': 'error',
  363. // Prefer use of an object spread over Object.assign
  364. // https://eslint.org/docs/rules/prefer-object-spread
  365. 'prefer-object-spread': 'error',
  366. // require quotes around object literal property names
  367. // https://eslint.org/docs/rules/quote-props.html
  368. 'quote-props': ['error', 'as-needed', { keywords: false, unnecessary: true, numbers: false }],
  369. // specify whether double or single quotes should be used
  370. quotes: ['error', 'single', { avoidEscape: true }],
  371. // do not require jsdoc
  372. // https://eslint.org/docs/rules/require-jsdoc
  373. 'require-jsdoc': 'off',
  374. // require or disallow use of semicolons instead of ASI
  375. semi: ['error', 'always'],
  376. // enforce spacing before and after semicolons
  377. 'semi-spacing': ['error', { before: false, after: true }],
  378. // Enforce location of semicolons
  379. // https://eslint.org/docs/rules/semi-style
  380. 'semi-style': ['error', 'last'],
  381. // requires object keys to be sorted
  382. 'sort-keys': ['off', 'asc', { caseSensitive: false, natural: true }],
  383. // sort variables within the same declaration block
  384. 'sort-vars': 'off',
  385. // require or disallow space before blocks
  386. 'space-before-blocks': 'error',
  387. // require or disallow space before function opening parenthesis
  388. // https://eslint.org/docs/rules/space-before-function-paren
  389. 'space-before-function-paren': ['error', {
  390. anonymous: 'always',
  391. named: 'never',
  392. asyncArrow: 'always'
  393. }],
  394. // require or disallow spaces inside parentheses
  395. 'space-in-parens': ['error', 'never'],
  396. // require spaces around operators
  397. 'space-infix-ops': 'error',
  398. // Require or disallow spaces before/after unary operators
  399. // https://eslint.org/docs/rules/space-unary-ops
  400. 'space-unary-ops': ['error', {
  401. words: true,
  402. nonwords: false,
  403. overrides: {
  404. },
  405. }],
  406. // require or disallow a space immediately following the // or /* in a comment
  407. // https://eslint.org/docs/rules/spaced-comment
  408. 'spaced-comment': ['error', 'always', {
  409. line: {
  410. exceptions: ['-', '+'],
  411. markers: ['=', '!', '/'], // space here to support sprockets directives, slash for TS /// comments
  412. },
  413. block: {
  414. exceptions: ['-', '+'],
  415. markers: ['=', '!', ':', '::'], // space here to support sprockets directives and flow comment types
  416. balanced: true,
  417. }
  418. }],
  419. // Enforce spacing around colons of switch statements
  420. // https://eslint.org/docs/rules/switch-colon-spacing
  421. 'switch-colon-spacing': ['error', { after: true, before: false }],
  422. // Require or disallow spacing between template tags and their literals
  423. // https://eslint.org/docs/rules/template-tag-spacing
  424. 'template-tag-spacing': ['error', 'never'],
  425. // require or disallow the Unicode Byte Order Mark
  426. // https://eslint.org/docs/rules/unicode-bom
  427. 'unicode-bom': ['error', 'never'],
  428. // require regex literals to be wrapped in parentheses
  429. 'wrap-regex': 'off'
  430. }
  431. };