@commencis/eslint-plugin 1.2.2 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @commencis/eslint-plugin
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: add support for Commencis copyright-text replacement to ESLint fixer ([#193](https://github.com/Commencis/js-toolkit/pull/193))
8
+
9
+ ## 1.2.3
10
+
11
+ ### Patch Changes
12
+
13
+ - chore(deps): update typescript-eslint monorepo to v8.19.0 ([#191](https://github.com/Commencis/js-toolkit/pull/191))
14
+
3
15
  ## 1.2.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- default: () => src_default
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => index_default
24
24
  });
25
- module.exports = __toCommonJS(src_exports);
25
+ module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/configs/all.ts
28
28
  var all = {
@@ -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
- if (!trimmedText.startsWith(expectedCopyrightText)) {
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.2.2",
147
+ version: "1.3.0",
139
148
  description: "Commencis ESLint plugin",
140
149
  author: "Commencis WEB Team",
141
150
  license: "Apache-2.0",
@@ -169,7 +178,7 @@ var package_default = {
169
178
  "lint:types": "tsc --noEmit"
170
179
  },
171
180
  dependencies: {
172
- "@typescript-eslint/utils": "8.18.2"
181
+ "@typescript-eslint/utils": "8.19.0"
173
182
  },
174
183
  devDependencies: {
175
184
  "@commencis/ts-config": "workspace:*",
@@ -201,4 +210,4 @@ Object.assign(plugin.configs, {
201
210
  }
202
211
  ]
203
212
  });
204
- var src_default = plugin;
213
+ var index_default = plugin;
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
- if (!trimmedText.startsWith(expectedCopyrightText)) {
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.2.2",
121
+ version: "1.3.0",
113
122
  description: "Commencis ESLint plugin",
114
123
  author: "Commencis WEB Team",
115
124
  license: "Apache-2.0",
@@ -143,7 +152,7 @@ var package_default = {
143
152
  "lint:types": "tsc --noEmit"
144
153
  },
145
154
  dependencies: {
146
- "@typescript-eslint/utils": "8.18.2"
155
+ "@typescript-eslint/utils": "8.19.0"
147
156
  },
148
157
  devDependencies: {
149
158
  "@commencis/ts-config": "workspace:*",
@@ -175,7 +184,7 @@ Object.assign(plugin.configs, {
175
184
  }
176
185
  ]
177
186
  });
178
- var src_default = plugin;
187
+ var index_default = plugin;
179
188
  export {
180
- src_default as default
189
+ index_default as default
181
190
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commencis/eslint-plugin",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Commencis ESLint plugin",
5
5
  "author": "Commencis WEB Team",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  "require": "./dist/index.cjs"
30
30
  },
31
31
  "dependencies": {
32
- "@typescript-eslint/utils": "8.18.2"
32
+ "@typescript-eslint/utils": "8.19.0"
33
33
  },
34
34
  "devDependencies": {
35
35
  "tsup": "8.3.5",