github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/.eslintrc.js (about)

     1  const path = require('path');
     2  
     3  module.exports = {
     4    plugins: ['@typescript-eslint', 'css-modules'],
     5    extends: [
     6      'airbnb-typescript-prettier',
     7      'plugin:cypress/recommended',
     8      'plugin:import/typescript',
     9      'plugin:css-modules/recommended',
    10      'eslint:recommended',
    11      'plugin:@typescript-eslint/recommended',
    12      'plugin:@typescript-eslint/recommended-requiring-type-checking',
    13    ],
    14    rules: {
    15      '@typescript-eslint/no-shadow': 'warn',
    16  
    17      // https://stackoverflow.com/questions/63818415/react-was-used-before-it-was-defined/64024916#64024916
    18      '@typescript-eslint/no-use-before-define': ['off'],
    19  
    20      // react functional components are usually written using PascalCase
    21      '@typescript-eslint/naming-convention': [
    22        'warn',
    23        { selector: 'function', format: ['PascalCase', 'camelCase'] },
    24      ],
    25      '@typescript-eslint/no-empty-function': 'warn',
    26      '@typescript-eslint/no-var-requires': 'warn',
    27      'react-hooks/exhaustive-deps': 'warn',
    28  
    29      'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
    30      'no-param-reassign': ['warn'],
    31      'no-case-declarations': ['warn'],
    32      'no-restricted-globals': ['warn'],
    33      'react/button-has-type': ['warn'],
    34      'react/prop-types': ['off'],
    35      'jsx-a11y/heading-has-content': ['warn'],
    36      'jsx-a11y/control-has-associated-label': ['warn'],
    37      'no-undef': ['warn'],
    38      'jsx-a11y/mouse-events-have-key-events': ['warn'],
    39      'jsx-a11y/click-events-have-key-events': ['warn'],
    40      'jsx-a11y/no-static-element-interactions': ['warn'],
    41      'jsx-a11y/label-has-associated-control': [
    42        'error',
    43        {
    44          required: {
    45            some: ['nesting', 'id'],
    46          },
    47        },
    48      ],
    49      'react/jsx-filename-extension': [1, { extensions: ['.tsx', '.ts'] }],
    50      'import/extensions': [
    51        'error',
    52        'always',
    53        {
    54          js: 'never',
    55          jsx: 'never',
    56          ts: 'never',
    57          tsx: 'never',
    58        },
    59      ],
    60      'spaced-comment': [2, 'always', { exceptions: ['*'] }],
    61      'react/require-default-props': 'off',
    62  
    63      'import/no-extraneous-dependencies': [
    64        'error',
    65        {
    66          devDependencies: [
    67            '**/*.spec.jsx',
    68            '**/*.spec.ts',
    69            '**/*.spec.tsx',
    70            '**/*.stories.tsx',
    71          ],
    72          packageDir: [
    73            // TODO compute this dynamically
    74            path.resolve(__dirname, 'packages/pyroscope-flamegraph'),
    75            process.cwd(),
    76          ],
    77        },
    78      ],
    79      // otherwise it conflincts with ts411
    80      'dot-notation': 'off',
    81  
    82      // disable relative imports to force people to use '@webapp'
    83      'import/no-relative-packages': 'error',
    84  
    85      // https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/
    86      'import/prefer-default-export': 'off',
    87  
    88      '@typescript-eslint/no-unused-vars': [
    89        'error',
    90        {
    91          ignoreRestSiblings: true,
    92        },
    93      ],
    94  
    95      // any is bad, if really necessary one can use ShamefulAny
    96      '@typescript-eslint/no-explicit-any': 'error',
    97  
    98      // ATM there's too many errors to deal with right now
    99      // TODO: deal with each issue individually
   100      '@typescript-eslint/no-unsafe-member-access': 'warn',
   101      '@typescript-eslint/no-unsafe-argument': 'warn',
   102      '@typescript-eslint/no-unsafe-call': 'warn',
   103      '@typescript-eslint/no-unsafe-assignment': 'warn',
   104      '@typescript-eslint/no-unsafe-return': 'warn',
   105      '@typescript-eslint/restrict-template-expressions': 'warn',
   106  
   107      // https://github.com/typescript-eslint/typescript-eslint/issues/1184
   108      '@typescript-eslint/no-floating-promises': ['warn', { ignoreVoid: true }],
   109  
   110      // makes it easier to check what are local variables computated dynamically and what are static props
   111      'react/destructuring-assignment': 'off',
   112  
   113      '@typescript-eslint/switch-exhaustiveness-check': 'error',
   114    },
   115    env: {
   116      browser: true,
   117      jquery: true,
   118    },
   119    settings: {
   120      'import/internal-regex': '^@pyroscope',
   121      'import/resolver': {
   122        'eslint-import-resolver-lerna': {
   123          packages: path.resolve(__dirname, 'packages'),
   124        },
   125        typescript: {
   126          project: 'tsconfig.json',
   127        },
   128      },
   129    },
   130    overrides: [
   131      // Tests are completely different
   132      // And we shouldn't be so strict
   133      {
   134        files: ['**/?(*.)+(spec|test).+(ts|tsx|js)'],
   135        plugins: ['jest'],
   136        env: {
   137          node: true,
   138          'jest/globals': true,
   139        },
   140      },
   141    ],
   142    ignorePatterns: ['dist', 'public'],
   143    globals: {
   144      // see ./lib/alias.d.ts
   145      ShamefulAny: true,
   146      JSX: true,
   147    },
   148    parserOptions: {
   149      project: ['./tsconfig.json'],
   150    },
   151  };