From ed38f1fcb2e761e3bd84c3d128163141cef844d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 26 Aug 2024 15:44:52 +0200 Subject: [PATCH] Migrate eslint config, fix --- .eslintrc.yaml | 76 ----------------------- Makefile | 23 ++++--- contribs/gmf/test/.eslintrc.yaml | 2 - eslint.config.mjs | 100 +++++++++++++++++++++++++++++++ package.json | 9 ++- src/misc/php-date-formatter.js | 1 - test/.eslintrc.yaml | 4 -- test/eslint.config.mjs | 12 ++++ test/spec/beforeeach.js | 1 - 9 files changed, 132 insertions(+), 96 deletions(-) delete mode 100644 .eslintrc.yaml delete mode 100644 contribs/gmf/test/.eslintrc.yaml create mode 100644 eslint.config.mjs delete mode 100644 test/.eslintrc.yaml create mode 100644 test/eslint.config.mjs 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..ee244851d82a 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ GMF_EXAMPLES_JS_FILES := $(GMF_EXAMPLES_HTML_FILES:.html=.js) GMF_APPS += mobile desktop desktop_alt iframe_api mobile_alt oeedit GMF_APPS_JS_FILES = $(shell find contribs/gmf/apps/ -type f -name '*.js') $(shell find contribs/gmf/apps/ -type f -name '*.ts') -BUILD_JS_FILES = $(shell ls -1 *.js) $(shell ls -1 utils/*.js) $(shell find buildtools/ -type f -name '*.js') $(shell find .storybook/ -type f -name '*.js') $(shell find cypress/ -type f -name '*.js') +BUILD_JS_FILES = $(shell ls -1 *.js) $(shell ls -1 utils/*.js) $(shell find buildtools/ -type f -name '*.js') $(shell find cypress/ -type f -name '*.js') GMF_APPS_PARTIALS_FILES = $(shell find contribs/gmf/apps/ -type f -name '*.html' -or -name '*.html.ejs') GMF_APPS_ALL_FILES = $(shell find contribs/gmf/apps/ -type f) $(NGEO_ALL_SRC_FILES) @@ -199,25 +199,30 @@ examples-hosted-apps: .build/gmf-apps.timestamp npm run build-gmf-apps touch $@ -.build/eslint.timestamp: .eslintrc.yaml \ +.build/eslint.timestamp: eslint.config.mjs .build/eslint.test.timestamp \ $(API_JS_FILES) \ $(NGEO_JS_FILES) \ - $(NGEO_TEST_JS_FILES) \ $(NGEO_EXAMPLES_JS_FILES) \ - $(GMF_TEST_JS_FILES) \ $(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 .build/eslint.test.timestamp, $^) + touch $@ + + +.build/eslint.test.timestamp: test/eslint.config.mjs \ + $(NGEO_TEST_JS_FILES) \ + $(GMF_TEST_JS_FILES) + ./node_modules/.bin/eslint --config=test/eslint.config.mjs $(filter-out test/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 +230,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/contribs/gmf/test/.eslintrc.yaml b/contribs/gmf/test/.eslintrc.yaml deleted file mode 100644 index 73255ae23afc..000000000000 --- a/contribs/gmf/test/.eslintrc.yaml +++ /dev/null @@ -1,2 +0,0 @@ -env: - jasmine: true 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 0b1352ba3837..a6c661d5e515 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": "21.11.0", "qruri": "0.0.4", diff --git a/src/misc/php-date-formatter.js b/src/misc/php-date-formatter.js index 145634cb325c..d66dc152f242 100644 --- a/src/misc/php-date-formatter.js +++ b/src/misc/php-date-formatter.js @@ -37,7 +37,6 @@ */ /* eslint max-len: 0 */ -/* eslint valid-jsdoc: 0 */ /* eslint quotes: 0 */ /* eslint indent: 0 */ /* eslint default-case: 0 */ diff --git a/test/.eslintrc.yaml b/test/.eslintrc.yaml deleted file mode 100644 index 0b39c32e9c04..000000000000 --- a/test/.eslintrc.yaml +++ /dev/null @@ -1,4 +0,0 @@ -env: - jasmine: true -globals: - sinon: true diff --git a/test/eslint.config.mjs b/test/eslint.config.mjs new file mode 100644 index 000000000000..577b2f73e9a2 --- /dev/null +++ b/test/eslint.config.mjs @@ -0,0 +1,12 @@ +import globals from 'globals'; + +export default [ + { + languageOptions: { + globals: { + ...globals.jasmine, + sinon: true, + }, + }, + }, +]; diff --git a/test/spec/beforeeach.js b/test/spec/beforeeach.js index 4aebad9743cb..09a1d086eae0 100644 --- a/test/spec/beforeeach.js +++ b/test/spec/beforeeach.js @@ -20,7 +20,6 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // @ts-nocheck -/* eslint valid-jsdoc: 0 */ import angular from 'angular'; import ngeoMainmodule from 'ngeo/mainmodule'; import i18next from 'i18next';