@commencis/eslint-plugin 1.2.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +13 -4
- package/dist/index.js +13 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -76,6 +76,12 @@ function getCopyrightText(startYear, isHtml) {
|
|
|
76
76
|
*/`;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// src/utils/validateCommencisCopyright.ts
|
|
80
|
+
var import_utils2 = require("@typescript-eslint/utils");
|
|
81
|
+
function validateCommencisCopyright(commentNode) {
|
|
82
|
+
return !!commentNode && commentNode.type === import_utils2.AST_TOKEN_TYPES.Block && commentNode.value.includes("Commencis") && commentNode.value.includes("Copyright");
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
// src/rules/copyright-text.ts
|
|
80
86
|
var copyright_text_default = createRule({
|
|
81
87
|
name: "copyright-text",
|
|
@@ -85,7 +91,7 @@ var copyright_text_default = createRule({
|
|
|
85
91
|
description: "Ensure files start with the required Commencis copyright text"
|
|
86
92
|
},
|
|
87
93
|
messages: {
|
|
88
|
-
missingCopyright: "File must start with the required Commencis copyright text."
|
|
94
|
+
missingCopyright: "File must start with the required Commencis copyright text with correct dates."
|
|
89
95
|
},
|
|
90
96
|
schema: [
|
|
91
97
|
{
|
|
@@ -109,8 +115,11 @@ var copyright_text_default = createRule({
|
|
|
109
115
|
return {
|
|
110
116
|
Program(node) {
|
|
111
117
|
const sourceCode = context.sourceCode.getText();
|
|
118
|
+
const firstComment = context.sourceCode.getAllComments()[0];
|
|
112
119
|
const trimmedText = sourceCode.trimStart();
|
|
113
|
-
|
|
120
|
+
const isCopyrightValid = trimmedText.startsWith(expectedCopyrightText);
|
|
121
|
+
if (!isCopyrightValid) {
|
|
122
|
+
const isCommencisCopyrightExists = validateCommencisCopyright(firstComment);
|
|
114
123
|
context.report({
|
|
115
124
|
node,
|
|
116
125
|
messageId: "missingCopyright",
|
|
@@ -118,7 +127,7 @@ var copyright_text_default = createRule({
|
|
|
118
127
|
const insertText = `${expectedCopyrightText}
|
|
119
128
|
|
|
120
129
|
`;
|
|
121
|
-
return fixer.insertTextBeforeRange([0, 0], insertText);
|
|
130
|
+
return isCommencisCopyrightExists ? fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
|
|
122
131
|
}
|
|
123
132
|
});
|
|
124
133
|
}
|
|
@@ -135,7 +144,7 @@ var rules_default = {
|
|
|
135
144
|
// package.json
|
|
136
145
|
var package_default = {
|
|
137
146
|
name: "@commencis/eslint-plugin",
|
|
138
|
-
version: "1.
|
|
147
|
+
version: "1.3.0",
|
|
139
148
|
description: "Commencis ESLint plugin",
|
|
140
149
|
author: "Commencis WEB Team",
|
|
141
150
|
license: "Apache-2.0",
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,12 @@ function getCopyrightText(startYear, isHtml) {
|
|
|
50
50
|
*/`;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
// src/utils/validateCommencisCopyright.ts
|
|
54
|
+
import { AST_TOKEN_TYPES } from "@typescript-eslint/utils";
|
|
55
|
+
function validateCommencisCopyright(commentNode) {
|
|
56
|
+
return !!commentNode && commentNode.type === AST_TOKEN_TYPES.Block && commentNode.value.includes("Commencis") && commentNode.value.includes("Copyright");
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
// src/rules/copyright-text.ts
|
|
54
60
|
var copyright_text_default = createRule({
|
|
55
61
|
name: "copyright-text",
|
|
@@ -59,7 +65,7 @@ var copyright_text_default = createRule({
|
|
|
59
65
|
description: "Ensure files start with the required Commencis copyright text"
|
|
60
66
|
},
|
|
61
67
|
messages: {
|
|
62
|
-
missingCopyright: "File must start with the required Commencis copyright text."
|
|
68
|
+
missingCopyright: "File must start with the required Commencis copyright text with correct dates."
|
|
63
69
|
},
|
|
64
70
|
schema: [
|
|
65
71
|
{
|
|
@@ -83,8 +89,11 @@ var copyright_text_default = createRule({
|
|
|
83
89
|
return {
|
|
84
90
|
Program(node) {
|
|
85
91
|
const sourceCode = context.sourceCode.getText();
|
|
92
|
+
const firstComment = context.sourceCode.getAllComments()[0];
|
|
86
93
|
const trimmedText = sourceCode.trimStart();
|
|
87
|
-
|
|
94
|
+
const isCopyrightValid = trimmedText.startsWith(expectedCopyrightText);
|
|
95
|
+
if (!isCopyrightValid) {
|
|
96
|
+
const isCommencisCopyrightExists = validateCommencisCopyright(firstComment);
|
|
88
97
|
context.report({
|
|
89
98
|
node,
|
|
90
99
|
messageId: "missingCopyright",
|
|
@@ -92,7 +101,7 @@ var copyright_text_default = createRule({
|
|
|
92
101
|
const insertText = `${expectedCopyrightText}
|
|
93
102
|
|
|
94
103
|
`;
|
|
95
|
-
return fixer.insertTextBeforeRange([0, 0], insertText);
|
|
104
|
+
return isCommencisCopyrightExists ? fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
|
|
96
105
|
}
|
|
97
106
|
});
|
|
98
107
|
}
|
|
@@ -109,7 +118,7 @@ var rules_default = {
|
|
|
109
118
|
// package.json
|
|
110
119
|
var package_default = {
|
|
111
120
|
name: "@commencis/eslint-plugin",
|
|
112
|
-
version: "1.
|
|
121
|
+
version: "1.3.0",
|
|
113
122
|
description: "Commencis ESLint plugin",
|
|
114
123
|
author: "Commencis WEB Team",
|
|
115
124
|
license: "Apache-2.0",
|