|
| 1 | +/* |
| 2 | +Copyright 2025 Bonitasoft S.A. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { readFileSync } from 'node:fs'; |
| 18 | +import path from 'node:path'; |
| 19 | + |
| 20 | +import eslint from '@eslint/js'; |
| 21 | +import importPlugin from 'eslint-plugin-import'; |
| 22 | +import jestPlugin from 'eslint-plugin-jest'; |
| 23 | +import jestDomPlugin from 'eslint-plugin-jest-dom'; |
| 24 | +import nodePlugin from 'eslint-plugin-n'; |
| 25 | +import noticePlugin from 'eslint-plugin-notice'; |
| 26 | +import prettierRecommendedConfig from 'eslint-plugin-prettier/recommended'; |
| 27 | +import unicornPlugin from 'eslint-plugin-unicorn'; |
| 28 | +// eslint-disable-next-line import/no-unresolved |
| 29 | +import tsEslint from 'typescript-eslint'; |
| 30 | + |
| 31 | +const jestPackagePath = path.resolve('node_modules', 'jest', 'package.json'); |
| 32 | +const jestPackage = JSON.parse(readFileSync(jestPackagePath, 'utf8')); |
| 33 | + |
| 34 | +export default tsEslint.config( |
| 35 | + { |
| 36 | + // Need to be in first before any other configuration |
| 37 | + // https://eslint.org/docs/latest/use/configure/ignore |
| 38 | + ignores: [ |
| 39 | + '.github/*', |
| 40 | + '.idea/*', |
| 41 | + // at project root, this directory includes a js template file used to add a license header with eslint in all files. It doesn't match the license rule because it is the template! |
| 42 | + 'config/*', |
| 43 | + '**/coverage/*', |
| 44 | + '**/dist/*', |
| 45 | + '**/lib/*', |
| 46 | + '**/node_modules/*', |
| 47 | + ], |
| 48 | + }, |
| 49 | + |
| 50 | + eslint.configs.recommended, |
| 51 | + |
| 52 | + { |
| 53 | + plugins: { |
| 54 | + notice: noticePlugin, |
| 55 | + }, |
| 56 | + rules: { |
| 57 | + 'notice/notice': ['error', { templateFile: 'config/license-header.js', onNonMatchingHeader: 'replace' }], |
| 58 | + 'no-console': ['error', { allow: ['warn', 'error'] }], |
| 59 | + }, |
| 60 | + }, |
| 61 | + |
| 62 | + unicornPlugin.configs['flat/recommended'], // https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config |
| 63 | + |
| 64 | + importPlugin.flatConfigs.recommended, |
| 65 | + { |
| 66 | + rules: { |
| 67 | + // as defined in `bpmn-visualization` b122995c |
| 68 | + 'import/newline-after-import': ['error', { count: 1 }], |
| 69 | + 'import/first': 'error', |
| 70 | + 'import/order': [ |
| 71 | + 'error', |
| 72 | + { |
| 73 | + groups: ['type', 'builtin', 'external', 'parent', 'sibling', 'index', 'internal'], |
| 74 | + 'newlines-between': 'always', |
| 75 | + alphabetize: { |
| 76 | + order: 'asc', |
| 77 | + orderImportKind: 'asc', |
| 78 | + caseInsensitive: true, |
| 79 | + }, |
| 80 | + }, |
| 81 | + ], |
| 82 | + }, |
| 83 | + }, |
| 84 | + |
| 85 | + // disable type-aware linting on JS files |
| 86 | + { |
| 87 | + files: ['**/*.{js,cjs,mjs}'], |
| 88 | + ...tsEslint.configs.disableTypeChecked, |
| 89 | + }, |
| 90 | + |
| 91 | + // typescript |
| 92 | + tsEslint.configs.recommended, |
| 93 | + tsEslint.configs.stylistic, |
| 94 | + |
| 95 | + /** @type {import('@typescript-eslint').ConfigWithExtends} */ |
| 96 | + { |
| 97 | + files: ['**/*.{ts,cts,mts}'], |
| 98 | + ...importPlugin.flatConfigs.typescript, |
| 99 | + settings: { |
| 100 | + 'import/resolver': { |
| 101 | + typescript: { |
| 102 | + alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist` |
| 103 | + project: '**/tsconfig.json', |
| 104 | + }, |
| 105 | + }, |
| 106 | + }, |
| 107 | + languageOptions: { |
| 108 | + parser: tsEslint.parser, |
| 109 | + parserOptions: { |
| 110 | + // This setting is required if you want to use rules which require type information |
| 111 | + // https://typescript-eslint.io/packages/parser/#project |
| 112 | + project: ['./packages/**/tsconfig.json', './tsconfig.eslint.json'], |
| 113 | + }, |
| 114 | + }, |
| 115 | + rules: { |
| 116 | + '@typescript-eslint/explicit-function-return-type': [ |
| 117 | + 'error', |
| 118 | + { |
| 119 | + allowExpressions: true, |
| 120 | + allowTypedFunctionExpressions: true, |
| 121 | + }, |
| 122 | + ], |
| 123 | + '@typescript-eslint/explicit-member-accessibility': [ |
| 124 | + 'error', |
| 125 | + { |
| 126 | + accessibility: 'no-public', |
| 127 | + }, |
| 128 | + ], |
| 129 | + '@typescript-eslint/consistent-type-exports': [ |
| 130 | + 'error', |
| 131 | + { |
| 132 | + fixMixedExportsWithInlineTypeSpecifier: true, |
| 133 | + }, |
| 134 | + ], |
| 135 | + '@typescript-eslint/consistent-type-imports': ['error'], |
| 136 | + }, |
| 137 | + }, |
| 138 | + |
| 139 | + // node plugin |
| 140 | + { |
| 141 | + ...nodePlugin.configs['flat/recommended-script'], |
| 142 | + settings: { |
| 143 | + node: { |
| 144 | + allowModules: ['@process-analytics/bpmn-visualization-addons'], |
| 145 | + }, |
| 146 | + }, |
| 147 | + rules: { |
| 148 | + 'n/file-extension-in-import': ['error', 'always'], |
| 149 | + }, |
| 150 | + }, |
| 151 | + |
| 152 | + // for test files |
| 153 | + { |
| 154 | + files: ['**/test/**/*'], |
| 155 | + ...jestPlugin.configs['flat/recommended'], |
| 156 | + ...jestPlugin.configs['flat/style'], |
| 157 | + ...jestDomPlugin.configs['flat/recommended'], |
| 158 | + plugins: { |
| 159 | + jest: jestPlugin, |
| 160 | + 'jest-dom': jestDomPlugin, |
| 161 | + }, |
| 162 | + languageOptions: { |
| 163 | + globals: jestPlugin.environments.globals.globals, |
| 164 | + }, |
| 165 | + settings: { |
| 166 | + jest: { |
| 167 | + version: jestPackage.version, |
| 168 | + }, |
| 169 | + }, |
| 170 | + rules: { |
| 171 | + ...jestPlugin.configs['flat/recommended'].rules, |
| 172 | + ...jestPlugin.configs['flat/style'].rules, |
| 173 | + ...jestDomPlugin.configs['flat/recommended'].rules, |
| 174 | + /* The rule list: https://github.com/jest-community/eslint-plugin-jest#rules */ |
| 175 | + 'jest/prefer-expect-resolves': 'warn', |
| 176 | + 'jest/prefer-spy-on': 'warn', |
| 177 | + 'jest/prefer-todo': 'warn', |
| 178 | + }, |
| 179 | + }, |
| 180 | + |
| 181 | + prettierRecommendedConfig, // Enables eslint-plugin-prettier, eslint-config-prettier and prettier/prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration. |
| 182 | +); |
0 commit comments