Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

99 changes: 0 additions & 99 deletions .eslintrc.cjs

This file was deleted.

10 changes: 4 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ updates:
# We must use an old version in packages/check-ts-support that works with the typescript version used in this package.
# As the typescript version is old, it requires an old version of "@types/node".
- dependency-name: "@types/node"
# eslint v9 requires to first switch to flat configuration
- dependency-name: "eslint"
- dependency-name: "@types/eslint"
# eslint-plugin-unicorn v57+ requires eslint v9 and flat configuration
- dependency-name: "eslint-plugin-unicorn"
groups:
css:
patterns:
Expand All @@ -41,10 +36,13 @@ updates:
- "tailwindcss"
lint:
patterns:
- "@typescript-eslint/*"
- "@eslint/*"
- "@types/eslint"
- "eslint*"
- "eslint-*"
- "lint-staged"
- "prettier"
- "typescript-eslint"
test:
patterns:
- "@jest/*"
Expand Down
233 changes: 233 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
/*
Copyright 2025 Bonitasoft S.A.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { readFileSync } from 'node:fs';
import path from 'node:path';

import eslint from '@eslint/js';
import importPlugin from 'eslint-plugin-import';
import jestPlugin from 'eslint-plugin-jest';
import jestDomPlugin from 'eslint-plugin-jest-dom';
import nodePlugin from 'eslint-plugin-n';
import noticePlugin from 'eslint-plugin-notice';
import prettierRecommendedConfig from 'eslint-plugin-prettier/recommended';
import unicornPlugin from 'eslint-plugin-unicorn';
// eslint-disable-next-line import/no-unresolved
import tseslint from 'typescript-eslint';

const jestPackagePath = path.resolve('node_modules', 'jest', 'package.json');
const jestPackage = JSON.parse(readFileSync(jestPackagePath, 'utf8'));

/**
* @type {import("eslint").Linter.FlatConfig[]}
*/
export default tseslint.config(
{
// Need to be in first before any other configuration
// https://eslint.org/docs/latest/use/configure/ignore
ignores: [
'.github/*',
'.idea/*',
// 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!
'config/*',
'**/coverage/*',
'**/dist/*',
'**/lib/*',
'**/node_modules/*',
],
},

{
plugins: {
notice: noticePlugin,
},
languageOptions: {
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
},
rules: {
'notice/notice': ['error', { templateFile: 'config/license-header.js', onNonMatchingHeader: 'replace' }],
'no-console': ['error', { allow: ['warn', 'error'] }],
},
},

// Unicorn
{
extends: [unicornPlugin.configs['flat/recommended']], // https://github.com/sindresorhus/eslint-plugin-unicorn?tab=readme-ov-file#es-module-recommended-1

rules: {
'unicorn/filename-case': [
'error',
{
cases: {
camelCase: true,
kebabCase: true,
pascalCase: true,
snakeCase: true,
},
},
],
'unicorn/prefer-keyboard-event-key': 'off', // 'key' doesn't exist in the used ES version
'unicorn/prefer-module': 'off', // We don't want to change a working configuration
'unicorn/prefer-string-replace-all': 'off', // String#replaceAll() doesn't exist in the used ES version
'unicorn/no-new-array': 'off', // In contradiction with unicorn/new-for-builtins: Use `new Array()` instead of `Array()`
'unicorn/no-null': 'off', // We don't know the impact on mxGraph code
'unicorn/no-useless-undefined': 'off', // The "undefined" value is useful where we use it and change some mxGraph code
'unicorn/prefer-global-this': 'off', // We only target the browser, so it is valid to use the window object. In addition, using 'globalThis' require additional changes in the code/configuration to work.
},
},
{
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
rules: {
'unicorn/numeric-separators-style': 'off', // With ESLint v9, the syntax with underscores is not supported in older versions of JavaScript.
'unicorn/prefer-optional-catch-binding': 'off', // With ESLint v9, the syntax 'try {} catch {}' is not supported in cjs files (not tested on other JS files).
},
},

// Import
{
extends: [
// Feature of `typescript-eslint` to extend multiple configs: https://typescript-eslint.io/packages/typescript-eslint/#flat-config-extends
importPlugin.flatConfigs.recommended,
],
rules: {
// as defined in `bpmn-visualization` b122995c
'import/newline-after-import': ['error', { count: 1 }],
'import/first': 'error',
'import/order': [
'error',
{
groups: ['type', 'builtin', 'external', 'parent', 'sibling', 'index', 'internal'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
orderImportKind: 'asc',
caseInsensitive: true,
},
},
],
},
},

// TypeScript
eslint.configs.recommended,
tseslint.configs.recommended,
tseslint.configs.stylistic,
// disable type-aware linting on JS files
{
files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
extends: [tseslint.configs.disableTypeChecked],
},

{
files: ['**/*.ts', '**/*.cts', '**/*.mts'],
extends: [
// Feature of `typescript-eslint` to extend multiple configs: https://typescript-eslint.io/packages/typescript-eslint/#flat-config-extends
importPlugin.flatConfigs.typescript,
],
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
project: '**/tsconfig.json',
},
},
},
languageOptions: {
parserOptions: {
// This setting is required if you want to use rules which require type information
// https://typescript-eslint.io/packages/parser/#project
project: ['./packages/**/tsconfig.json', './tsconfig.eslint.json'],
},
},
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
allowTypedFunctionExpressions: true,
},
],
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
accessibility: 'no-public',
},
],
'@typescript-eslint/consistent-type-exports': [
'error',
{
fixMixedExportsWithInlineTypeSpecifier: true,
},
],
'@typescript-eslint/consistent-type-imports': ['error'],
},
},

// node plugin
{
extends: [nodePlugin.configs['flat/recommended-script']],
settings: {
node: {
allowModules: ['@process-analytics/bpmn-visualization-addons', 'eslint-plugin-jest', 'eslint-plugin-jest-dom'],
},
},
rules: {
'n/file-extension-in-import': ['error', 'always'],
},
},

// test files
// There is no more cascading and hierarchy configuration files in ESLint v9.
// All configurations must be in the same file.
{
// enable jest rules on test files
files: ['test/**'],
extends: [
// Feature of `typescript-eslint` to extend multiple configs: https://typescript-eslint.io/packages/typescript-eslint/#flat-config-extends
jestPlugin.configs['flat/recommended'],
jestPlugin.configs['flat/style'],
],
plugins: {
jest: jestPlugin,
},
languageOptions: {
globals: jestPlugin.environments.globals.globals,
},
settings: {
jest: {
version: jestPackage.version,
},
},
rules: {
/* The rule list: https://github.com/jest-community/eslint-plugin-jest#rules */
'jest/prefer-expect-resolves': 'warn',
'jest/prefer-spy-on': 'warn',
'jest/prefer-todo': 'warn',
/* The rule didn't find the 'expect' in the called methods */
'jest/expect-expect': 'off',
},
},

{
files: ['test/**'],
...jestDomPlugin.configs['flat/recommended'],
},

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.
);
Loading