whitespace-async.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env node
  2. const assign = require('object.assign');
  3. const entries = require('object.entries');
  4. const { ESLint } = require('eslint');
  5. const baseConfig = require('.');
  6. const severities = ['off', 'warn', 'error'];
  7. function getSeverity(ruleConfig) {
  8. if (Array.isArray(ruleConfig)) {
  9. return getSeverity(ruleConfig[0]);
  10. }
  11. if (typeof ruleConfig === 'number') {
  12. return severities[ruleConfig];
  13. }
  14. return ruleConfig;
  15. }
  16. async function onlyErrorOnRules(rulesToError, config) {
  17. const errorsOnly = assign({}, config);
  18. const cli = new ESLint({
  19. useEslintrc: false,
  20. baseConfig: config
  21. });
  22. const baseRules = (await cli.calculateConfigForFile(require.resolve('./'))).rules;
  23. entries(baseRules).forEach((rule) => {
  24. const ruleName = rule[0];
  25. const ruleConfig = rule[1];
  26. const severity = getSeverity(ruleConfig);
  27. if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') {
  28. if (Array.isArray(ruleConfig)) {
  29. errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1));
  30. } else if (typeof ruleConfig === 'number') {
  31. errorsOnly.rules[ruleName] = 1;
  32. } else {
  33. errorsOnly.rules[ruleName] = 'warn';
  34. }
  35. }
  36. });
  37. return errorsOnly;
  38. }
  39. onlyErrorOnRules([
  40. 'array-bracket-newline',
  41. 'array-bracket-spacing',
  42. 'array-element-newline',
  43. 'arrow-spacing',
  44. 'block-spacing',
  45. 'comma-spacing',
  46. 'computed-property-spacing',
  47. 'dot-location',
  48. 'eol-last',
  49. 'func-call-spacing',
  50. 'function-paren-newline',
  51. 'generator-star-spacing',
  52. 'implicit-arrow-linebreak',
  53. 'indent',
  54. 'key-spacing',
  55. 'keyword-spacing',
  56. 'line-comment-position',
  57. 'linebreak-style',
  58. 'multiline-ternary',
  59. 'newline-per-chained-call',
  60. 'no-irregular-whitespace',
  61. 'no-mixed-spaces-and-tabs',
  62. 'no-multi-spaces',
  63. 'no-regex-spaces',
  64. 'no-spaced-func',
  65. 'no-trailing-spaces',
  66. 'no-whitespace-before-property',
  67. 'nonblock-statement-body-position',
  68. 'object-curly-newline',
  69. 'object-curly-spacing',
  70. 'object-property-newline',
  71. 'one-var-declaration-per-line',
  72. 'operator-linebreak',
  73. 'padded-blocks',
  74. 'padding-line-between-statements',
  75. 'rest-spread-spacing',
  76. 'semi-spacing',
  77. 'semi-style',
  78. 'space-before-blocks',
  79. 'space-before-function-paren',
  80. 'space-in-parens',
  81. 'space-infix-ops',
  82. 'space-unary-ops',
  83. 'spaced-comment',
  84. 'switch-colon-spacing',
  85. 'template-tag-spacing',
  86. 'import/newline-after-import',
  87. ], baseConfig).then((config) => console.log(JSON.stringify(config)));