All files / src rule-severities.js

100% Statements 12/12
100% Branches 8/8
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69    2x                                                                           2x   8x             3x   69x 3x       1x 2x 1x   1x           3x    
'use strict'
 
const severityOverrides = {
  // Warnings only for debuggers
  'no-debugger': 'warn',
  'testing-library/no-debug': 'warn',
 
  // These rules are non critical, stylistic rules, warn only in dev for them
  'class-methods-use-this': 'warn',
  'no-unused-vars': 'warn',
  'prefer-const': 'warn',
  'prefer-destructuring': 'warn',
  'sort-imports': 'warn',
 
  // Imports style preferences rules
  'import/order': 'warn',
 
  // React style preferences rules
  'react/default-props-match-prop-types': 'warn',
  'react/forbid-prop-types': 'warn',
  'react/jsx-boolean-value': 'warn',
  'react/jsx-sort-default-props': 'warn',
  'react/jsx-sort-props': 'warn',
  'react/sort-prop-types': 'warn',
  'react/no-unescaped-entities': 'warn',
  'react/no-unused-prop-types': 'warn',
  'react/no-unused-state': 'warn',
  'react/prefer-stateless-function': 'warn',
  'react/prop-types': 'warn',
  'react/require-default-props': 'warn',
  'react/self-closing-comp': 'warn',
 
  // Allow unused variables with a warning in development
  '@typescript-eslint/no-unused-vars': 'warn',
 
  // Don't show any Prettier formatting errors during dev b/c they're SUPER
  // noisy and annoying and NOT helpful at that time
  'prettier/prettier': 'off',
}
 
module.exports = (env, rules) => {
  // During tests linting, rule severity levels are not overridden
  if (env === 'test') return rules
 
  // Outside tests linting, downgrade severity levels for style and formatting
  // rules by setting the rule level. ESLint handles rule extends with a level
  // only by keeping the original rule settings and overriding the level only
  // which makes this a super convenient list of severity overrides that won't
  // affect the rule custom settings
  Object.keys(severityOverrides).forEach((rule) => {
    /* eslint-disable no-param-reassign */
    if (rules[rule]) {
      if (rules[rule] === 'off') {
        // If a rule is disabled, keep it disabled (severity overrides only move down, not
        // up) This is a workaround for TS where core rules like no-unused-vars are off
        // and should stay off instead of accidentally being set to 'warn'
        rules[rule] = 'off'
      } else if (Array.isArray(rules[rule])) {
        rules[rule][0] = severityOverrides[rule]
      } else {
        rules[rule] = severityOverrides[rule]
      }
    }
    /* eslint-enable no-param-reassign */
  })
 
  return rules
}