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: {}