feat: eslint license header plugin

This commit is contained in:
2024-07-15 13:48:44 +02:00
parent 2a1a7a5d5b
commit f8efb7db57
9 changed files with 110 additions and 85 deletions

View File

@@ -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 <https://www.gnu.org/licenses/>.',
' ',
],
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': [
'error',

View File

@@ -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 <http://www.gnu.org/licenses/>.

View File

@@ -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"
}
}

View File

@@ -1,2 +1,3 @@
src/app/_helpers/data
node_modules
src/index.html

View File

@@ -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 <https://www.gnu.org/licenses/>."
]
]
}
}
]
}

View File

@@ -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",

View File

@@ -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"
}
}
}

View File

@@ -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 "<!--\n " + textArray.join(eol) + "\n -->" + 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) === "<!--";
}
function matchesLineEndings(src, num) {
@@ -180,7 +185,7 @@ module.exports = {
message: "missing header",
fix: canFix ? genPrependFixer(commentType, node, fixLines, eol, numNewlines) : null
});
- } else if (leadingComments[0].type.toLowerCase() !== commentType) {
+ } else if (leadingComments[0].type.toLowerCase() !== commentType.replace(/-html$/, '')) {
context.report({
loc: node.loc,
message: "header should be a {{commentType}} comment",

5
pnpm-lock.yaml generated
View File

@@ -4,6 +4,11 @@ settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
patchedDependencies:
eslint-plugin-header@3.1.1:
hash: pgohhqwij7scbwihbawhnhtg3i
path: patches/eslint-plugin-header@3.1.1.patch
importers:
.: