| 1 | import cspell from '@cspell/eslint-plugin'; |
| 2 | import eslint from '@eslint/js'; |
| 3 | import cypress from 'eslint-plugin-cypress'; |
| 4 | import jsdoc from 'eslint-plugin-jsdoc'; |
| 5 | import json from 'eslint-plugin-json'; |
| 6 | import lodash from 'eslint-plugin-lodash'; |
| 7 | import markdown from 'eslint-plugin-markdown'; |
| 8 | import noOnlyTests from 'eslint-plugin-no-only-tests'; |
| 9 | import tsdoc from 'eslint-plugin-tsdoc'; |
| 10 | import unicorn from 'eslint-plugin-unicorn'; |
| 11 | import globals from 'globals'; |
| 12 | import tseslint from 'typescript-eslint'; |
| 13 | |
| 14 | export default tseslint.config( |
| 15 | eslint.configs.recommended, |
| 16 | ...tseslint.configs.recommendedTypeChecked, |
| 17 | ...tseslint.configs.stylisticTypeChecked, |
| 18 | { |
| 19 | ignores: [ |
| 20 | '**/*.d.ts', |
| 21 | '**/dist/', |
| 22 | '**/node_modules/', |
| 23 | '.git/', |
| 24 | '**/generated/', |
| 25 | '**/coverage/', |
| 26 | 'packages/mermaid/src/config.type.ts', |
| 27 | 'packages/mermaid/src/docs/.vitepress/components.d.ts', |
| 28 | ], |
| 29 | }, |
| 30 | { |
| 31 | languageOptions: { |
| 32 | parserOptions: { |
| 33 | project: [ |
| 34 | './tsconfig.eslint.json', |
| 35 | './packages/*/tsconfig.json', |
| 36 | './packages/*/tsconfig.eslint.json', |
| 37 | './packages/mermaid/src/docs/tsconfig.json', |
| 38 | ], |
| 39 | tsconfigRootDir: import.meta.dirname, |
| 40 | }, |
| 41 | globals: { |
| 42 | ...globals.browser, |
| 43 | ...globals.node, |
| 44 | ...globals.es2020, |
| 45 | ...globals.jest, |
| 46 | cy: 'readonly', |
| 47 | Cypress: 'readonly', |
| 48 | }, |
| 49 | }, |
| 50 | }, |
| 51 | { |
| 52 | plugins: { |
| 53 | json, |
| 54 | '@cspell': cspell, |
| 55 | 'no-only-tests': noOnlyTests, |
| 56 | lodash, |
| 57 | unicorn, |
| 58 | cypress, |
| 59 | markdown, |
| 60 | tsdoc, |
| 61 | jsdoc, |
| 62 | }, |
| 63 | rules: { |
| 64 | curly: 'error', |
| 65 | 'no-console': 'error', |
| 66 | 'no-prototype-builtins': 'off', |
| 67 | 'no-unused-vars': 'off', |
| 68 | 'cypress/no-async-tests': 'off', |
| 69 | '@typescript-eslint/consistent-type-imports': 'error', |
| 70 | '@typescript-eslint/no-explicit-any': 'warn', |
| 71 | '@typescript-eslint/no-floating-promises': 'error', |
| 72 | '@typescript-eslint/no-misused-promises': 'error', |
| 73 | '@typescript-eslint/no-unused-vars': [ |
| 74 | 'error', |
| 75 | { |
| 76 | args: 'after-used', |
| 77 | argsIgnorePattern: '^_', |
| 78 | caughtErrors: 'all', |
| 79 | caughtErrorsIgnorePattern: '^_', |
| 80 | destructuredArrayIgnorePattern: '^_', |
| 81 | varsIgnorePattern: '^_', |
| 82 | ignoreRestSiblings: true, |
| 83 | }, |
| 84 | ], |
| 85 | '@typescript-eslint/consistent-type-definitions': 'error', |
| 86 | '@typescript-eslint/ban-ts-comment': [ |
| 87 | 'error', |
| 88 | { |
| 89 | 'ts-expect-error': 'allow-with-description', |
| 90 | 'ts-ignore': 'allow-with-description', |
| 91 | 'ts-nocheck': 'allow-with-description', |
| 92 | 'ts-check': 'allow-with-description', |
| 93 | minimumDescriptionLength: 10, |
| 94 | }, |
| 95 | ], |
| 96 | '@typescript-eslint/naming-convention': [ |
| 97 | 'error', |
| 98 | { |
| 99 | selector: 'typeLike', |
| 100 | format: ['PascalCase'], |
| 101 | custom: { |
| 102 | regex: '^I[A-Z]', |
| 103 | match: false, |
| 104 | }, |
| 105 | }, |
| 106 | ], |
| 107 | // START: These rules should be turned on once the codebase is cleaned up |
| 108 | '@typescript-eslint/no-unsafe-argument': 'off', |
| 109 | '@typescript-eslint/no-unsafe-assignment': 'off', |
| 110 | '@typescript-eslint/no-unsafe-call': 'off', |
| 111 | '@typescript-eslint/no-unsafe-member-access': 'off', |
| 112 | '@typescript-eslint/no-unsafe-return': 'off', |
| 113 | '@typescript-eslint/only-throw-error': 'warn', |
| 114 | '@typescript-eslint/prefer-nullish-coalescing': 'warn', |
| 115 | '@typescript-eslint/prefer-promise-reject-errors': 'warn', |
| 116 | // END |
| 117 | 'json/*': ['error', 'allowComments'], |
| 118 | '@cspell/spellchecker': [ |
| 119 | 'error', |
| 120 | { |
| 121 | checkIdentifiers: true, |
| 122 | checkStrings: true, |
| 123 | checkStringTemplates: true, |
| 124 | }, |
| 125 | ], |
| 126 | 'no-empty': [ |
| 127 | 'error', |
| 128 | { |
| 129 | allowEmptyCatch: true, |
| 130 | }, |
| 131 | ], |
| 132 | 'no-only-tests/no-only-tests': 'error', |
| 133 | 'lodash/import-scope': ['error', 'method'], |
| 134 | 'unicorn/better-regex': 'error', |
| 135 | 'unicorn/no-abusive-eslint-disable': 'error', |
| 136 | 'unicorn/no-array-push-push': 'error', |
| 137 | 'unicorn/no-for-loop': 'error', |
| 138 | 'unicorn/no-instanceof-array': 'error', |
| 139 | 'unicorn/no-typeof-undefined': 'error', |
| 140 | 'unicorn/no-unnecessary-await': 'error', |
| 141 | 'unicorn/no-useless-promise-resolve-reject': 'error', |
| 142 | 'unicorn/prefer-array-find': 'error', |
| 143 | 'unicorn/prefer-array-flat-map': 'error', |
| 144 | 'unicorn/prefer-array-index-of': 'error', |
| 145 | 'unicorn/prefer-array-some': 'error', |
| 146 | 'unicorn/prefer-default-parameters': 'error', |
| 147 | 'unicorn/prefer-includes': 'error', |
| 148 | 'unicorn/prefer-negative-index': 'error', |
| 149 | 'unicorn/prefer-object-from-entries': 'error', |
| 150 | 'unicorn/prefer-string-starts-ends-with': 'error', |
| 151 | 'unicorn/prefer-string-trim-start-end': 'error', |
| 152 | 'unicorn/string-content': 'error', |
| 153 | 'unicorn/prefer-spread': 'error', |
| 154 | 'unicorn/no-lonely-if': 'error', |
| 155 | }, |
| 156 | }, |
| 157 | { |
| 158 | files: ['cypress/**', 'demos/**'], |
| 159 | rules: { |
| 160 | 'no-console': 'off', |
| 161 | }, |
| 162 | }, |
| 163 | { |
| 164 | files: ['**/*.{js,jsx,mjs,cjs}'], |
| 165 | rules: { |
| 166 | 'jsdoc/check-indentation': 'off', |
| 167 | 'jsdoc/check-alignment': 'off', |
| 168 | 'jsdoc/check-line-alignment': 'off', |
| 169 | 'jsdoc/multiline-blocks': 'off', |
| 170 | 'jsdoc/newline-after-description': 'off', |
| 171 | 'jsdoc/tag-lines': 'off', |
| 172 | 'jsdoc/require-param-description': 'off', |
| 173 | 'jsdoc/require-param-type': 'off', |
| 174 | 'jsdoc/require-returns': 'off', |
| 175 | 'jsdoc/require-returns-description': 'off', |
| 176 | }, |
| 177 | }, |
| 178 | { |
| 179 | files: ['**/*.{ts,tsx}'], |
| 180 | rules: { |
| 181 | 'no-restricted-syntax': [ |
| 182 | 'error', |
| 183 | { |
| 184 | selector: 'TSEnumDeclaration', |
| 185 | message: |
| 186 | 'Prefer using TypeScript union types over TypeScript enum, since TypeScript enums have a bunch of issues, see https://dev.to/dvddpl/whats-the-problem-with-typescript-enums-2okj', |
| 187 | }, |
| 188 | ], |
| 189 | 'tsdoc/syntax': 'error', |
| 190 | }, |
| 191 | }, |
| 192 | { |
| 193 | files: ['**/*.spec.{ts,js}', 'cypress/**', 'demos/**', '**/docs/**'], |
| 194 | rules: { |
| 195 | 'jsdoc/require-jsdoc': 'off', |
| 196 | '@typescript-eslint/no-unused-vars': 'off', |
| 197 | }, |
| 198 | }, |
| 199 | { |
| 200 | files: ['**/*.spec.{ts,js}', 'tests/**', 'cypress/**/*.js'], |
| 201 | rules: { |
| 202 | '@cspell/spellchecker': [ |
| 203 | 'error', |
| 204 | { |
| 205 | checkIdentifiers: false, |
| 206 | checkStrings: false, |
| 207 | checkStringTemplates: false, |
| 208 | }, |
| 209 | ], |
| 210 | }, |
| 211 | }, |
| 212 | { |
| 213 | files: ['*.html', '*.md', '**/*.md/*'], |
| 214 | rules: { |
| 215 | 'no-var': 'error', |
| 216 | 'no-undef': 'off', |
| 217 | '@typescript-eslint/no-unused-vars': 'off', |
| 218 | '@typescript-eslint/no-floating-promises': 'off', |
| 219 | '@typescript-eslint/no-misused-promises': 'off', |
| 220 | }, |
| 221 | processor: 'markdown/markdown', |
| 222 | } |
| 223 | ); |
| 224 | |