From 169b02d6eacc2d81122d8412f0b1b8b67c0be6d9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 26 Aug 2024 08:47:50 +0000 Subject: [PATCH 1/3] Update typescript-eslint monorepo to v8 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 54cf4feb1e26..7da2197dc995 100644 --- a/package.json +++ b/package.json @@ -99,8 +99,8 @@ "@types/sinon": "17.0.3", "@types/tinycolor2": "1.4.6", "@types/typeahead": "0.11.32", - "@typescript-eslint/eslint-plugin": "5.62.0", - "@typescript-eslint/parser": "5.62.0", + "@typescript-eslint/eslint-plugin": "8.2.0", + "@typescript-eslint/parser": "8.2.0", "angular": "1.8.3", "angular-animate": "1.8.3", "angular-dynamic-locale": "0.1.38", From 54620e3a0bb74f58f96ec952bc83858cc97848eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 26 Aug 2024 11:37:38 +0200 Subject: [PATCH 2/3] Remove copyright plugin, replaced by a pre-commit hook --- .eslintrc.yaml | 2 - Makefile | 16 +-- buildtools/.eslintrc.yaml | 4 - buildtools/copyright/index.js | 177 ------------------------- buildtools/copyright/package-lock.json | 12 -- buildtools/copyright/package.json | 6 - lib/.eslintrc.yaml | 3 +- 7 files changed, 7 insertions(+), 213 deletions(-) delete mode 100644 buildtools/copyright/index.js delete mode 100644 buildtools/copyright/package-lock.json delete mode 100644 buildtools/copyright/package.json diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 9f873442c55f..ff099a0e6559 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -7,7 +7,6 @@ extends: - plugin:lit/recommended plugins: - - copyright - '@typescript-eslint' parser: '@typescript-eslint/parser' @@ -34,7 +33,6 @@ rules: - error - nofunc no-var: error - copyright/copyright: error jsdoc/require-param-type: off jsdoc/require-property-type: off jsdoc/require-returns-type: off diff --git a/Makefile b/Makefile index 5dcb486aea50..670e4a2635ec 100644 --- a/Makefile +++ b/Makefile @@ -199,11 +199,7 @@ examples-hosted-apps: .build/gmf-apps.timestamp npm run build-gmf-apps touch $@ -.build/node_modules.copyright.timestamp: .build/node_modules.timestamp - npm install --no-save --omit=optional --no-package-lock ./buildtools/copyright - touch $@ - -.build/eslint.timestamp: .build/node_modules.copyright.timestamp .eslintrc.yaml \ +.build/eslint.timestamp: .eslintrc.yaml \ $(API_JS_FILES) \ $(NGEO_JS_FILES) \ $(NGEO_TEST_JS_FILES) \ @@ -212,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 .build/node_modules.copyright.timestamp .eslintrc.yaml, $^) + ./node_modules/.bin/eslint $(filter-out .eslintrc.yaml, $^) touch $@ -.build/eslint-ts.timestamp: .build/node_modules.copyright.timestamp .eslintrc.yaml \ +.build/eslint-ts.timestamp: .eslintrc.yaml \ $(TS_FILES) - ./node_modules/.bin/eslint --max-warnings=0 $(filter-out .build/node_modules.copyright.timestamp .eslintrc.yaml .eslintrc-ts.yaml, $^) + ./node_modules/.bin/eslint --max-warnings=0 $(filter-out .eslintrc.yaml .eslintrc-ts.yaml, $^) touch $@ .PHONY: eslint-fix -eslint-fix: .build/node_modules.copyright.timestamp .eslintrc.yaml \ +eslint-fix: .eslintrc.yaml \ $(API_JS_FILES) \ $(NGEO_JS_FILES) \ $(NGEO_TEST_JS_FILES) \ @@ -229,7 +225,7 @@ eslint-fix: .build/node_modules.copyright.timestamp .eslintrc.yaml \ $(GMF_EXAMPLES_JS_FILES) \ $(GMF_APPS_JS_FILES) \ $(BUILD_JS_FILES) - ./node_modules/.bin/eslint --fix $(filter-out .build/node_modules.copyright.timestamp .eslintrc.yaml, $^) + ./node_modules/.bin/eslint --fix $(filter-out .eslintrc.yaml, $^) .build/examples-hosted/partials: examples/partials/ mkdir -p $(dir $@) diff --git a/buildtools/.eslintrc.yaml b/buildtools/.eslintrc.yaml index 76bffa005da9..c6ac4e38e015 100644 --- a/buildtools/.eslintrc.yaml +++ b/buildtools/.eslintrc.yaml @@ -1,9 +1,6 @@ extends: - eslint:recommended -plugins: - - copyright - parserOptions: sourceType: module ecmaVersion: 2020 @@ -23,4 +20,3 @@ rules: - error - nofunc no-var: error - copyright/copyright: error diff --git a/buildtools/copyright/index.js b/buildtools/copyright/index.js deleted file mode 100644 index 85779d1193f6..000000000000 --- a/buildtools/copyright/index.js +++ /dev/null @@ -1,177 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2020-2024 Camptocamp SA -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; - -const spawnSync = require('child_process').spawnSync; - -/** - * @param actual - * @param expected - */ -function match(actual, expected) { - if (expected.test) { - return expected.test(actual); - } else { - return expected.trim() === actual.trim(); - } -} - -/** - * @param textArray - */ -function genCommentBody(textArray) { - return `// ${textArray.join('\n// ')}\n\n\n`; -} - -/** - * @param context - * @param leadingComments - * @param fixLines - * @param headerLines - */ -function genReplaceFixer(context, leadingComments, fixLines, headerLines) { - return function (fixer) { - const start = leadingComments[0].range[0]; - let end = start; - if (context.getSourceCode().text[end] === '\n') { - end += 1; - } - if (headerLines) { - for (let i = 0; i < headerLines.length; i++) { - if (match(leadingComments[i].value, headerLines[i])) { - end = leadingComments[i].range[1]; - } else { - break; - } - } - } - - return fixer.replaceTextRange([start, end], genCommentBody(fixLines)); - }; -} - -/** - * @param context - */ -function check(context) { - const headerLines1 = ['The MIT License (MIT)', '']; - const headerLines3 = [ - '', - 'Permission is hereby granted, free of charge, to any person obtaining a copy of', - 'this software and associated documentation files (the "Software"), to deal in', - 'the Software without restriction, including without limitation the rights to', - 'use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of', - 'the Software, and to permit persons to whom the Software is furnished to do so,', - 'subject to the following conditions:', - '', - 'The above copyright notice and this permission notice shall be included in all', - 'copies or substantial portions of the Software.', - '', - 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR', - 'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS', - 'FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR', - 'COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER', - 'IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN', - 'CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.', - ]; - - return { - Program: function (node) { - const {stdout} = spawnSync('git', ['log', '--follow', '--pretty=format:%ci', context.getFilename()]); - const commits_date = stdout.toString().split('\n'); - const first_year = parseInt(commits_date[commits_date.length - 1].substring(0, 4)); - const last_year = commits_date[0].substring(0, 4); - const current_year = new Date().getFullYear(); - const headerLines2 = [ - new RegExp(`Copyright \\(c\\) ([0-9][0-9][0-9][0-9]-)?(${last_year}|${current_year}) Camptocamp SA`), - ]; - const fixLines2 = [ - first_year == current_year - ? `Copyright (c) ${first_year} Camptocamp SA` - : `Copyright (c) ${first_year}-${current_year} Camptocamp SA`, - ]; - const headerLines = Array.prototype.concat(headerLines1, headerLines2, headerLines3); - const fixLines = Array.prototype.concat(headerLines1, fixLines2, headerLines3); - - const leadingComments = ( - node.body.length ? context.getComments(node.body[0]).leading : context.getComments(node).leading - ).filter(function (comment) { - return comment.type !== 'Shebang'; - }); - if (!leadingComments.length) { - context.report({ - loc: node.loc, - message: 'missing header', - fix: function (fixer) { - return fixer.insertTextBefore(node, genCommentBody(fixLines)); - }, - }); - } else if (leadingComments[0].type.toLowerCase() !== 'line') { - context.report({ - loc: node.loc, - message: 'header should be a block comment', - fix: genReplaceFixer(context, leadingComments, fixLines), - }); - } else { - if (leadingComments.length < headerLines.length) { - context.report({ - loc: node.loc, - message: `incorrect header ${leadingComments.length} should be ${headerLines.length}`, - fix: genReplaceFixer( - context, - leadingComments, - fixLines, - Array.prototype.concat(headerLines1, [/Copyright .*/], headerLines3), - ), - }); - return; - } - for (let i = 0; i < headerLines.length; i++) { - if (!match(leadingComments[i].value, headerLines[i])) { - context.report({ - loc: node.loc, - message: `incorrect header ${leadingComments[i].value} should be ${headerLines[i]}`, - fix: genReplaceFixer( - context, - leadingComments, - fixLines, - Array.prototype.concat(headerLines1, [/Copyright .*/], headerLines3), - ), - }); - return; - } - } - } - }, - }; -} - -module.exports = { - rules: { - 'copyright': { - meta: { - fixable: 'code', - }, - create: check, - }, - }, -}; diff --git a/buildtools/copyright/package-lock.json b/buildtools/copyright/package-lock.json deleted file mode 100644 index 8d1e7115af3f..000000000000 --- a/buildtools/copyright/package-lock.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "eslint-plugin-copyright", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "eslint-plugin-copyright", - "version": "1.0.0" - } - } -} diff --git a/buildtools/copyright/package.json b/buildtools/copyright/package.json deleted file mode 100644 index f0b1d46837a4..000000000000 --- a/buildtools/copyright/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "eslint-plugin-copyright", - "version": "1.0.0", - "description": "Check the copyright", - "main": "index.js" -} diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 0d3d775414de..550e33a7cc5d 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -1,2 +1 @@ -rules: - copyright/copyright: 0 +rules: {} From 68fbed3f28c0d74830a69d06d5a23fd3ff2216b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Mon, 26 Aug 2024 11:07:53 +0200 Subject: [PATCH 3/3] Fix or ignore new checks errors --- .eslintrc.yaml | 5 +++++ buildtools/codeshift-js2ts.js | 2 +- buildtools/svg-viewbox-loader.js | 1 + src/controllers/bootstrap.js | 2 +- src/e2e/mobile.spec.ts | 2 +- src/lidar/Manager.ts | 3 ++- src/lidar/PanelElement.ts | 2 +- src/lidar/Plot.ts | 2 +- src/message/Disclaimer.js | 2 +- src/message/Notification.ts | 8 ++++---- src/message/Notification_OLD.js | 8 ++++---- src/misc/php-date-formatter.js | 2 +- src/profile/d3Elevation.ts | 4 ++-- src/query/Querent.js | 4 ++-- webpack.config.js | 2 ++ 15 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index ff099a0e6559..ef7ce9420208 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -59,6 +59,11 @@ rules: '@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 diff --git a/buildtools/codeshift-js2ts.js b/buildtools/codeshift-js2ts.js index 8f7459ae5d35..b7aaa5a17e55 100644 --- a/buildtools/codeshift-js2ts.js +++ b/buildtools/codeshift-js2ts.js @@ -566,7 +566,7 @@ function visit(indent, node, call) { if (!done) { console.log('Unknown node type'); console.log(node); - throw 'Unknown node type'; + throw new Error('Unknown node type'); } } diff --git a/buildtools/svg-viewbox-loader.js b/buildtools/svg-viewbox-loader.js index 51d75c79f638..39e91b948e3b 100644 --- a/buildtools/svg-viewbox-loader.js +++ b/buildtools/svg-viewbox-loader.js @@ -41,6 +41,7 @@ module.exports = function (source) { let tokens = simpleHTMLTokenizer.tokenize(source); tokens = tokens.map((tag) => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison if (tag.type === 'StartTag' && tag.tagName === 'svg') { let width = undefined; let height = undefined; diff --git a/src/controllers/bootstrap.js b/src/controllers/bootstrap.js index fa0f6650f5c5..fcae74d49ff6 100644 --- a/src/controllers/bootstrap.js +++ b/src/controllers/bootstrap.js @@ -112,7 +112,7 @@ function bootstrap(module) { angular.bootstrap(document, [appName]); }) .catch((error) => { - window.alert(`Failed to get the dynamic: ${error}`); + window.alert(`Failed to get the dynamic: ${error}`); // eslint-disable-line @typescript-eslint/no-base-to-string }); } diff --git a/src/e2e/mobile.spec.ts b/src/e2e/mobile.spec.ts index b582f64fafca..735d0b639bee 100644 --- a/src/e2e/mobile.spec.ts +++ b/src/e2e/mobile.spec.ts @@ -464,7 +464,7 @@ if (Cypress.browser.isHeaded) { cy.wrap(btn) .click({force: true}) .then((btn) => { - expect(btn).to.not.be.visible; + expect(btn).to.not.be.visible; // eslint-disable-line @typescript-eslint/no-unused-expressions // Check the placeholder cy.get('.tt-input').should('have.attr', 'placeholder', 'Search…'); diff --git a/src/lidar/Manager.ts b/src/lidar/Manager.ts index 7861c9b864a3..f503b2edd67b 100644 --- a/src/lidar/Manager.ts +++ b/src/lidar/Manager.ts @@ -421,7 +421,7 @@ export class LidarprofileManager { this.processBuffer_(data, iter, distanceOffset, lastLOD, resetPlot); }) .catch((err: Error) => { - throw `Error on pytree query: ${err.message}`; + throw new Error(`Error on pytree query: ${err.message}`); }); } @@ -470,6 +470,7 @@ export class LidarprofileManager { try { JSON.parse(strHeaderLocal); + // eslint-disable-next-line @typescript-eslint/no-unused-vars } catch (e) { if (!this.isPlotSetup_) { const canvas: any = d3select(lidarContainerElement.querySelector('.lidar-canvas')); diff --git a/src/lidar/PanelElement.ts b/src/lidar/PanelElement.ts index c51a3d375c04..dfe6e537ee87 100644 --- a/src/lidar/PanelElement.ts +++ b/src/lidar/PanelElement.ts @@ -257,7 +257,7 @@ export default class GmfLidarPanel extends ToolPanelElement { * @param key The key string of the toggled classification. */ toggleVisibility(classification: LidarprofileServerConfigClassification, key: string): void { - classification.visible === 0 ? (classification.visible = 1) : (classification.visible = 0); + classification.visible = classification.visible === 0 ? 1 : 0; this.setClassification(classification, parseInt(key)); } diff --git a/src/lidar/Plot.ts b/src/lidar/Plot.ts index eca67d79d0ed..7fa89435c2d3 100644 --- a/src/lidar/Plot.ts +++ b/src/lidar/Plot.ts @@ -502,7 +502,7 @@ export default class { source.clear(); const lidarPointGeom = new olGeomPoint([p.coords[0], p.coords[1]]); const lidarPointFeature = new olFeature(lidarPointGeom); - if (typeof pointClassification.color !== undefined) { + if (pointClassification.color !== undefined) { lidarPointFeature.setStyle( new olStyleStyle({ image: new olStyleCircle({ diff --git a/src/message/Disclaimer.js b/src/message/Disclaimer.js index e5b725c663ff..5bd6d4145c47 100644 --- a/src/message/Disclaimer.js +++ b/src/message/Disclaimer.js @@ -337,7 +337,7 @@ export class MessageDisclaimerService extends ngeoMessageMessage { jqueryObj.alert('close'); } } else { - console.log(`No disclaimer found for '${message}'.`); + console.log(`No disclaimer found for '${message.msg}'.`); } // (3) Remove message from cache since it's closed now. diff --git a/src/message/Notification.ts b/src/message/Notification.ts index bf132a7a42c7..e7da20d904df 100644 --- a/src/message/Notification.ts +++ b/src/message/Notification.ts @@ -106,16 +106,16 @@ export class MessageNotification extends ngeoMessageMessage { const classNames = ['alert', 'fade', 'show']; switch (type) { - case MessageType.ERROR: + case MessageType.ERROR: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-danger'); break; - case MessageType.INFORMATION: + case MessageType.INFORMATION: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-info'); break; - case MessageType.SUCCESS: + case MessageType.SUCCESS: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-success'); break; - case MessageType.WARNING: + case MessageType.WARNING: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-warning'); break; default: diff --git a/src/message/Notification_OLD.js b/src/message/Notification_OLD.js index 6c1198944a1a..3ce85091931a 100644 --- a/src/message/Notification_OLD.js +++ b/src/message/Notification_OLD.js @@ -109,16 +109,16 @@ export class MessageNotification extends ngeoMessageMessage { const classNames = ['alert', 'fade', 'show']; switch (type) { - case MessageType.ERROR: + case MessageType.ERROR: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-danger'); break; - case MessageType.INFORMATION: + case MessageType.INFORMATION: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-info'); break; - case MessageType.SUCCESS: + case MessageType.SUCCESS: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-success'); break; - case MessageType.WARNING: + case MessageType.WARNING: // eslint-disable-line @typescript-eslint/no-unsafe-enum-comparison classNames.push('alert-warning'); break; default: diff --git a/src/misc/php-date-formatter.js b/src/misc/php-date-formatter.js index 1227ff0efa49..145634cb325c 100644 --- a/src/misc/php-date-formatter.js +++ b/src/misc/php-date-formatter.js @@ -79,7 +79,7 @@ function _compare(str1, str2) { * @returns {string} */ function _lpad(value, length, chr) { - const val = value.toString(); + const val = value.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string chr = chr || '0'; return val.length < length ? _lpad(chr + val, length) : val; } diff --git a/src/profile/d3Elevation.ts b/src/profile/d3Elevation.ts index c38f0dfd7da9..3eb04507cbe3 100644 --- a/src/profile/d3Elevation.ts +++ b/src/profile/d3Elevation.ts @@ -337,7 +337,7 @@ function d3Elevation( .attr('dy', '.75em') .attr('transform', 'rotate(-90)') .style('fill', 'grey') - .text(`${yAxisLabel} [m]`); // eslint-disable-line @typescript-eslint/restrict-template-expressions + .text(`${yAxisLabel} [m]`); // eslint-disable-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-base-to-string gEnter .append('g') @@ -447,7 +447,7 @@ function d3Elevation( g.select('.x.axis').transition().call(xAxis); g.select('.x.label') - .text(`${xAxisLabel} [${xUnits}]`) // eslint-disable-line @typescript-eslint/restrict-template-expressions + .text(`${xAxisLabel} [${xUnits}]`) // eslint-disable-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-base-to-string .style('fill', 'grey') .style('shape-rendering', 'crispEdges'); diff --git a/src/query/Querent.js b/src/query/Querent.js index 1bfab83960c8..ec6223944339 100644 --- a/src/query/Querent.js +++ b/src/query/Querent.js @@ -265,8 +265,8 @@ export class Querent { */ wfsDescribeFeatureType(dataSource) { if (!dataSource.supportsAttributes) { - throw `The data source must support WFS, have a single OGCLayer that - is queryable in order to issue WFS DescribeFeatureType requests`; + throw new Error(`The data source must support WFS, have a single OGCLayer that + is queryable in order to issue WFS DescribeFeatureType requests`); } if (!dataSource.wfsUrl) { throw new Error('Missing WFS URL'); diff --git a/webpack.config.js b/webpack.config.js index 05a27404bceb..512a53c30a6c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -19,6 +19,8 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/* eslint-disable @typescript-eslint/no-require-imports */ + const {merge} = require('webpack-merge'); module.exports = (env, args) => {