Skip to content

Commit

Permalink
in eslint v9, we can only have one file of configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
csouchet committed Jan 7, 2025
1 parent 0505c73 commit 6e20074
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 146 deletions.
55 changes: 54 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@ 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 jestExtendedPlugin from 'eslint-plugin-jest-extended';
import noticePlugin from 'eslint-plugin-notice';
import playwright from 'eslint-plugin-playwright';
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'));

export default tseslint.config(
{
// Need to be in first before any other configuration
Expand Down Expand Up @@ -185,13 +193,58 @@ export default tseslint.config(
// '@typescript-eslint/unbound-method': 'error',
},
},

// 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,
},
...jestPlugin.configs['flat/recommended'],
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/**/*.test.ts'],
extends: [
// Feature of `typescript-eslint` to extend multiple configs: https://typescript-eslint.io/packages/typescript-eslint/#flat-config-extends
jestExtendedPlugin.configs['flat/recommended'],
],

plugins: { 'jest-extended': jestExtendedPlugin },
},
{
files: ['test/(bundles|e2e|performance)/*.test.ts'],
extends: [
// Feature of `typescript-eslint` to extend multiple configs: https://typescript-eslint.io/packages/typescript-eslint/#flat-config-extends
playwright.configs['flat/recommended'],
],

rules: {
/* This rule is for playwright-test and we are using jest-playwright */
'playwright/no-standalone-expect': 'off',
},
},

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.
Expand Down
1 change: 0 additions & 1 deletion scripts/add-license-header.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
import fs, { readFileSync } from 'node:fs';

import { computeBanner } from './shared/banner.mjs';
// eslint-disable-next-line import/namespace
import { getTypeFilesInformation } from './shared/types-info.mjs';

const { notSupportedTSVersionsFilePath, typesFilePath } = getTypeFilesInformation();
Expand Down
1 change: 0 additions & 1 deletion scripts/generate-types-for-not-supported-ts-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.

import * as fs from 'node:fs';

// eslint-disable-next-line import/namespace
import { getTypeFilesInformation } from './shared/types-info.mjs';

// generate a definition file for not supported TS versions. It provokes syntax error to show an explicit message about what are the supported versions.
Expand Down
6 changes: 3 additions & 3 deletions scripts/shared/types-info.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ limitations under the License.
*/

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

// generate warning when running with Node 18
// (node:75278) ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time
import packageJSON from '../../package.json' assert { type: 'json' };
const packageJSON = JSON.parse(readFileSync(path.resolve(__dirname, '../../package.json'), 'utf8'));

export const getTypeFilesInformation = () => {
const notSupportedTSVersionsFilePath = packageJSON.types;
Expand Down
1 change: 0 additions & 1 deletion src/component/mxgraph/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export const mxUtils = mxgraph.mxUtils;

/** @internal */
declare global {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Since we are overriding an existing interface in the global scope, it is not possible to convert it to a type.
interface Window {
mxForceIncludes: boolean;
mxLoadResources: boolean;
Expand Down
30 changes: 0 additions & 30 deletions test/bundles/eslint.config.mjs

This file was deleted.

29 changes: 0 additions & 29 deletions test/e2e/eslint.config.mjs

This file was deleted.

49 changes: 0 additions & 49 deletions test/eslint.config.mjs

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/helpers/model-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import { BpmnVisualization, ShapeBpmnElementKind } from '@lib/bpmn-visualization
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- Since we are overriding an existing interface in Jest, it is not possible to convert it to a type.
interface Matchers<R> {
toBeCell(): R;
toBeCellWithParentAndGeometry(modelElement: ExpectedCellWithGeometry): R;
Expand Down
29 changes: 0 additions & 29 deletions test/performance/eslint.config.mjs

This file was deleted.

1 change: 0 additions & 1 deletion test/typescript-support/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// eslint-disable-next-line import/no-unresolved -- The bpmn-visualization package may not have been built prior running eslint (it happens when running GitHub Actions)
import { BpmnVisualization } from 'bpmn-visualization';

Check failure on line 17 in test/typescript-support/src/index.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, -- --coverage)

Unable to resolve path to module 'bpmn-visualization'

Check failure on line 17 in test/typescript-support/src/index.ts

View workflow job for this annotation

GitHub Actions / build (macos-13)

Unable to resolve path to module 'bpmn-visualization'

Check failure on line 17 in test/typescript-support/src/index.ts

View workflow job for this annotation

GitHub Actions / build (windows-2022)

Unable to resolve path to module 'bpmn-visualization'

const bpmnVisualization = new BpmnVisualization({ container: 'bpmn-container' });
Expand Down

0 comments on commit 6e20074

Please sign in to comment.