@commencis/eslint-plugin 1.2.3 → 1.3.1

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.1
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: add vue support for copyright-text replacement ([#196](https://github.com/Commencis/js-toolkit/pull/196))
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - feat: add support for Commencis copyright-text replacement to ESLint fixer ([#193](https://github.com/Commencis/js-toolkit/pull/193))
14
+
3
15
  ## 1.2.3
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -76,6 +76,15 @@ 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(comment) {
82
+ if (typeof comment === "string") {
83
+ return comment.includes("Commencis") && comment.includes("Copyright");
84
+ }
85
+ return !!comment && comment.type === import_utils2.AST_TOKEN_TYPES.Block && comment.value.includes("Commencis") && comment.value.includes("Copyright");
86
+ }
87
+
79
88
  // src/rules/copyright-text.ts
80
89
  var copyright_text_default = createRule({
81
90
  name: "copyright-text",
@@ -85,7 +94,7 @@ var copyright_text_default = createRule({
85
94
  description: "Ensure files start with the required Commencis copyright text"
86
95
  },
87
96
  messages: {
88
- missingCopyright: "File must start with the required Commencis copyright text."
97
+ missingCopyright: "File must start with the required Commencis copyright text with correct dates."
89
98
  },
90
99
  schema: [
91
100
  {
@@ -109,8 +118,13 @@ var copyright_text_default = createRule({
109
118
  return {
110
119
  Program(node) {
111
120
  const sourceCode = context.sourceCode.getText();
121
+ const firstComment = context.sourceCode.getAllComments()[0];
112
122
  const trimmedText = sourceCode.trimStart();
113
- if (!trimmedText.startsWith(expectedCopyrightText)) {
123
+ const isCopyrightValid = trimmedText.startsWith(expectedCopyrightText);
124
+ if (!isCopyrightValid) {
125
+ const isCommencisCopyrightExists = validateCommencisCopyright(
126
+ isHtml ? trimmedText : firstComment
127
+ );
114
128
  context.report({
115
129
  node,
116
130
  messageId: "missingCopyright",
@@ -118,7 +132,7 @@ var copyright_text_default = createRule({
118
132
  const insertText = `${expectedCopyrightText}
119
133
 
120
134
  `;
121
- return fixer.insertTextBeforeRange([0, 0], insertText);
135
+ return isCommencisCopyrightExists ? isHtml ? fixer.replaceTextRange([0, insertText.length], insertText) : fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
122
136
  }
123
137
  });
124
138
  }
@@ -135,7 +149,7 @@ var rules_default = {
135
149
  // package.json
136
150
  var package_default = {
137
151
  name: "@commencis/eslint-plugin",
138
- version: "1.2.3",
152
+ version: "1.3.1",
139
153
  description: "Commencis ESLint plugin",
140
154
  author: "Commencis WEB Team",
141
155
  license: "Apache-2.0",
package/dist/index.js CHANGED
@@ -50,6 +50,15 @@ 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(comment) {
56
+ if (typeof comment === "string") {
57
+ return comment.includes("Commencis") && comment.includes("Copyright");
58
+ }
59
+ return !!comment && comment.type === AST_TOKEN_TYPES.Block && comment.value.includes("Commencis") && comment.value.includes("Copyright");
60
+ }
61
+
53
62
  // src/rules/copyright-text.ts
54
63
  var copyright_text_default = createRule({
55
64
  name: "copyright-text",
@@ -59,7 +68,7 @@ var copyright_text_default = createRule({
59
68
  description: "Ensure files start with the required Commencis copyright text"
60
69
  },
61
70
  messages: {
62
- missingCopyright: "File must start with the required Commencis copyright text."
71
+ missingCopyright: "File must start with the required Commencis copyright text with correct dates."
63
72
  },
64
73
  schema: [
65
74
  {
@@ -83,8 +92,13 @@ var copyright_text_default = createRule({
83
92
  return {
84
93
  Program(node) {
85
94
  const sourceCode = context.sourceCode.getText();
95
+ const firstComment = context.sourceCode.getAllComments()[0];
86
96
  const trimmedText = sourceCode.trimStart();
87
- if (!trimmedText.startsWith(expectedCopyrightText)) {
97
+ const isCopyrightValid = trimmedText.startsWith(expectedCopyrightText);
98
+ if (!isCopyrightValid) {
99
+ const isCommencisCopyrightExists = validateCommencisCopyright(
100
+ isHtml ? trimmedText : firstComment
101
+ );
88
102
  context.report({
89
103
  node,
90
104
  messageId: "missingCopyright",
@@ -92,7 +106,7 @@ var copyright_text_default = createRule({
92
106
  const insertText = `${expectedCopyrightText}
93
107
 
94
108
  `;
95
- return fixer.insertTextBeforeRange([0, 0], insertText);
109
+ return isCommencisCopyrightExists ? isHtml ? fixer.replaceTextRange([0, insertText.length], insertText) : fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
96
110
  }
97
111
  });
98
112
  }
@@ -109,7 +123,7 @@ var rules_default = {
109
123
  // package.json
110
124
  var package_default = {
111
125
  name: "@commencis/eslint-plugin",
112
- version: "1.2.3",
126
+ version: "1.3.1",
113
127
  description: "Commencis ESLint plugin",
114
128
  author: "Commencis WEB Team",
115
129
  license: "Apache-2.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commencis/eslint-plugin",
3
- "version": "1.2.3",
3
+ "version": "1.3.1",
4
4
  "description": "Commencis ESLint plugin",
5
5
  "author": "Commencis WEB Team",
6
6
  "license": "Apache-2.0",