diff --git a/.eslintrc.yaml b/.eslintrc.yaml deleted file mode 100644 index ef7ce9420208..000000000000 --- a/.eslintrc.yaml +++ /dev/null @@ -1,76 +0,0 @@ -extends: - - eslint:recommended - - plugin:jsdoc/recommended - - plugin:@typescript-eslint/recommended - - plugin:@typescript-eslint/recommended-requiring-type-checking - - plugin:wc/recommended - - plugin:lit/recommended - -plugins: - - '@typescript-eslint' - -parser: '@typescript-eslint/parser' -parserOptions: - sourceType: module - ecmaVersion: 2020 - project: - - tsconfig-eslint.json - -env: - es6: true - node: true - browser: true - jquery: true - -rules: - no-multi-asterisks: off - no-prototype-builtins: warn - no-case-declarations: warn - no-eq-null: error - no-multi-assign: error - no-negated-in-lhs: error - no-use-before-define: - - error - - nofunc - no-var: error - jsdoc/require-param-type: off - jsdoc/require-property-type: off - jsdoc/require-returns-type: off - jsdoc/check-tag-names: warn - # not compatible with jsdoc - jsdoc/check-types: off - jsdoc/no-undefined-types: warn - jsdoc/require-returns-description: warn - jsdoc/require-param-description: warn - jsdoc/require-property-description: warn - '@typescript-eslint/no-var-requires': off - '@typescript-eslint/ban-ts-comment': off - '@typescript-eslint/no-explicit-any': off - '@typescript-eslint/no-empty-function': off - '@typescript-eslint/no-non-null-assertion': off - '@typescript-eslint/explicit-module-boundary-types': warn - '@typescript-eslint/no-unsafe-member-access': warn - '@typescript-eslint/no-unsafe-assignment': warn - '@typescript-eslint/no-unsafe-return': warn - '@typescript-eslint/no-unsafe-call': warn - '@typescript-eslint/no-floating-promises': warn - '@typescript-eslint/unbound-method': warn - '@typescript-eslint/restrict-template-expressions': warn - '@typescript-eslint/no-misused-promises': warn - '@typescript-eslint/require-await': warn - '@typescript-eslint/no-unsafe-argument': warn - '@typescript-eslint/no-unused-vars': warn - '@typescript-eslint/no-unused-expressions': warn - '@typescript-eslint/prefer-promise-reject-errors': warn - # TODO: Remove before release 2.9 - '@typescript-eslint/no-require-imports': warn - '@typescript-eslint/no-useless-constructor': error - '@typescript-eslint/prefer-for-of': error - '@typescript-eslint/prefer-includes': error - '@typescript-eslint/prefer-string-starts-ends-with': error - -settings: - jsdoc: - preferredTypes: - '[]': - 'Array<>': '[]' diff --git a/Makefile b/Makefile index 670e4a2635ec..32edb90b6edf 100644 --- a/Makefile +++ b/Makefile @@ -199,7 +199,7 @@ examples-hosted-apps: .build/gmf-apps.timestamp npm run build-gmf-apps touch $@ -.build/eslint.timestamp: .eslintrc.yaml \ +.build/eslint.timestamp: eslint.config.mjs \ $(API_JS_FILES) \ $(NGEO_JS_FILES) \ $(NGEO_TEST_JS_FILES) \ @@ -208,16 +208,16 @@ examples-hosted-apps: .build/gmf-apps.timestamp $(GMF_EXAMPLES_JS_FILES) \ $(GMF_APPS_JS_FILES) \ $(BUILD_JS_FILES) - ./node_modules/.bin/eslint $(filter-out .eslintrc.yaml, $^) + ./node_modules/.bin/eslint $(filter-out eslint.config.mjs, $^) touch $@ -.build/eslint-ts.timestamp: .eslintrc.yaml \ +.build/eslint-ts.timestamp: eslint.config.mjs \ $(TS_FILES) - ./node_modules/.bin/eslint --max-warnings=0 $(filter-out .eslintrc.yaml .eslintrc-ts.yaml, $^) + ./node_modules/.bin/eslint --max-warnings=0 $(filter-out eslint.config.mjs .eslintrc-ts.yaml, $^) touch $@ .PHONY: eslint-fix -eslint-fix: .eslintrc.yaml \ +eslint-fix: eslint.config.mjs \ $(API_JS_FILES) \ $(NGEO_JS_FILES) \ $(NGEO_TEST_JS_FILES) \ @@ -225,7 +225,7 @@ eslint-fix: .eslintrc.yaml \ $(GMF_EXAMPLES_JS_FILES) \ $(GMF_APPS_JS_FILES) \ $(BUILD_JS_FILES) - ./node_modules/.bin/eslint --fix $(filter-out .eslintrc.yaml, $^) + ./node_modules/.bin/eslint --fix $(filter-out eslint.config.mjs, $^) .build/examples-hosted/partials: examples/partials/ mkdir -p $(dir $@) diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000000..cd7821cc5f4f --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,100 @@ +import typescriptEslint from '@typescript-eslint/eslint-plugin'; +import globals from 'globals'; +import tsParser from '@typescript-eslint/parser'; +import path from 'node:path'; +import {fileURLToPath} from 'node:url'; +import js from '@eslint/js'; +import {FlatCompat} from '@eslint/eslintrc'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}); + +export default [ + ...compat.extends( + 'eslint:recommended', + 'plugin:jsdoc/recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:@typescript-eslint/recommended-requiring-type-checking', + 'plugin:wc/recommended', + 'plugin:lit/recommended', + ), + { + plugins: { + '@typescript-eslint': typescriptEslint, + }, + + languageOptions: { + globals: { + ...globals.node, + ...globals.browser, + ...globals.jquery, + }, + + parser: tsParser, + ecmaVersion: 2020, + sourceType: 'module', + + parserOptions: { + project: ['tsconfig-eslint.json'], + }, + }, + + settings: { + jsdoc: { + preferredTypes: { + '[]': null, + 'Array<>': '[]', + }, + }, + }, + + rules: { + 'no-multi-asterisks': 'off', + 'no-prototype-builtins': 'warn', + 'no-case-declarations': 'warn', + 'no-eq-null': 'error', + 'no-multi-assign': 'error', + 'no-negated-in-lhs': 'error', + 'no-use-before-define': ['error', 'nofunc'], + 'no-var': 'error', + 'jsdoc/require-param-type': 'off', + 'jsdoc/require-property-type': 'off', + 'jsdoc/require-returns-type': 'off', + 'jsdoc/check-tag-names': 'warn', + 'jsdoc/check-types': 'off', + 'jsdoc/no-undefined-types': 'warn', + 'jsdoc/require-returns-description': 'warn', + 'jsdoc/require-param-description': 'warn', + 'jsdoc/require-property-description': 'warn', + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'warn', + '@typescript-eslint/no-unsafe-member-access': 'warn', + '@typescript-eslint/no-unsafe-assignment': 'warn', + '@typescript-eslint/no-unsafe-return': 'warn', + '@typescript-eslint/no-unsafe-call': 'warn', + '@typescript-eslint/no-floating-promises': 'warn', + '@typescript-eslint/unbound-method': 'warn', + '@typescript-eslint/restrict-template-expressions': 'warn', + '@typescript-eslint/no-misused-promises': 'warn', + '@typescript-eslint/require-await': 'warn', + '@typescript-eslint/no-unsafe-argument': 'warn', + '@typescript-eslint/no-unused-vars': 'warn', + '@typescript-eslint/no-unused-expressions': 'warn', + '@typescript-eslint/prefer-promise-reject-errors': 'warn', + '@typescript-eslint/no-require-imports': 'warn', + '@typescript-eslint/no-useless-constructor': 'error', + '@typescript-eslint/prefer-for-of': 'error', + '@typescript-eslint/prefer-includes': 'error', + '@typescript-eslint/prefer-string-starts-ends-with': 'error', + }, + }, +]; diff --git a/package.json b/package.json index f48d51ceb91b..83ecc1c26854 100644 --- a/package.json +++ b/package.json @@ -58,17 +58,20 @@ }, "devDependencies": { "@babel/core": "7.25.2", - "@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6", - "@babel/plugin-proposal-optional-chaining": "7.21.0", "@babel/plugin-proposal-class-properties": "7.18.6", "@babel/plugin-proposal-decorators": "7.24.7", + "@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6", + "@babel/plugin-proposal-optional-chaining": "7.21.0", "@babel/plugin-syntax-object-rest-spread": "7.8.3", "@babel/plugin-transform-spread": "7.24.7", "@babel/plugin-transform-typescript": "7.25.2", "@babel/preset-env": "7.25.3", "@babel/preset-typescript": "7.24.7", + "@eslint/eslintrc": "3.1.0", + "@eslint/js": "9.9.1", "@fortawesome/fontawesome-free": "5.15.4", "@lit/reactive-element": "1.6.3", + "@popperjs/core": "2.11.8", "@sentry/browser": "7.118.0", "@sentry/tracing": "7.114.0", "@sentry/types": "7.118.0", @@ -144,6 +147,7 @@ "floatthead": "2.2.5", "fs-extra": "11.2.0", "glob": "11.0.0", + "globals": "15.9.0", "html-webpack-plugin": "4.5.2", "i18next": "23.14.0", "i18next-browser-languagedetector": "8.0.0", @@ -179,7 +183,6 @@ "ol-layerswitcher": "4.1.2", "ol-mapbox-style": "12.3.5", "parse-absolute-css-unit": "1.0.2", - "@popperjs/core": "2.11.8", "proj4": "2.11.0", "puppeteer": "20.9.0", "qruri": "0.0.4",