tz-clean 2.3.0 → 2.3.2
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/eslint.config.mjs +1 -6
- package/index.js +63 -6
- package/package.json +1 -2
package/eslint.config.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import js from '@eslint/js';
|
|
2
|
-
import jsdoc from 'eslint-plugin-jsdoc';
|
|
3
2
|
import noComments from 'eslint-plugin-no-comments';
|
|
4
3
|
import perfectionist from 'eslint-plugin-perfectionist';
|
|
5
4
|
import projectStructure from 'eslint-plugin-project-structure';
|
|
@@ -23,7 +22,6 @@ export default [
|
|
|
23
22
|
js.configs.recommended,
|
|
24
23
|
...tseslint.configs.recommended,
|
|
25
24
|
sonarjs.configs.recommended,
|
|
26
|
-
jsdoc.configs['flat/recommended'],
|
|
27
25
|
perfectionist.configs['recommended-natural'],
|
|
28
26
|
{
|
|
29
27
|
linterOptions: {
|
|
@@ -56,11 +54,8 @@ export default [
|
|
|
56
54
|
{ format: null, selector: 'objectLiteralProperty' },
|
|
57
55
|
],
|
|
58
56
|
complexity: ['warn', { max: 15 }],
|
|
59
|
-
'jsdoc/require-jsdoc': 'warn',
|
|
60
|
-
'jsdoc/require-param': 'warn',
|
|
61
|
-
'jsdoc/require-returns': 'warn',
|
|
62
57
|
'no-comments/disallowComments': 'warn',
|
|
63
|
-
'no-multiple-empty-lines': ['
|
|
58
|
+
'no-multiple-empty-lines': ['warn', { max: 1, maxBOF: 0, maxEOF: 0 }],
|
|
64
59
|
'no-redeclare': 'off',
|
|
65
60
|
'no-undef': 'off',
|
|
66
61
|
'no-unused-vars': ['error', { args: 'none', vars: 'local' }],
|
package/index.js
CHANGED
|
@@ -185,6 +185,66 @@ async function run() {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Strips all comments from a JS/TS source string without touching string literals or regex.
|
|
190
|
+
* Handles single-line (//), block (/* *\/), and preserves URLs inside strings like 'http://...'.
|
|
191
|
+
* @param {string} source - The source code string.
|
|
192
|
+
* @returns {string} The source with all comments removed.
|
|
193
|
+
*/
|
|
194
|
+
function stripCommentsFromSource(source) {
|
|
195
|
+
let result = '';
|
|
196
|
+
let i = 0;
|
|
197
|
+
const len = source.length;
|
|
198
|
+
|
|
199
|
+
while (i < len) {
|
|
200
|
+
const ch = source[i];
|
|
201
|
+
|
|
202
|
+
// String literals: single, double, or template
|
|
203
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
204
|
+
const quote = ch;
|
|
205
|
+
result += ch;
|
|
206
|
+
i++;
|
|
207
|
+
while (i < len) {
|
|
208
|
+
const sc = source[i];
|
|
209
|
+
if (sc === '\\') {
|
|
210
|
+
result += sc + (source[i + 1] || '');
|
|
211
|
+
i += 2;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
result += sc;
|
|
215
|
+
i++;
|
|
216
|
+
if (sc === quote) break;
|
|
217
|
+
}
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Block comment: /* ... */
|
|
222
|
+
if (ch === '/' && source[i + 1] === '*') {
|
|
223
|
+
i += 2;
|
|
224
|
+
while (i < len) {
|
|
225
|
+
if (source[i] === '*' && source[i + 1] === '/') {
|
|
226
|
+
i += 2;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Single-line comment: // ...
|
|
235
|
+
if (ch === '/' && source[i + 1] === '/') {
|
|
236
|
+
i += 2;
|
|
237
|
+
while (i < len && source[i] !== '\n') i++;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
result += ch;
|
|
242
|
+
i++;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
188
248
|
/**
|
|
189
249
|
* Strips all comments and excess blank lines from JS/TS files in the target paths.
|
|
190
250
|
* Removes single-line comments (//), block comments (/* *\/), eslint-disable directives,
|
|
@@ -223,11 +283,8 @@ function stripCommentsAndEmptyLines(includePaths = [], excludePaths = []) {
|
|
|
223
283
|
const original = fs.readFileSync(fullPath, 'utf-8');
|
|
224
284
|
let cleaned = original;
|
|
225
285
|
|
|
226
|
-
//
|
|
227
|
-
cleaned = cleaned
|
|
228
|
-
|
|
229
|
-
// Remove single-line comments // (including eslint-disable)
|
|
230
|
-
cleaned = cleaned.replace(/[ \t]*\/\/.*$/gm, '');
|
|
286
|
+
// Use parser-aware comment stripper (safe for URLs in strings)
|
|
287
|
+
cleaned = stripCommentsFromSource(cleaned);
|
|
231
288
|
|
|
232
289
|
// Collapse multiple blank lines into one
|
|
233
290
|
cleaned = cleaned.replace(/\n{3,}/g, '\n\n');
|
|
@@ -267,7 +324,7 @@ function runEslintTools(includePaths = [], excludePaths = []) {
|
|
|
267
324
|
|
|
268
325
|
try {
|
|
269
326
|
eslintOutput = execSync(
|
|
270
|
-
`npx eslint ${targets}
|
|
327
|
+
`npx eslint ${targets} -c "${path.join(configDir, 'eslint.config.mjs')}" -f json ${ignoreFlags}`,
|
|
271
328
|
{
|
|
272
329
|
encoding: 'utf-8',
|
|
273
330
|
maxBuffer: 1024 * 1024 * 10,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tz-clean",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@eslint/js": "^10.0.1",
|
|
46
46
|
"eslint": "^10.6.0",
|
|
47
|
-
"eslint-plugin-jsdoc": "^63.0.12",
|
|
48
47
|
"eslint-plugin-no-comments": "^1.2.1",
|
|
49
48
|
"eslint-plugin-perfectionist": "^5.10.0",
|
|
50
49
|
"eslint-plugin-project-structure": "^3.14.3",
|