@commencis/eslint-plugin 2.1.0 → 3.0.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 +12 -0
- package/dist/index.cjs +90 -190
- package/dist/index.d.cts +14 -12
- package/dist/index.d.mts +19 -0
- package/dist/index.mjs +118 -0
- package/package.json +7 -9
- package/dist/index.d.ts +0 -16
- package/dist/index.js +0 -195
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @commencis/eslint-plugin
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- fix: export paths ([#416](https://github.com/Commencis/js-toolkit/pull/416))
|
|
8
|
+
|
|
9
|
+
## 3.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [BreakingChange]: Introducing v3 - With cleaner dependencies and structure. Check readme files for implementations. ([#414](https://github.com/Commencis/js-toolkit/pull/414))
|
|
14
|
+
|
|
3
15
|
## 2.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all2) => {
|
|
7
|
-
for (var name in all2)
|
|
8
|
-
__defProp(target, name, { get: all2[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
default: () => index_default
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
let _typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
26
2
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// src/configs/recommended.ts
|
|
33
|
-
var recommended = {
|
|
34
|
-
"@commencis/copyright-text": "off"
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// src/constants/copyright.ts
|
|
38
|
-
var DEFAULT_START_YEAR = 2017;
|
|
39
|
-
var COPYRIGHT_TEXT = `
|
|
3
|
+
//#region src/constants/copyright.ts
|
|
4
|
+
const DEFAULT_START_YEAR = 2017;
|
|
5
|
+
const COPYRIGHT_TEXT = `
|
|
40
6
|
* Copyright {startYear}-{currentYear} Commencis. All Rights Reserved.
|
|
41
7
|
*
|
|
42
8
|
* Save to the extent permitted by law, you may not use, copy, modify,
|
|
@@ -45,174 +11,108 @@ var COPYRIGHT_TEXT = `
|
|
|
45
11
|
* Any reproduction of this material must contain this notice.
|
|
46
12
|
`.trim();
|
|
47
13
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// src/utils/createRule.ts
|
|
52
|
-
var import_utils = require("@typescript-eslint/utils");
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/constants/docsBaseUrl.ts
|
|
16
|
+
const DOCS_BASE_URL = "https://github.com/Commencis/js-toolkit/tree/main/packages/eslint-plugin/docs/rules/";
|
|
53
17
|
|
|
54
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/getDocsUrl.ts
|
|
55
20
|
function getDocsUrls(ruleName) {
|
|
56
|
-
|
|
21
|
+
return `${DOCS_BASE_URL}${ruleName}.md`;
|
|
57
22
|
}
|
|
58
23
|
|
|
59
|
-
|
|
60
|
-
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/utils/createRule.ts
|
|
26
|
+
const createRule = _typescript_eslint_utils.ESLintUtils.RuleCreator((name$1) => getDocsUrls(name$1));
|
|
61
27
|
|
|
62
|
-
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/utils/getCopyrightText.ts
|
|
63
30
|
function getCopyrightText(startYear, isHtml) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
).replace(/{currentYear}/g, currentYear.toString());
|
|
69
|
-
if (isHtml) {
|
|
70
|
-
return `<!--
|
|
71
|
-
${formattedText}
|
|
72
|
-
-->`;
|
|
73
|
-
}
|
|
74
|
-
return `/*
|
|
75
|
-
${formattedText}
|
|
76
|
-
*/`;
|
|
31
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
32
|
+
const formattedText = COPYRIGHT_TEXT.replace(/{startYear}/g, startYear.toString()).replace(/{currentYear}/g, currentYear.toString());
|
|
33
|
+
if (isHtml) return `<!--\n ${formattedText}\n-->`;
|
|
34
|
+
return `/*\n ${formattedText}\n */`;
|
|
77
35
|
}
|
|
78
36
|
|
|
79
|
-
|
|
80
|
-
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/utils/validateCommencisCopyright.ts
|
|
81
39
|
function validateCommencisCopyright(comment) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return !!comment && comment.type === import_utils2.AST_TOKEN_TYPES.Block && comment.value.includes("Commencis") && comment.value.includes("Copyright");
|
|
40
|
+
if (typeof comment === "string") return comment.includes("Commencis") && comment.includes("Copyright");
|
|
41
|
+
return !!comment && comment.type === _typescript_eslint_utils.AST_TOKEN_TYPES.Block && comment.value.includes("Commencis") && comment.value.includes("Copyright");
|
|
86
42
|
}
|
|
87
43
|
|
|
88
|
-
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/rules/copyright-text.ts
|
|
89
46
|
var copyright_text_default = createRule({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
);
|
|
128
|
-
context.report({
|
|
129
|
-
node,
|
|
130
|
-
messageId: "missingCopyright",
|
|
131
|
-
fix(fixer) {
|
|
132
|
-
const insertText = `${expectedCopyrightText}
|
|
133
|
-
|
|
134
|
-
`;
|
|
135
|
-
return isCommencisCopyrightExists ? isHtml ? fixer.replaceTextRange([0, insertText.length], insertText) : fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
47
|
+
name: "copyright-text",
|
|
48
|
+
meta: {
|
|
49
|
+
type: "suggestion",
|
|
50
|
+
docs: { description: "Ensure files start with the required Commencis copyright text" },
|
|
51
|
+
messages: { missingCopyright: "File must start with the required Commencis copyright text with correct dates." },
|
|
52
|
+
schema: [{
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: { startYear: {
|
|
55
|
+
type: "number",
|
|
56
|
+
default: DEFAULT_START_YEAR
|
|
57
|
+
} },
|
|
58
|
+
additionalProperties: false
|
|
59
|
+
}],
|
|
60
|
+
fixable: "code"
|
|
61
|
+
},
|
|
62
|
+
defaultOptions: [{ startYear: DEFAULT_START_YEAR }],
|
|
63
|
+
create(context, [options]) {
|
|
64
|
+
const startYear = options.startYear ?? DEFAULT_START_YEAR;
|
|
65
|
+
const isHtml = context.filename.endsWith(".vue");
|
|
66
|
+
const expectedCopyrightText = getCopyrightText(startYear, isHtml);
|
|
67
|
+
return { Program(node) {
|
|
68
|
+
const sourceCode = context.sourceCode.getText();
|
|
69
|
+
const firstComment = context.sourceCode.getAllComments()[0];
|
|
70
|
+
const trimmedText = sourceCode.trimStart();
|
|
71
|
+
if (!trimmedText.startsWith(expectedCopyrightText)) {
|
|
72
|
+
const isCommencisCopyrightExists = validateCommencisCopyright(isHtml ? trimmedText : firstComment);
|
|
73
|
+
context.report({
|
|
74
|
+
node,
|
|
75
|
+
messageId: "missingCopyright",
|
|
76
|
+
fix(fixer) {
|
|
77
|
+
const insertText = `${expectedCopyrightText}\n\n`;
|
|
78
|
+
return isCommencisCopyrightExists ? isHtml ? fixer.replaceTextRange([0, insertText.length], insertText) : fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
} };
|
|
83
|
+
}
|
|
142
84
|
});
|
|
143
85
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
};
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/rules/index.ts
|
|
88
|
+
var rules_default = { "copyright-text": copyright_text_default };
|
|
148
89
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
description: "Commencis ESLint plugin",
|
|
154
|
-
author: "Commencis WEB Team",
|
|
155
|
-
license: "Apache-2.0",
|
|
156
|
-
type: "module",
|
|
157
|
-
homepage: "https://github.com/Commencis/js-toolkit/tree/main/packages/eslint-plugin#readme",
|
|
158
|
-
bugs: {
|
|
159
|
-
url: "https://github.com/Commencis/js-toolkit/issues"
|
|
160
|
-
},
|
|
161
|
-
repository: {
|
|
162
|
-
type: "git",
|
|
163
|
-
url: "https://github.com/Commencis/js-toolkit.git",
|
|
164
|
-
directory: "packages/eslint-plugin"
|
|
165
|
-
},
|
|
166
|
-
publishConfig: {
|
|
167
|
-
access: "public"
|
|
168
|
-
},
|
|
169
|
-
main: "dist/index.js",
|
|
170
|
-
files: [
|
|
171
|
-
"dist",
|
|
172
|
-
"*.md",
|
|
173
|
-
"LICENSE"
|
|
174
|
-
],
|
|
175
|
-
exports: {
|
|
176
|
-
types: "./dist/index.d.ts",
|
|
177
|
-
import: "./dist/index.js",
|
|
178
|
-
require: "./dist/index.cjs"
|
|
179
|
-
},
|
|
180
|
-
scripts: {
|
|
181
|
-
dev: "tsup --watch",
|
|
182
|
-
build: "tsup",
|
|
183
|
-
"lint:types": "tsc --noEmit"
|
|
184
|
-
},
|
|
185
|
-
dependencies: {
|
|
186
|
-
"@typescript-eslint/utils": "8.49.0"
|
|
187
|
-
},
|
|
188
|
-
devDependencies: {
|
|
189
|
-
"@commencis/ts-config": "1.0.0",
|
|
190
|
-
tsup: "8.5.1",
|
|
191
|
-
typescript: "5.9.3"
|
|
192
|
-
}
|
|
193
|
-
};
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region package.json
|
|
92
|
+
var name = "@commencis/eslint-plugin";
|
|
93
|
+
var version = "3.0.1";
|
|
194
94
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/index.ts
|
|
97
|
+
const plugin = {
|
|
98
|
+
meta: {
|
|
99
|
+
name,
|
|
100
|
+
version
|
|
101
|
+
},
|
|
102
|
+
configs: {},
|
|
103
|
+
rules: rules_default
|
|
203
104
|
};
|
|
204
105
|
Object.assign(plugin.configs, {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
plugins: { "@commencis": plugin },
|
|
214
|
-
rules: recommended
|
|
215
|
-
}
|
|
216
|
-
]
|
|
106
|
+
all: [{
|
|
107
|
+
plugins: { "@commencis": plugin },
|
|
108
|
+
rules: { "@commencis/copyright-text": "error" }
|
|
109
|
+
}],
|
|
110
|
+
recommended: [{
|
|
111
|
+
plugins: { "@commencis": plugin },
|
|
112
|
+
rules: { "@commencis/copyright-text": "off" }
|
|
113
|
+
}]
|
|
217
114
|
});
|
|
218
|
-
var
|
|
115
|
+
var src_default = plugin;
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
module.exports = src_default;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
2
2
|
|
|
3
|
+
//#region src/index.d.ts
|
|
3
4
|
declare const plugin: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
meta: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
};
|
|
9
|
+
configs: {};
|
|
10
|
+
rules: {
|
|
11
|
+
'copyright-text': _typescript_eslint_utils_ts_eslint0.RuleModule<"missingCopyright", [{
|
|
12
|
+
startYear?: number;
|
|
13
|
+
}], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
14
|
+
name: string;
|
|
13
15
|
};
|
|
16
|
+
};
|
|
14
17
|
};
|
|
15
|
-
|
|
16
|
-
export { plugin as default };
|
|
18
|
+
export = plugin;
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as _typescript_eslint_utils_ts_eslint0 from "@typescript-eslint/utils/ts-eslint";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
declare const plugin: {
|
|
5
|
+
meta: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
};
|
|
9
|
+
configs: {};
|
|
10
|
+
rules: {
|
|
11
|
+
'copyright-text': _typescript_eslint_utils_ts_eslint0.RuleModule<"missingCopyright", [{
|
|
12
|
+
startYear?: number;
|
|
13
|
+
}], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener> & {
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { plugin as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { AST_TOKEN_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
|
|
3
|
+
//#region src/constants/copyright.ts
|
|
4
|
+
const DEFAULT_START_YEAR = 2017;
|
|
5
|
+
const COPYRIGHT_TEXT = `
|
|
6
|
+
* Copyright {startYear}-{currentYear} Commencis. All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* Save to the extent permitted by law, you may not use, copy, modify,
|
|
9
|
+
* distribute or create derivative works of this material or any part
|
|
10
|
+
* of it without the prior written consent of Commencis.
|
|
11
|
+
* Any reproduction of this material must contain this notice.
|
|
12
|
+
`.trim();
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/constants/docsBaseUrl.ts
|
|
16
|
+
const DOCS_BASE_URL = "https://github.com/Commencis/js-toolkit/tree/main/packages/eslint-plugin/docs/rules/";
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/utils/getDocsUrl.ts
|
|
20
|
+
function getDocsUrls(ruleName) {
|
|
21
|
+
return `${DOCS_BASE_URL}${ruleName}.md`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/utils/createRule.ts
|
|
26
|
+
const createRule = ESLintUtils.RuleCreator((name$1) => getDocsUrls(name$1));
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/utils/getCopyrightText.ts
|
|
30
|
+
function getCopyrightText(startYear, isHtml) {
|
|
31
|
+
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
32
|
+
const formattedText = COPYRIGHT_TEXT.replace(/{startYear}/g, startYear.toString()).replace(/{currentYear}/g, currentYear.toString());
|
|
33
|
+
if (isHtml) return `<!--\n ${formattedText}\n-->`;
|
|
34
|
+
return `/*\n ${formattedText}\n */`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/utils/validateCommencisCopyright.ts
|
|
39
|
+
function validateCommencisCopyright(comment) {
|
|
40
|
+
if (typeof comment === "string") return comment.includes("Commencis") && comment.includes("Copyright");
|
|
41
|
+
return !!comment && comment.type === AST_TOKEN_TYPES.Block && comment.value.includes("Commencis") && comment.value.includes("Copyright");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/rules/copyright-text.ts
|
|
46
|
+
var copyright_text_default = createRule({
|
|
47
|
+
name: "copyright-text",
|
|
48
|
+
meta: {
|
|
49
|
+
type: "suggestion",
|
|
50
|
+
docs: { description: "Ensure files start with the required Commencis copyright text" },
|
|
51
|
+
messages: { missingCopyright: "File must start with the required Commencis copyright text with correct dates." },
|
|
52
|
+
schema: [{
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: { startYear: {
|
|
55
|
+
type: "number",
|
|
56
|
+
default: DEFAULT_START_YEAR
|
|
57
|
+
} },
|
|
58
|
+
additionalProperties: false
|
|
59
|
+
}],
|
|
60
|
+
fixable: "code"
|
|
61
|
+
},
|
|
62
|
+
defaultOptions: [{ startYear: DEFAULT_START_YEAR }],
|
|
63
|
+
create(context, [options]) {
|
|
64
|
+
const startYear = options.startYear ?? DEFAULT_START_YEAR;
|
|
65
|
+
const isHtml = context.filename.endsWith(".vue");
|
|
66
|
+
const expectedCopyrightText = getCopyrightText(startYear, isHtml);
|
|
67
|
+
return { Program(node) {
|
|
68
|
+
const sourceCode = context.sourceCode.getText();
|
|
69
|
+
const firstComment = context.sourceCode.getAllComments()[0];
|
|
70
|
+
const trimmedText = sourceCode.trimStart();
|
|
71
|
+
if (!trimmedText.startsWith(expectedCopyrightText)) {
|
|
72
|
+
const isCommencisCopyrightExists = validateCommencisCopyright(isHtml ? trimmedText : firstComment);
|
|
73
|
+
context.report({
|
|
74
|
+
node,
|
|
75
|
+
messageId: "missingCopyright",
|
|
76
|
+
fix(fixer) {
|
|
77
|
+
const insertText = `${expectedCopyrightText}\n\n`;
|
|
78
|
+
return isCommencisCopyrightExists ? isHtml ? fixer.replaceTextRange([0, insertText.length], insertText) : fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
} };
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/rules/index.ts
|
|
88
|
+
var rules_default = { "copyright-text": copyright_text_default };
|
|
89
|
+
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region package.json
|
|
92
|
+
var name = "@commencis/eslint-plugin";
|
|
93
|
+
var version = "3.0.1";
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/index.ts
|
|
97
|
+
const plugin = {
|
|
98
|
+
meta: {
|
|
99
|
+
name,
|
|
100
|
+
version
|
|
101
|
+
},
|
|
102
|
+
configs: {},
|
|
103
|
+
rules: rules_default
|
|
104
|
+
};
|
|
105
|
+
Object.assign(plugin.configs, {
|
|
106
|
+
all: [{
|
|
107
|
+
plugins: { "@commencis": plugin },
|
|
108
|
+
rules: { "@commencis/copyright-text": "error" }
|
|
109
|
+
}],
|
|
110
|
+
recommended: [{
|
|
111
|
+
plugins: { "@commencis": plugin },
|
|
112
|
+
rules: { "@commencis/copyright-text": "off" }
|
|
113
|
+
}]
|
|
114
|
+
});
|
|
115
|
+
var src_default = plugin;
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
export { src_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commencis/eslint-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Commencis ESLint plugin",
|
|
5
5
|
"author": "Commencis WEB Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,21 +24,19 @@
|
|
|
24
24
|
"LICENSE"
|
|
25
25
|
],
|
|
26
26
|
"exports": {
|
|
27
|
-
"types": "./dist/index.d.
|
|
28
|
-
"import": "./dist/index.
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"import": "./dist/index.mjs",
|
|
29
29
|
"require": "./dist/index.cjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@typescript-eslint/utils": "8.
|
|
32
|
+
"@typescript-eslint/utils": "8.51.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@commencis/ts-config": "1.0.0"
|
|
36
|
-
"tsup": "8.5.1",
|
|
37
|
-
"typescript": "5.9.3"
|
|
35
|
+
"@commencis/ts-config": "1.0.0"
|
|
38
36
|
},
|
|
39
37
|
"scripts": {
|
|
40
|
-
"dev": "
|
|
41
|
-
"build": "
|
|
38
|
+
"dev": "tsdown --watch",
|
|
39
|
+
"build": "tsdown",
|
|
42
40
|
"lint:types": "tsc --noEmit"
|
|
43
41
|
}
|
|
44
42
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
-
|
|
3
|
-
declare const plugin: {
|
|
4
|
-
meta: {
|
|
5
|
-
name: string;
|
|
6
|
-
version: string;
|
|
7
|
-
};
|
|
8
|
-
configs: {};
|
|
9
|
-
rules: {
|
|
10
|
-
'copyright-text': _typescript_eslint_utils_ts_eslint.RuleModule<"missingCopyright", [{
|
|
11
|
-
startYear?: number;
|
|
12
|
-
}], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export { plugin as default };
|
package/dist/index.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
// src/configs/all.ts
|
|
2
|
-
var all = {
|
|
3
|
-
"@commencis/copyright-text": "error"
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
// src/configs/recommended.ts
|
|
7
|
-
var recommended = {
|
|
8
|
-
"@commencis/copyright-text": "off"
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
// src/constants/copyright.ts
|
|
12
|
-
var DEFAULT_START_YEAR = 2017;
|
|
13
|
-
var COPYRIGHT_TEXT = `
|
|
14
|
-
* Copyright {startYear}-{currentYear} Commencis. All Rights Reserved.
|
|
15
|
-
*
|
|
16
|
-
* Save to the extent permitted by law, you may not use, copy, modify,
|
|
17
|
-
* distribute or create derivative works of this material or any part
|
|
18
|
-
* of it without the prior written consent of Commencis.
|
|
19
|
-
* Any reproduction of this material must contain this notice.
|
|
20
|
-
`.trim();
|
|
21
|
-
|
|
22
|
-
// src/constants/docsBaseUrl.ts
|
|
23
|
-
var DOCS_BASE_URL = "https://github.com/Commencis/js-toolkit/tree/main/packages/eslint-plugin/docs/rules/";
|
|
24
|
-
|
|
25
|
-
// src/utils/createRule.ts
|
|
26
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
27
|
-
|
|
28
|
-
// src/utils/getDocsUrl.ts
|
|
29
|
-
function getDocsUrls(ruleName) {
|
|
30
|
-
return `${DOCS_BASE_URL}${ruleName}.md`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/utils/createRule.ts
|
|
34
|
-
var createRule = ESLintUtils.RuleCreator((name) => getDocsUrls(name));
|
|
35
|
-
|
|
36
|
-
// src/utils/getCopyrightText.ts
|
|
37
|
-
function getCopyrightText(startYear, isHtml) {
|
|
38
|
-
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
39
|
-
const formattedText = COPYRIGHT_TEXT.replace(
|
|
40
|
-
/{startYear}/g,
|
|
41
|
-
startYear.toString()
|
|
42
|
-
).replace(/{currentYear}/g, currentYear.toString());
|
|
43
|
-
if (isHtml) {
|
|
44
|
-
return `<!--
|
|
45
|
-
${formattedText}
|
|
46
|
-
-->`;
|
|
47
|
-
}
|
|
48
|
-
return `/*
|
|
49
|
-
${formattedText}
|
|
50
|
-
*/`;
|
|
51
|
-
}
|
|
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
|
-
|
|
62
|
-
// src/rules/copyright-text.ts
|
|
63
|
-
var copyright_text_default = createRule({
|
|
64
|
-
name: "copyright-text",
|
|
65
|
-
meta: {
|
|
66
|
-
type: "suggestion",
|
|
67
|
-
docs: {
|
|
68
|
-
description: "Ensure files start with the required Commencis copyright text"
|
|
69
|
-
},
|
|
70
|
-
messages: {
|
|
71
|
-
missingCopyright: "File must start with the required Commencis copyright text with correct dates."
|
|
72
|
-
},
|
|
73
|
-
schema: [
|
|
74
|
-
{
|
|
75
|
-
type: "object",
|
|
76
|
-
properties: {
|
|
77
|
-
startYear: {
|
|
78
|
-
type: "number",
|
|
79
|
-
default: DEFAULT_START_YEAR
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
additionalProperties: false
|
|
83
|
-
}
|
|
84
|
-
],
|
|
85
|
-
fixable: "code"
|
|
86
|
-
},
|
|
87
|
-
defaultOptions: [{ startYear: DEFAULT_START_YEAR }],
|
|
88
|
-
create(context, [options]) {
|
|
89
|
-
const startYear = options.startYear ?? DEFAULT_START_YEAR;
|
|
90
|
-
const isHtml = context.filename.endsWith(".vue");
|
|
91
|
-
const expectedCopyrightText = getCopyrightText(startYear, isHtml);
|
|
92
|
-
return {
|
|
93
|
-
Program(node) {
|
|
94
|
-
const sourceCode = context.sourceCode.getText();
|
|
95
|
-
const firstComment = context.sourceCode.getAllComments()[0];
|
|
96
|
-
const trimmedText = sourceCode.trimStart();
|
|
97
|
-
const isCopyrightValid = trimmedText.startsWith(expectedCopyrightText);
|
|
98
|
-
if (!isCopyrightValid) {
|
|
99
|
-
const isCommencisCopyrightExists = validateCommencisCopyright(
|
|
100
|
-
isHtml ? trimmedText : firstComment
|
|
101
|
-
);
|
|
102
|
-
context.report({
|
|
103
|
-
node,
|
|
104
|
-
messageId: "missingCopyright",
|
|
105
|
-
fix(fixer) {
|
|
106
|
-
const insertText = `${expectedCopyrightText}
|
|
107
|
-
|
|
108
|
-
`;
|
|
109
|
-
return isCommencisCopyrightExists ? isHtml ? fixer.replaceTextRange([0, insertText.length], insertText) : fixer.replaceText(firstComment, insertText) : fixer.insertTextBeforeRange([0, 0], insertText);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// src/rules/index.ts
|
|
119
|
-
var rules_default = {
|
|
120
|
-
"copyright-text": copyright_text_default
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// package.json
|
|
124
|
-
var package_default = {
|
|
125
|
-
name: "@commencis/eslint-plugin",
|
|
126
|
-
version: "2.1.0",
|
|
127
|
-
description: "Commencis ESLint plugin",
|
|
128
|
-
author: "Commencis WEB Team",
|
|
129
|
-
license: "Apache-2.0",
|
|
130
|
-
type: "module",
|
|
131
|
-
homepage: "https://github.com/Commencis/js-toolkit/tree/main/packages/eslint-plugin#readme",
|
|
132
|
-
bugs: {
|
|
133
|
-
url: "https://github.com/Commencis/js-toolkit/issues"
|
|
134
|
-
},
|
|
135
|
-
repository: {
|
|
136
|
-
type: "git",
|
|
137
|
-
url: "https://github.com/Commencis/js-toolkit.git",
|
|
138
|
-
directory: "packages/eslint-plugin"
|
|
139
|
-
},
|
|
140
|
-
publishConfig: {
|
|
141
|
-
access: "public"
|
|
142
|
-
},
|
|
143
|
-
main: "dist/index.js",
|
|
144
|
-
files: [
|
|
145
|
-
"dist",
|
|
146
|
-
"*.md",
|
|
147
|
-
"LICENSE"
|
|
148
|
-
],
|
|
149
|
-
exports: {
|
|
150
|
-
types: "./dist/index.d.ts",
|
|
151
|
-
import: "./dist/index.js",
|
|
152
|
-
require: "./dist/index.cjs"
|
|
153
|
-
},
|
|
154
|
-
scripts: {
|
|
155
|
-
dev: "tsup --watch",
|
|
156
|
-
build: "tsup",
|
|
157
|
-
"lint:types": "tsc --noEmit"
|
|
158
|
-
},
|
|
159
|
-
dependencies: {
|
|
160
|
-
"@typescript-eslint/utils": "8.49.0"
|
|
161
|
-
},
|
|
162
|
-
devDependencies: {
|
|
163
|
-
"@commencis/ts-config": "1.0.0",
|
|
164
|
-
tsup: "8.5.1",
|
|
165
|
-
typescript: "5.9.3"
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// src/index.ts
|
|
170
|
-
var plugin = {
|
|
171
|
-
meta: {
|
|
172
|
-
name: package_default.name,
|
|
173
|
-
version: package_default.version
|
|
174
|
-
},
|
|
175
|
-
configs: {},
|
|
176
|
-
rules: rules_default
|
|
177
|
-
};
|
|
178
|
-
Object.assign(plugin.configs, {
|
|
179
|
-
all: [
|
|
180
|
-
{
|
|
181
|
-
plugins: { "@commencis": plugin },
|
|
182
|
-
rules: all
|
|
183
|
-
}
|
|
184
|
-
],
|
|
185
|
-
recommended: [
|
|
186
|
-
{
|
|
187
|
-
plugins: { "@commencis": plugin },
|
|
188
|
-
rules: recommended
|
|
189
|
-
}
|
|
190
|
-
]
|
|
191
|
-
});
|
|
192
|
-
var index_default = plugin;
|
|
193
|
-
export {
|
|
194
|
-
index_default as default
|
|
195
|
-
};
|