tz-clean 2.0.2 → 2.1.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/README-USER.md CHANGED
@@ -9,17 +9,21 @@ This guide provides instructions on how to install and use the `tz-clean` CLI to
9
9
 
10
10
  ## Installation
11
11
 
12
- You can install this package globally using npm to use it across all your projects:
12
+ Install globally using npm to use it across all your projects:
13
13
 
14
14
  ```bash
15
15
  npm install -g tz-clean
16
16
  ```
17
17
 
18
- _(Note: If published under a scoped name, the command might be `npm install -g @your-username/tz-clean`)_
18
+ To update to the latest version:
19
+
20
+ ```bash
21
+ npm install -g tz-clean@latest
22
+ ```
19
23
 
20
24
  ## Usage
21
25
 
22
- Navigate to any project directory where you want to clean your code and simply run:
26
+ Navigate to any project directory and run:
23
27
 
24
28
  ```bash
25
29
  tz-clean
@@ -27,30 +31,75 @@ tz-clean
27
31
 
28
32
  ### Skipping Specific Tools
29
33
 
30
- You can selectively disable any of the integrated tools by passing the corresponding flag:
31
-
32
- - `--no-prettier`: Disables auto-formatting with Prettier.
33
- - `--no-eslint`: Disables linting and auto-fixing with ESLint.
34
- - `--no-typecheck`: Disables TypeScript validation.
34
+ Disable any of the integrated tools with the corresponding flag:
35
35
 
36
- **Example:**
36
+ | Flag | Description |
37
+ |---|---|
38
+ | `--no-prettier` | Disables auto-formatting with Prettier |
39
+ | `--no-eslint` | Disables linting and auto-fixing with ESLint |
40
+ | `--no-typecheck` | Disables TypeScript validation |
37
41
 
38
42
  ```bash
39
43
  tz-clean --no-prettier --no-typecheck
40
44
  ```
41
45
 
42
- ### What it does:
46
+ ### Including Specific Paths
47
+
48
+ Use `--include` to run the tools only on specific files or directories (comma-separated):
49
+
50
+ ```bash
51
+ # Analyze only the src folder
52
+ tz-clean --include src
53
+
54
+ # Analyze multiple folders
55
+ tz-clean --include src,app,lib
56
+ ```
57
+
58
+ ### Excluding Specific Paths
59
+
60
+ Use `--exclude` to skip files or directories (comma-separated):
61
+
62
+ ```bash
63
+ # Exclude a single folder
64
+ tz-clean --exclude js/libs
65
+
66
+ # Exclude multiple folders
67
+ tz-clean --exclude js/libs,dist,vendor
68
+ ```
69
+
70
+ ### Combining Options
71
+
72
+ All flags can be combined freely:
73
+
74
+ ```bash
75
+ # Analyze only src, skip typecheck
76
+ tz-clean --include src --no-typecheck
77
+
78
+ # Exclude generated files, skip prettier
79
+ tz-clean --exclude dist,vendor --no-prettier
80
+
81
+ # Include specific folder and exclude a subfolder within it
82
+ tz-clean --include src --exclude src/generated
83
+ ```
84
+
85
+ ### What It Does
86
+
87
+ The tool runs the following tasks sequentially (unless disabled):
88
+
89
+ 1. **Prettier** — Formats your code for consistent styling.
90
+ 2. **ESLint** — Lints and auto-fixes fixable issues.
91
+ 3. **TypeScript Validation** — Runs `tsc --noEmit` to check for type errors.
43
92
 
44
- The tool will sequentially run the following tasks on your project (unless disabled):
93
+ Files in the following locations are always skipped automatically:
45
94
 
46
- 1. **Prettier**: Formats your code to ensure consistent styling.
47
- 2. **ESLint**: Lints your code and automatically fixes fixable issues.
48
- 3. **TypeScript Validation**: Runs `tsc --noEmit` to check for type errors.
95
+ - `node_modules/`
96
+ - `dist/`, `build/`, `vendor/`, `libs/`
97
+ - Any file matching `*.min.js` or `*.min.cjs`
49
98
 
50
99
  ### Viewing the Report
51
100
 
52
- After analysis, you will be prompted to choose how you want to view the results:
101
+ After analysis, you will be prompted to choose how to view the results:
53
102
 
54
- 1. **Terminal Summary**: A quick overview printed directly in your terminal, including a list of auto-fixed files and detailed error logs.
55
- 2. **UI Dashboard (Browser)**: Generates a beautiful HTML report and automatically opens it in your default web browser.
56
- 3. **UI Dashboard (Hosted)**: Spawns a local server on port `8080` to host the HTML report, and opens `http://localhost:8080` in your browser.
103
+ 1. **Terminal Summary** A quick overview printed in your terminal, including auto-fixed files and detailed error logs.
104
+ 2. **UI Dashboard (Browser)** Generates an HTML report and opens it automatically in your default browser.
105
+ 3. **UI Dashboard (Hosted)** Starts a local server on port `8080` and opens `http://localhost:8080` in your browser.
package/eslint.config.mjs CHANGED
@@ -7,6 +7,18 @@ import globals from 'globals';
7
7
  import tseslint from 'typescript-eslint';
