From f8efb7db57f856dba655aeeb07ca2c8947e80182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Mon, 15 Jul 2024 13:48:44 +0200 Subject: [PATCH] feat: eslint license header plugin --- configuration/eslint-config/index.js | 24 +++++- .../eslint-config/licenses/GPL-3.0-only.txt | 14 --- configuration/eslint-config/package.json | 14 +-- frontend/app/.eslintignore | 1 + frontend/app/.eslintrc.json | 85 ++++++------------- frontend/app/package.json | 6 +- package.json | 5 ++ patches/eslint-plugin-header@3.1.1.patch | 41 +++++++++ pnpm-lock.yaml | 5 ++ 9 files changed, 110 insertions(+), 85 deletions(-) delete mode 100644 configuration/eslint-config/licenses/GPL-3.0-only.txt create mode 100644 patches/eslint-plugin-header@3.1.1.patch diff --git a/configuration/eslint-config/index.js b/configuration/eslint-config/index.js index c87d6fe7..10ab439e 100644 --- a/configuration/eslint-config/index.js +++ b/configuration/eslint-config/index.js @@ -22,7 +22,7 @@ const config = { 'plugin:unicorn/recommended', 'prettier', ], - plugins: ['eslint-plugin-unicorn', 'eslint-plugin-jsdoc'], + plugins: ['eslint-plugin-unicorn', 'eslint-plugin-jsdoc', 'header'], settings: { jsdoc: { mode: 'typescript', @@ -36,6 +36,7 @@ const config = { 'unicorn/prefer-node-protocol': 'off', 'unicorn/no-process-exit': 'off', 'unicorn/no-array-reduce': 'off', + 'unicorn/prefer-event-target': 'off', 'unicorn/prevent-abbreviations': [ 'error', { @@ -77,6 +78,27 @@ const config = { }, ], + 'header/header': [ + 2, + 'block', + [ + '', + ' * Copyright (C) 2023 StApps', + ' * This program is free software: you can redistribute it and/or modify it', + ' * under the terms of the GNU General Public License as published by the Free', + ' * Software Foundation, version 3.', + ' *', + ' * This program is distributed in the hope that it will be useful, but WITHOUT', + ' * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or', + ' * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for', + ' * more details.', + ' *', + ' * You should have received a copy of the GNU General Public License along with', + ' * this program. If not, see .', + ' ', + ], + ], + '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-unused-vars': [ 'error', diff --git a/configuration/eslint-config/licenses/GPL-3.0-only.txt b/configuration/eslint-config/licenses/GPL-3.0-only.txt deleted file mode 100644 index 359a1741..00000000 --- a/configuration/eslint-config/licenses/GPL-3.0-only.txt +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (C) {{year}} {{author}} - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . diff --git a/configuration/eslint-config/package.json b/configuration/eslint-config/package.json index 4c501e9b..7d801198 100644 --- a/configuration/eslint-config/package.json +++ b/configuration/eslint-config/package.json @@ -22,11 +22,13 @@ "typescript": "5.4.2" }, "peerDependencies": { - "@typescript-eslint/eslint-plugin": "7.2.0", - "@typescript-eslint/parser": "7.2.0", - "eslint": "8.57.0", - "eslint-config-prettier": "9.1.0", - "eslint-plugin-jsdoc": "48.2.1", - "eslint-plugin-unicorn": "51.0.1" + "@typescript-eslint/eslint-plugin": "5.60.1", + "@typescript-eslint/parser": "5.60.1", + "eslint": "8.43.0", + "eslint-config-prettier": "8.8.0", + "eslint-plugin-jsdoc": "46.4.2", + "eslint-plugin-prettier": "4.2.1", + "eslint-plugin-unicorn": "47.0.0", + "eslint-plugin-header": "3.1.1" } } diff --git a/frontend/app/.eslintignore b/frontend/app/.eslintignore index 0b48282a..3cb66b48 100644 --- a/frontend/app/.eslintignore +++ b/frontend/app/.eslintignore @@ -1,2 +1,3 @@ src/app/_helpers/data node_modules +src/index.html diff --git a/frontend/app/.eslintrc.json b/frontend/app/.eslintrc.json index 57d6fbc0..a00c39da 100644 --- a/frontend/app/.eslintrc.json +++ b/frontend/app/.eslintrc.json @@ -1,76 +1,43 @@ { "root": true, "ignorePatterns": ["projects/**/*"], + "extends": ["@openstapps/eslint-config"], "overrides": [ { "files": ["*.ts"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2020, - "sourceType": "module", - "project": ["tsconfig.json", "tsconfig.spec.json", "cypress/tsconfig.json"], - "createDefaultProgram": true - }, "extends": [ - "plugin:@typescript-eslint/recommended", "plugin:@angular-eslint/recommended", - "plugin:@angular-eslint/template/process-inline-templates", - "plugin:jsdoc/recommended", - "plugin:unicorn/recommended", - "prettier" + "plugin:@angular-eslint/template/process-inline-templates" ], - "plugins": ["eslint-plugin-unicorn", "eslint-plugin-jsdoc"], - "settings": { - "jsdoc": { - "mode": "typescript" - } - }, "rules": { - "unicorn/filename-case": "error", - "unicorn/no-array-reduce": "off", - "unicorn/no-array-callback-reference": "off", - "unicorn/no-await-expression-member": "off", - "unicorn/prefer-object-from-entries": "off", - "unicorn/prefer-node-protocol": "off", - "unicorn/no-process-exit": "off", - "unicorn/prefer-event-target": "off", - "unicorn/prevent-abbreviations": [ - "warn", - { - "replacements": { - "ref": false, - "i": false - } - } - ], - "unicorn/no-nested-ternary": "off", - "unicorn/better-regex": "off", - "unicorn/no-non-null-assertion": "off", - "unicorn/consistent-function-scoping": ["error", {"checkArrowFunctions": false}], - "jsdoc/no-types": "error", - "jsdoc/require-param": "off", - "jsdoc/require-param-description": "error", - "jsdoc/check-param-names": "error", - "jsdoc/require-returns": "off", - "jsdoc/require-param-type": "off", - "jsdoc/require-returns-type": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-unused-vars": [ - "error", - { - "args": "after-used", - "argsIgnorePattern": "^_" - } - ], - "@typescript-eslint/lines-between-class-members": ["error", "always"], - "@typescript-eslint/no-explicit-any": "error", - "@angular-eslint/use-lifecycle-interface": "error" + "@angular-eslint/use-lifecycle-interface": "error", + "no-console": "off" } }, { "files": ["*.html"], - "extends": ["plugin:@angular-eslint/template/recommended", "prettier"] + "plugins": ["header"], + "extends": ["plugin:@angular-eslint/template/recommended", "prettier"], + "rules": { + "header/header": [ + 2, + "block-html", + [ + "~ Copyright (C) 2023 StApps", + " ~ This program is free software: you can redistribute it and/or modify it", + " ~ under the terms of the GNU General Public License as published by the Free", + " ~ Software Foundation, version 3.", + " ~", + " ~ This program is distributed in the hope that it will be useful, but WITHOUT", + " ~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or", + " ~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for", + " ~ more details.", + " ~", + " ~ You should have received a copy of the GNU General Public License along with", + " ~ this program. If not, see ." + ] + ] + } } ] } diff --git a/frontend/app/package.json b/frontend/app/package.json index ea5f6051..d961edae 100644 --- a/frontend/app/package.json +++ b/frontend/app/package.json @@ -138,6 +138,7 @@ "@ionic/angular-toolkit": "11.0.1", "@ionic/cli": "7.2.0", "@openstapps/prettier-config": "workspace:*", + "@openstapps/eslint-config": "workspace:*", "@openstapps/tsconfig": "workspace:*", "@types/fontkit": "2.0.7", "@types/geojson": "1.0.6", @@ -154,11 +155,6 @@ "@typescript-eslint/parser": "7.2.0", "cordova-res": "0.15.4", "cypress": "13.7.0", - "eslint": "8.57.0", - "eslint-plugin-jsdoc": "48.2.1", - "eslint-plugin-prettier": "5.1.3", - "eslint-plugin-unicorn": "51.0.1", - "fast-deep-equal": "3.1.3", "fontkit": "2.0.2", "glob": "10.3.10", "http-server": "14.1.1", diff --git a/package.json b/package.json index 314e5d22..b5c3f467 100644 --- a/package.json +++ b/package.json @@ -43,5 +43,10 @@ "turbo-ignore": "1.10.16", "typedoc": "0.25.12", "typescript": "5.4.2" + }, + "pnpm": { + "patchedDependencies": { + "eslint-plugin-header@3.1.1": "patches/eslint-plugin-header@3.1.1.patch" + } } } diff --git a/patches/eslint-plugin-header@3.1.1.patch b/patches/eslint-plugin-header@3.1.1.patch new file mode 100644 index 00000000..ede68411 --- /dev/null +++ b/patches/eslint-plugin-header@3.1.1.patch @@ -0,0 +1,41 @@ +diff --git a/lib/rules/header.js b/lib/rules/header.js +index 3504b6fc59b780674e652ad1ca944cb3577b8fed..d86dc0b490845c22f54ae83dbc52efcf448e628b 100644 +--- a/lib/rules/header.js ++++ b/lib/rules/header.js +@@ -27,6 +27,9 @@ function excludeShebangs(comments) { + // check if they are at the start of the file since that is already checked by + // hasHeader(). + function getLeadingComments(context, node) { ++ if (!node.body) { ++ return context.getSourceCode().ast.comments; ++ } + var all = excludeShebangs(context.getSourceCode().getAllComments(node.body.length ? node.body[0] : node)); + if (all[0].type.toLowerCase() === "block") { + return [all[0]]; +@@ -44,6 +47,8 @@ function genCommentBody(commentType, textArray, eol, numNewlines) { + var eols = eol.repeat(numNewlines); + if (commentType === "block") { + return "/*" + textArray.join(eol) + "*/" + eols; ++ } else if (commentType === "block-html") { ++ return "" + eols; + } else { + return "//" + textArray.join(eol + "//") + eols; + } +@@ -103,7 +108,7 @@ function hasHeader(src) { + src = src.slice(m.index + m[0].length); + } + } +- return src.substr(0, 2) === "/*" || src.substr(0, 2) === "//"; ++ return src.substr(0, 2) === "/*" || src.substr(0, 2) === "//" || src.substr(0, 4) === "