Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@kv/eslint-config / src / utils / getRules.ts
Size: Mime:
import type { PackageConfig } from '../types';

const sharedRules = {
  'arrow-body-style': ['warn', 'as-needed'],
  'prefer-const': ['warn'],
  'react/jsx-uses-react': 'off',
  'react/react-in-jsx-scope': 'off',
  'react/jsx-curly-brace-presence': [
    'warn',
    { props: 'never', children: 'never' },
  ],
  // Temporary fix until `eslint-config-react-app` is updated to support
  // ESLint v8 and the newer version of `eslint-plugin-jest`
  'jest/valid-describe': 'off',
  'jest/valid-describe-callback': 'error',
  'import/order': [
    'warn',
    {
      groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
      pathGroups: [
        {
          pattern: '~/**',
          group: 'internal',
        },
      ],
      'newlines-between': 'always-and-inside-groups',
    },
  ],
  'import/no-unresolved': [
    'error',
    {
      ignore: ['^@react-types/shared$'],
    },
  ],
  'unicorn/consistent-destructuring': ['warn'],
  'unicorn/filename-case': [
    'error',
    {
      cases: {
        camelCase: true,
        pascalCase: true,
      },
      ignore: [/react-app-env.d.ts/],
    },
  ],
  'unicorn/no-array-callback-reference': 'off',
  'unicorn/no-array-for-each': 'off',
  'unicorn/no-array-reduce': 'off',
  'unicorn/no-null': 'off',
  'unicorn/no-useless-undefined': 'off',
  'unicorn/prefer-spread': 'off',
  'unicorn/prevent-abbreviations': 'off',
  'unicorn/prefer-object-from-entries': 'off',
  'unicorn/prefer-export-from': 'off',
};

const tsRules = {
  // We're already defining our prop types in TypeScript,
  // we don't need to define them again
  'react/prop-types': 'off',
  '@typescript-eslint/explicit-function-return-type': 'off',
  '@typescript-eslint/explicit-module-boundary-types': 'off',
  'brace-style': 'off',
  '@typescript-eslint/brace-style': ['warn'],
  'comma-dangle': 'off',
  '@typescript-eslint/comma-dangle': ['warn', 'always-multiline'],
  'comma-spacing': 'off',
  '@typescript-eslint/comma-spacing': ['warn'],
  'default-param-last': 'off',
  '@typescript-eslint/default-param-last': ['error'],
  // Needs type-checking enabled
  // 'dot-notation': 'off',
  // '@typescript-eslint/dot-notation': ['error'],
  'no-dupe-class-members': 'off',
  '@typescript-eslint/no-dupe-class-members': ['error'],
  'no-duplicate-imports': 'off',
  '@typescript-eslint/no-duplicate-imports': [
    'error',
    {
      includeExports: true,
    },
  ],
  'no-invalid-this': 'off',
  '@typescript-eslint/no-invalid-this': ['error'],
  'no-loop-func': 'off',
  '@typescript-eslint/no-loop-func': ['error'],
  'no-loss-of-precision': 'off',
  '@typescript-eslint/no-loss-of-precision': ['error'],
  'no-magic-numbers': 'off',
  '@typescript-eslint/no-magic-numbers': [
    'warn',
    {
      ignore: [-1, 0, 1, 2, 3, 4, 5],
      enforceConst: true,
      ignoreDefaultValues: true,
      ignoreEnums: true,
      ignoreNumericLiteralTypes: true,
      ignoreReadonlyClassProperties: true,
    },
  ],
  'no-redeclare': 'off',
  '@typescript-eslint/no-redeclare': [
    'warn',
    {
      ignoreDeclarationMerge: true,
    },
  ],
  'no-shadow': 'off',
  '@typescript-eslint/no-shadow': ['error'],
  // Needs type-checking enabled
  // 'no-throw-literal': 'off',
  // '@typescript-eslint/no-throw-literal': ['error'],
  'no-unused-expressions': 'off',
  '@typescript-eslint/no-unused-expressions': ['error'],
  'no-unused-vars': 'off',
  '@typescript-eslint/no-unused-vars': ['warn'],
  'no-use-before-define': 'off',
  '@typescript-eslint/no-use-before-define': ['error'],
};

const jsRules = {
  'new-cap': 'warn',
  'no-duplicate-imports': ['error', { includeExports: true }],
  'no-invalid-this': ['error'],
  'no-unused-vars': ['warn'],
  'no-unused-expressions': [
    'error',
    {
      allowShortCircuit: true,
      allowTernary: true,
      allowTaggedTemplates: true,
    },
  ],
};

const getRules = ({ isTypeScript }: PackageConfig) => ({
  ...sharedRules,
  ...(isTypeScript ? tsRules : jsRules),
});

export default getRules;