8
8
 
9
9
  export default [
10
+ {
11
+ ignores: [
12
+ '**/node_modules/**',
13
+ '**/*.min.js',
14
+ '**/*.min.cjs',
15
+ '**/*.bundle.js',
16
+ '**/dist/**',
17
+ '**/build/**',
18
+ '**/vendor/**',
19
+ '**/libs/**',
20
+ ],
21
+ },
10
22
  js.configs.recommended,
11
23
  ...tseslint.configs.recommended,
12
24
  sonarjs.configs.recommended,
package/index.js CHANGED
@@ -47,7 +47,7 @@ function generateHtmlReport(reportData, fixedFiles) {
47
47
 
48
48
  /**
49
49
  * Parses command line arguments to determine which tools to run.
50
- * @returns {{runEslint: boolean, runPrettier: boolean, runTypecheck: boolean, tools: string[]}} The configuration object.
50
+ * @returns {{runEslint: boolean, runPrettier: boolean, runTypecheck: boolean, tools: string[], includePaths: string[], excludePaths: string[]}} The configuration object.
51
51
  */
52
52
  function parseArgs() {
53
53
  const args = process.argv.slice(2);
@@ -55,12 +55,25 @@ function parseArgs() {
55
55
  const runEslint = !args.includes('--no-eslint');
56
56
  const runTypecheck = !args.includes('--no-typecheck');
57
57
 
58
+ const includePaths = [];
59
+ const excludePaths = [];
60
+
61
+ for (let i = 0; i < args.length; i++) {
62
+ if (args[i] === '--include' && args[i + 1]) {
63
+ args[i + 1].split(',').forEach((p) => includePaths.push(p.trim()));
64
+ i++;
65
+ } else if (args[i] === '--exclude' && args[i + 1]) {
66
+ args[i + 1].split(',').forEach((p) => excludePaths.push(p.trim()));
67
+ i++;
68
+ }
69
+ }
70
+
58
71
  const tools = [];
59
72
  if (runPrettier) tools.push('Prettier');
60
73
  if (runEslint) tools.push('ESLint');
61
74
  if (runTypecheck) tools.push('Typecheck');
62
75
 
63
- return { runEslint, runPrettier, runTypecheck, tools };
76
+ return { excludePaths, includePaths, runEslint, runPrettier, runTypecheck, tools };
64
77
  }
65
78
 
66
79
  /**
@@ -114,7 +127,7 @@ function printTerminalSummary(reportData, fixedFiles, totalErrors, totalWarnings
114
127
  * @returns {Promise<void>}
115
128
  */
116
129
  async function run() {
117
- const { runEslint, runPrettier, runTypecheck, tools } = parseArgs();
130
+ const { runEslint, runPrettier, runTypecheck, tools, includePaths, excludePaths } = parseArgs();
118
131
 
119
132
  if (tools.length === 0) {
120
133
  console.log('No tools selected to run.');
@@ -122,11 +135,13 @@ async function run() {
122
135
  }
123
136
 
124
137
  console.log(`🧹 Running tz-clean (${tools.join(', ')})...`);
138
+ if (includePaths.length > 0) console.log(`📁 Include: ${includePaths.join(', ')}`);
139
+ if (excludePaths.length > 0) console.log(`🚫 Exclude: ${excludePaths.join(', ')}`);
125
140
 
126
141
  try {
127
- const fixedFiles = runPrettier ? runPrettierTools() : [];
142
+ const fixedFiles = runPrettier ? runPrettierTools(includePaths, excludePaths) : [];
128
143
  const typecheckResult = runTypecheck ? runTypecheckTools() : { error: null, ran: false };
129
- const reportData = runEslint ? runEslintTools() : [];
144
+ const reportData = runEslint ? runEslintTools(includePaths, excludePaths) : [];
130
145
  const { totalErrors, totalWarnings } = calculateTotals(reportData);
131
146
 
132
147
  console.log('\n✅ Analysis complete!');
@@ -170,16 +185,25 @@ async function run() {
170
185
 
171
186
  /**
172
187
  * Executes ESLint to analyze code.
188
+ * @param {string[]} includePaths - Paths to include in analysis.
189
+ * @param {string[]} excludePaths - Paths to exclude from analysis.
173
190
  * @returns {Array<object>} An array containing the report data from ESLint.
174
191
  */
175
- function runEslintTools() {
192
+ function runEslintTools(includePaths = [], excludePaths = []) {
176
193
  let eslintOutput = '';
177
194
  let reportData = [];
195
+
196
+ const targets = includePaths.length > 0 ? includePaths.map((p) => `"${p}"`).join(' ') : '.';
197
+ const ignoreFlags = excludePaths.map((p) => `--ignore-pattern "${p}"`).join(' ');
198
+
178
199
  try {
179
- eslintOutput = execSync(`npx eslint . --fix -c "${path.join(configDir, 'eslint.config.mjs')}" -f json`, {
180
- encoding: 'utf-8',
181
- maxBuffer: 1024 * 1024 * 10,
182
- });
200
+ eslintOutput = execSync(
201
+ `npx eslint ${targets} --fix -c "${path.join(configDir, 'eslint.config.mjs')}" -f json ${ignoreFlags}`,
202
+ {
203
+ encoding: 'utf-8',
204
+ maxBuffer: 1024 * 1024 * 10,
205
+ },
206
+ );
183
207
  } catch (err) {
184
208
  eslintOutput = err.stdout;
185
209
  }
@@ -197,13 +221,19 @@ function runEslintTools() {
197
221
 
198
222
  /**
199
223
  * Executes Prettier to format files.
224
+ * @param {string[]} includePaths - Paths to include in formatting.
225
+ * @param {string[]} excludePaths - Paths to exclude from formatting.
200
226
  * @returns {string[]} An array of files that were fixed.
201
227
  */
202
- function runPrettierTools() {
228
+ function runPrettierTools(includePaths = [], excludePaths = []) {
203
229
  let fixedFiles = [];
230
+
231
+ const targets = includePaths.length > 0 ? includePaths.map((p) => `"${p}"`).join(' ') : '.';
232
+ const ignoreFlags = excludePaths.map((p) => `--ignore-path-without-warn "${p}"`).join(' ');
233
+
204
234
  try {
205
235
  const prettierOutput = execSync(
206
- `npx prettier --write . --config "${path.join(configDir, '.prettierrc')}" --ignore-unknown`,
236
+ `npx prettier --write ${targets} --config "${path.join(configDir, '.prettierrc')}" --ignore-unknown ${ignoreFlags}`,
207
237
  { encoding: 'utf-8' },
208
238
  );
209
239
  fixedFiles = prettierOutput
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "tz-clean",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
7
- "tz-clean": "./index.js"
7
+ "tz-clean": "index.js"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "vitest run",