2022-03-08 14:17:59 +01:00
|
|
|
/* global module */
|
2023-08-21 14:28:29 +02:00
|
|
|
|
|
|
|
const env = {
|
|
|
|
browser: true,
|
|
|
|
es6: true,
|
|
|
|
'cypress/globals': true,
|
|
|
|
}
|
|
|
|
|
|
|
|
const globals = {
|
|
|
|
Atomics: 'readonly',
|
|
|
|
SharedArrayBuffer: 'readonly',
|
|
|
|
}
|
|
|
|
|
2020-05-13 14:17:00 +02:00
|
|
|
module.exports = {
|
2024-07-09 11:59:53 +02:00
|
|
|
ignorePatterns: ['node_modules', 'plugin-server'],
|
2023-08-21 14:28:29 +02:00
|
|
|
env,
|
2020-05-13 14:17:00 +02:00
|
|
|
settings: {
|
|
|
|
react: {
|
|
|
|
version: 'detect',
|
|
|
|
},
|
2023-10-26 13:11:38 +02:00
|
|
|
'import/resolver': {
|
|
|
|
node: {
|
|
|
|
paths: ['eslint-rules'], // Add the directory containing your custom rules
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'], // Ensure ESLint resolves both JS and TS files
|
|
|
|
},
|
|
|
|
},
|
2020-05-13 14:17:00 +02:00
|
|
|
},
|
2022-03-08 14:17:59 +01:00
|
|
|
extends: [
|
2023-08-21 14:28:29 +02:00
|
|
|
'eslint:recommended',
|
2023-11-17 15:33:01 +01:00
|
|
|
'plugin:@typescript-eslint/recommended-type-checked',
|
2022-03-08 14:17:59 +01:00
|
|
|
'plugin:react/recommended',
|
2022-05-25 16:38:44 +02:00
|
|
|
'plugin:eslint-comments/recommended',
|
2022-03-08 14:17:59 +01:00
|
|
|
'plugin:storybook/recommended',
|
2023-09-19 17:19:48 +02:00
|
|
|
'plugin:compat/recommended',
|
2024-03-11 16:15:19 +01:00
|
|
|
'prettier',
|
2022-03-08 14:17:59 +01:00
|
|
|
],
|
2023-08-21 14:28:29 +02:00
|
|
|
globals,
|
2020-07-17 19:57:42 +02:00
|
|
|
parser: '@typescript-eslint/parser',
|
2020-05-13 14:17:00 +02:00
|
|
|
parserOptions: {
|
2024-03-11 16:15:19 +01:00
|
|
|
project: true,
|
|
|
|
tsconfigRootDir: __dirname,
|
2020-05-13 14:17:00 +02:00
|
|
|
},
|
2023-11-22 15:07:34 +01:00
|
|
|
plugins: [
|
|
|
|
'react',
|
2024-11-13 22:15:24 +01:00
|
|
|
'react-hooks',
|
2023-11-22 15:07:34 +01:00
|
|
|
'cypress',
|
|
|
|
'@typescript-eslint',
|
|
|
|
'compat',
|
|
|
|
'posthog',
|
|
|
|
'simple-import-sort',
|
2023-11-29 11:41:18 +01:00
|
|
|
'import',
|
2024-05-16 11:11:26 +02:00
|
|
|
'unused-imports',
|
2023-11-22 15:07:34 +01:00
|
|
|
],
|
2020-05-13 14:17:00 +02:00
|
|
|
rules: {
|
2024-11-13 22:15:24 +01:00
|
|
|
'react-hooks/rules-of-hooks': 'error',
|
|
|
|
'react-hooks/exhaustive-deps': 'warn',
|
2024-01-15 09:16:12 +01:00
|
|
|
// PyCharm always adds curly braces, I guess vscode doesn't, PR reviewers often complain they are present on props that don't need them
|
|
|
|
// let's save the humans time and let the machines do the work
|
|
|
|
// "never" means if the prop does not need the curly braces, they will be removed/errored
|
|
|
|
// see https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
|
2024-01-17 21:28:10 +01:00
|
|
|
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never', propElementValues: 'always' }],
|
2023-07-27 11:51:29 +02:00
|
|
|
'no-console': ['error', { allow: ['warn', 'error'] }],
|
2023-05-11 11:01:27 +02:00
|
|
|
'no-debugger': 'error',
|
2023-11-22 15:07:34 +01:00
|
|
|
'simple-import-sort/imports': 'error',
|
|
|
|
'simple-import-sort/exports': 'error',
|
2020-05-13 14:17:00 +02:00
|
|
|
'react/prop-types': [0],
|
2022-10-17 19:30:31 +02:00
|
|
|
'react/react-in-jsx-scope': [0],
|
2020-05-13 14:17:00 +02:00
|
|
|
'react/no-unescaped-entities': [0],
|
2020-08-27 14:34:11 +02:00
|
|
|
'react/jsx-no-target-blank': [0],
|
2020-10-26 11:45:57 +01:00
|
|
|
'react/self-closing-comp': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
component: true,
|
|
|
|
html: true,
|
|
|
|
},
|
|
|
|
],
|
2024-05-16 11:11:26 +02:00
|
|
|
'unused-imports/no-unused-imports': 'error',
|
2022-05-25 16:38:44 +02:00
|
|
|
'no-unused-vars': 'off',
|
|
|
|
'@typescript-eslint/no-unused-vars': [
|
2022-03-08 14:17:59 +01:00
|
|
|
'error',
|
|
|
|
{
|
|
|
|
ignoreRestSiblings: true,
|
2024-04-15 14:08:17 +02:00
|
|
|
destructuredArrayIgnorePattern: '^_$',
|
2022-03-08 14:17:59 +01:00
|
|
|
},
|
|
|
|
],
|
2022-05-25 16:38:44 +02:00
|
|
|
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
2020-07-08 09:45:23 +02:00
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
2020-07-28 22:25:24 +02:00
|
|
|
'@typescript-eslint/no-inferrable-types': 'off',
|
2021-02-09 18:11:53 +01:00
|
|
|
'@typescript-eslint/ban-ts-comment': 'off',
|
2023-11-17 15:33:01 +01:00
|
|
|
'@typescript-eslint/require-await': 'off', // TODO: Enable - this rule is useful, but doesn't have an autofix
|
|
|
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-member-access': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-argument': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-return': 'off',
|
|
|
|
'@typescript-eslint/no-unsafe-call': 'off',
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
|
|
|
'@typescript-eslint/restrict-template-expressions': 'off',
|
|
|
|
'@typescript-eslint/explicit-function-return-type': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
allowExpressions: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
allowArgumentsExplicitlyTypedAsAny: true,
|
|
|
|
},
|
|
|
|
],
|
2020-11-25 17:46:49 +01:00
|
|
|
curly: 'error',
|
2022-01-20 13:13:29 +01:00
|
|
|
'no-restricted-imports': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
paths: [
|
|
|
|
{
|
|
|
|
name: 'dayjs',
|
|
|
|
message: 'Do not directly import dayjs. Only import the dayjs exported from lib/dayjs.',
|
2024-11-13 22:15:24 +01:00
|
|
|
},
|
2022-01-20 13:13:29 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2022-08-02 10:49:06 +02:00
|
|
|
'react/forbid-dom-props': [
|
2023-12-11 21:10:23 +01:00
|
|
|
'error',
|
2022-08-02 10:49:06 +02:00
|
|
|
{
|
|
|
|
forbid: [
|
|
|
|
{
|
|
|
|
propName: 'style',
|
|
|
|
message:
|
|
|
|
'style should be avoided in favor of utility CSS classes - see https://storybook.posthog.net/?path=/docs/lemon-ui-utilities--overview',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-10-26 13:11:38 +02:00
|
|
|
'posthog/warn-elements': [
|
2023-11-07 15:46:03 +01:00
|
|
|
'warn',
|
2022-08-02 10:49:06 +02:00
|
|
|
{
|
|
|
|
forbid: [
|
|
|
|
{
|
|
|
|
element: 'Button',
|
|
|
|
message: 'use <LemonButton> instead',
|
|
|
|
},
|
2022-08-16 11:07:50 +02:00
|
|
|
{
|
|
|
|
element: 'Input',
|
|
|
|
message: 'use <LemonInput> instead',
|
|
|
|
},
|
2023-02-13 17:13:07 +01:00
|
|
|
{
|
2023-08-04 15:49:45 +02:00
|
|
|
element: 'Modal',
|
|
|
|
message: 'use <LemonModal> or `<LemonDialog> instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: 'Select',
|
|
|
|
message: 'use <LemonSelect> instead',
|
2023-02-13 17:13:07 +01:00
|
|
|
},
|
2023-11-03 11:22:19 +01:00
|
|
|
{
|
|
|
|
element: 'LemonButtonWithDropdown',
|
|
|
|
message: 'use <LemonMenu> with a <LemonButton> child instead',
|
|
|
|
},
|
2024-01-26 17:03:17 +01:00
|
|
|
{
|
|
|
|
element: 'Progress',
|
|
|
|
message: 'use <LemonProgress> instead',
|
|
|
|
},
|
2022-08-02 10:49:06 +02:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-01-12 12:37:17 +01:00
|
|
|
'react/forbid-elements': [
|
2023-11-07 15:46:03 +01:00
|
|
|
'error',
|
2023-01-12 12:37:17 +01:00
|
|
|
{
|
|
|
|
forbid: [
|
|
|
|
{
|
|
|
|
element: 'Layout',
|
|
|
|
message: 'use utility classes instead',
|
|
|
|
},
|
2023-08-04 15:49:45 +02:00
|
|
|
{
|
|
|
|
element: 'Tabs',
|
|
|
|
message: 'use <LemonTabs> instead',
|
|
|
|
},
|
2023-11-06 16:58:08 +01:00
|
|
|
{
|
|
|
|
element: 'Space',
|
|
|
|
message: 'use flex or space utility classes instead',
|
|
|
|
},
|
2023-01-12 12:37:17 +01:00
|
|
|
{
|
|
|
|
element: 'Spin',
|
|
|
|
message: 'use Spinner instead',
|
|
|
|
},
|
2023-01-18 15:50:51 +01:00
|
|
|
{
|
|
|
|
element: 'Badge',
|
|
|
|
message: 'use LemonBadge instead',
|
|
|
|
},
|
2024-01-05 08:46:01 +01:00
|
|
|
{
|
|
|
|
element: 'InputNumber',
|
|
|
|
message: 'use LemonInput with type="number" instead',
|
|
|
|
},
|
2023-03-10 15:55:26 +01:00
|
|
|
{
|
|
|
|
element: 'Collapse',
|
|
|
|
message: 'use <LemonCollapse> instead',
|
|
|
|
},
|
2024-01-25 16:48:08 +01:00
|
|
|
{
|
|
|
|
element: 'Slider',
|
|
|
|
message: 'use <LemonSlider> instead',
|
|
|
|
},
|
2023-11-06 14:38:55 +01:00
|
|
|
{
|
|
|
|
element: 'Checkbox',
|
|
|
|
message: 'use <LemonCheckbox> instead',
|
|
|
|
},
|
2023-08-29 09:28:03 +02:00
|
|
|
{
|
2023-09-18 12:16:33 +02:00
|
|
|
element: 'MonacoEditor',
|
2023-08-29 09:28:03 +02:00
|
|
|
message: 'use <CodeEditor> instead',
|
2023-09-18 12:16:33 +02:00
|
|
|
},
|
2023-10-04 15:32:49 +02:00
|
|
|
{
|
|
|
|
element: 'Typography',
|
|
|
|
message: 'use utility classes instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: 'Input.TextArea',
|
|
|
|
message: 'use <LemonTextArea> instead',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
element: 'ReactMarkdown',
|
|
|
|
message: 'use <LemonMarkdown> instead',
|
|
|
|
},
|
2023-11-02 10:35:10 +01:00
|
|
|
{
|
|
|
|
element: 'a',
|
|
|
|
message: 'use <Link> instead',
|
|
|
|
},
|
2023-11-22 12:11:45 +01:00
|
|
|
{
|
2023-11-29 16:25:16 +01:00
|
|
|
element: 'Tag',
|
|
|
|
message: 'use <LemonTag> instead',
|
2024-02-02 16:20:26 +01:00
|
|
|
},
|
|
|
|
{
|
2023-11-22 12:11:45 +01:00
|
|
|
element: 'Alert',
|
|
|
|
message: 'use <LemonBanner> instead',
|
|
|
|
},
|
2023-11-27 13:14:08 +01:00
|
|
|
{
|
|
|
|
element: 'ReactJson',
|
|
|
|
message: 'use <JSONViewer> for dark mode support instead',
|
|
|
|
},
|
2024-02-02 16:20:26 +01:00
|
|
|
{
|
|
|
|
element: 'Radio',
|
|
|
|
message: 'use <LemonRadio> instead',
|
|
|
|
},
|
2024-01-31 14:07:22 +01:00
|
|
|
{
|
|
|
|
element: 'Skeleton',
|
|
|
|
message: 'use <LemonSkeleton> instead',
|
|
|
|
},
|
2024-01-31 10:27:42 +01:00
|
|
|
{
|
|
|
|
element: 'Divider',
|
|
|
|
message: 'use <LemonDivider> instead',
|
|
|
|
},
|
2024-03-08 20:46:48 +01:00
|
|
|
{
|
|
|
|
element: 'Popconfirm',
|
|
|
|
message: 'use <LemonDialog> instead',
|
|
|
|
},
|
2023-01-12 12:37:17 +01:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-11-09 11:37:05 +01:00
|
|
|
'no-constant-binary-expression': 'error',
|
2023-11-07 15:46:03 +01:00
|
|
|
'no-constant-condition': 'off',
|
|
|
|
'no-prototype-builtins': 'off',
|
|
|
|
'no-irregular-whitespace': 'off',
|
2024-01-26 10:21:10 +01:00
|
|
|
'no-useless-rename': 'error',
|
2023-11-29 11:41:18 +01:00
|
|
|
'import/no-restricted-paths': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
zones: [
|
|
|
|
{
|
|
|
|
target: './frontend/**',
|
|
|
|
from: './ee/frontend/**',
|
|
|
|
message:
|
|
|
|
"EE licensed TypeScript should only be accessed via the posthogEE objects. Use `import posthogEE from '@posthog/ee/exports'`",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2024-05-16 11:11:26 +02:00
|
|
|
'no-else-return': 'warn',
|
2020-05-13 14:17:00 +02:00
|
|
|
},
|
2020-07-08 09:45:23 +02:00
|
|
|
overrides: [
|
2023-08-21 14:28:29 +02:00
|
|
|
{
|
|
|
|
files: ['**/test/**/*', '**/*.test.*'],
|
|
|
|
env: {
|
|
|
|
...env,
|
|
|
|
node: true,
|
|
|
|
'jest/globals': true,
|
|
|
|
},
|
2024-11-13 22:15:24 +01:00
|
|
|
plugins: ['jest'],
|
|
|
|
extends: ['plugin:jest/recommended'],
|
2023-08-21 14:28:29 +02:00
|
|
|
globals: {
|
|
|
|
...globals,
|
|
|
|
given: 'readonly',
|
|
|
|
},
|
2023-11-17 15:33:01 +01:00
|
|
|
rules: {
|
|
|
|
// The below complains needlessly about expect(api.createInvite).toHaveBeenCalledWith(...)
|
|
|
|
'@typescript-eslint/unbound-method': 'off',
|
2024-06-10 10:49:47 +02:00
|
|
|
// it doesn't know about expectLogic kea tests so isn't helpful
|
|
|
|
'jest/expect-expect': 'off',
|
|
|
|
// we import non-jest mocks from __mocks__ directories
|
|
|
|
'jest/no-mocks-import': 'off',
|
|
|
|
// I'll put expect whereever I want
|
|
|
|
'jest/no-standalone-expect': 'off',
|
|
|
|
// but it's helpful sometimes
|
|
|
|
'jest/no-export': 'off',
|
|
|
|
// also helpful sometimes, but not always
|
2024-07-09 11:59:53 +02:00
|
|
|
'jest/no-conditional-expect': 'warn',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['**/*.cy.ts'],
|
|
|
|
env: {
|
|
|
|
...env,
|
|
|
|
node: true,
|
|
|
|
'jest/globals': true,
|
|
|
|
},
|
2024-11-13 22:15:24 +01:00
|
|
|
plugins: ['jest'],
|
|
|
|
extends: ['plugin:jest/recommended'],
|
2024-07-09 11:59:53 +02:00
|
|
|
globals: {
|
|
|
|
...globals,
|
|
|
|
given: 'readonly',
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
// don't complain about unknown expect statements
|
|
|
|
'jest/valid-expect': 'off',
|
|
|
|
// don't warn about missing expect
|
2024-11-13 22:15:24 +01:00
|
|
|
'jest/expect-expect': 'off',
|
2023-11-22 12:11:45 +01:00
|
|
|
},
|
2023-08-21 14:28:29 +02:00
|
|
|
},
|
2020-07-28 22:25:24 +02:00
|
|
|
{
|
2023-11-22 15:07:34 +01:00
|
|
|
files: ['*Type.ts', '*Type.tsx'], // Kea typegen output
|
2020-07-28 22:25:24 +02:00
|
|
|
rules: {
|
2023-11-17 15:33:01 +01:00
|
|
|
'no-restricted-imports': 'off',
|
2023-11-22 15:07:34 +01:00
|
|
|
'@typescript-eslint/ban-types': 'off',
|
|
|
|
'simple-import-sort/imports': 'off',
|
|
|
|
'simple-import-sort/exports': 'off',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ['frontend/src/scenes/notebooks/Nodes/*'], // Notebooks code weirdly relies on its order of sorting
|
|
|
|
rules: {
|
|
|
|
'simple-import-sort/imports': 'off',
|
|
|
|
'simple-import-sort/exports': 'off',
|
2020-07-28 22:25:24 +02:00
|
|
|
},
|
|
|
|
},
|
2020-07-08 09:45:23 +02:00
|
|
|
{
|
|
|
|
files: ['*.js'],
|
|
|
|
rules: {
|
2021-01-13 00:46:59 +01:00
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
2023-11-17 15:33:01 +01:00
|
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
2020-07-08 09:45:23 +02:00
|
|
|
},
|
|
|
|
},
|
2023-11-28 15:33:21 +01:00
|
|
|
{
|
|
|
|
files: ['*.mjs'],
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
|
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
|
|
'@typescript-eslint/no-misused-promises': 'off',
|
|
|
|
'no-console': 'off',
|
|
|
|
},
|
|
|
|
globals: { ...globals, process: 'readonly' },
|
|
|
|
},
|
2023-10-26 13:11:38 +02:00
|
|
|
{
|
|
|
|
files: 'eslint-rules/**/*',
|
|
|
|
rules: {
|
|
|
|
'@typescript-eslint/no-var-requires': 'off',
|
|
|
|
},
|
|
|
|
env: {
|
|
|
|
node: true,
|
|
|
|
},
|
|
|
|
},
|
2020-07-08 09:45:23 +02:00
|
|
|
],
|
2022-05-25 16:38:44 +02:00
|
|
|
reportUnusedDisableDirectives: true,
|
2020-05-13 14:17:00 +02:00
|
|
|
}
|