@user231243/remove-debugger 0.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/.vscodeignore +9 -0
- package/docs/superpowers/plans/2026-06-03-remove-debugger-extension.md +319 -0
- package/docs/superpowers/specs/2026-06-03-remove-debugger-extension-design.md +83 -0
- package/package.json +67 -0
- package/remove-debugger-0.0.1.vsix +0 -0
- package/src/extension.ts +66 -0
- package/tsconfig.json +12 -0
package/.vscodeignore
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
# Remove Debugger VS Code Extension Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** Build a VS Code extension that adds an editor title bar button to remove `debugger;` statements and `console.*()` calls from the active JS/TS file.
|
|
6
|
+
|
|
7
|
+
**Architecture:** Single `extension.ts` file registers a command bound to an editor title bar button. When clicked, it reads the active document, applies regex patterns (controlled by user settings) to strip matching lines, then replaces the document via `WorkspaceEdit` to preserve undo history.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** TypeScript, VS Code Extension API (`vscode`), Node.js built-ins only — no external runtime dependencies.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## File Map
|
|
14
|
+
|
|
15
|
+
| File | Action | Responsibility |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `package.json` | Create | Extension manifest: name, commands, menus, settings, activationEvents |
|
|
18
|
+
| `tsconfig.json` | Create | TypeScript compiler config |
|
|
19
|
+
| `.vscodeignore` | Create | Exclude dev files from packaged extension |
|
|
20
|
+
| `src/extension.ts` | Create | `activate()`, command handler, removal logic |
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
### Task 1: Scaffold package.json
|
|
25
|
+
|
|
26
|
+
**Files:**
|
|
27
|
+
- Create: `package.json`
|
|
28
|
+
|
|
29
|
+
- [ ] **Step 1: Create package.json**
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"name": "remove-debugger",
|
|
34
|
+
"displayName": "Remove Debugger",
|
|
35
|
+
"description": "Remove debugger statements and console calls from JS/TS files",
|
|
36
|
+
"version": "0.0.1",
|
|
37
|
+
"engines": { "vscode": "^1.75.0" },
|
|
38
|
+
"categories": ["Other"],
|
|
39
|
+
"activationEvents": [
|
|
40
|
+
"onLanguage:javascript",
|
|
41
|
+
"onLanguage:typescript",
|
|
42
|
+
"onLanguage:javascriptreact",
|
|
43
|
+
"onLanguage:typescriptreact"
|
|
44
|
+
],
|
|
45
|
+
"main": "./out/extension.js",
|
|
46
|
+
"contributes": {
|
|
47
|
+
"commands": [
|
|
48
|
+
{
|
|
49
|
+
"command": "removeDebugger.clean",
|
|
50
|
+
"title": "Remove Debugger & Console",
|
|
51
|
+
"icon": "$(trash)"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"menus": {
|
|
55
|
+
"editor/title": [
|
|
56
|
+
{
|
|
57
|
+
"command": "removeDebugger.clean",
|
|
58
|
+
"when": "editorLangId == javascript || editorLangId == typescript || editorLangId == javascriptreact || editorLangId == typescriptreact",
|
|
59
|
+
"group": "navigation"
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"configuration": {
|
|
64
|
+
"title": "Remove Debugger",
|
|
65
|
+
"properties": {
|
|
66
|
+
"removeDebugger.removeDebugger": {
|
|
67
|
+
"type": "boolean",
|
|
68
|
+
"default": true,
|
|
69
|
+
"description": "Remove debugger; statements."
|
|
70
|
+
},
|
|
71
|
+
"removeDebugger.removeConsole": {
|
|
72
|
+
"type": "boolean",
|
|
73
|
+
"default": true,
|
|
74
|
+
"description": "Remove console.* calls."
|
|
75
|
+
},
|
|
76
|
+
"removeDebugger.consoleMethodsToRemove": {
|
|
77
|
+
"type": "array",
|
|
78
|
+
"default": ["log", "warn", "error", "info", "debug", "trace"],
|
|
79
|
+
"description": "Which console methods to remove when removeConsole is enabled."
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"vscode:prepublish": "npm run compile",
|
|
86
|
+
"compile": "tsc -p ./",
|
|
87
|
+
"watch": "tsc -watch -p ./"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@types/vscode": "^1.75.0",
|
|
91
|
+
"@types/node": "^18.0.0",
|
|
92
|
+
"typescript": "^5.0.0"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- [ ] **Step 2: Commit**
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
git add package.json
|
|
101
|
+
git commit -m "feat: add extension manifest with command, menu, and settings"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### Task 2: Scaffold TypeScript config and ignore file
|
|
107
|
+
|
|
108
|
+
**Files:**
|
|
109
|
+
- Create: `tsconfig.json`
|
|
110
|
+
- Create: `.vscodeignore`
|
|
111
|
+
|
|
112
|
+
- [ ] **Step 1: Create tsconfig.json**
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"compilerOptions": {
|
|
117
|
+
"module": "commonjs",
|
|
118
|
+
"target": "ES2020",
|
|
119
|
+
"outDir": "out",
|
|
120
|
+
"lib": ["ES2020"],
|
|
121
|
+
"sourceMap": true,
|
|
122
|
+
"rootDir": "src",
|
|
123
|
+
"strict": true
|
|
124
|
+
},
|
|
125
|
+
"exclude": ["node_modules", ".vscode-test"]
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- [ ] **Step 2: Create .vscodeignore**
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
.vscode/**
|
|
133
|
+
src/**
|
|
134
|
+
.gitignore
|
|
135
|
+
tsconfig.json
|
|
136
|
+
**/*.map
|
|
137
|
+
**/*.ts
|
|
138
|
+
!out/**
|
|
139
|
+
node_modules/**
|
|
140
|
+
docs/**
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
- [ ] **Step 3: Commit**
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git add tsconfig.json .vscodeignore
|
|
147
|
+
git commit -m "feat: add tsconfig and vscodeignore"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
### Task 3: Install dev dependencies
|
|
153
|
+
|
|
154
|
+
**Files:**
|
|
155
|
+
- Modify: (node_modules, package-lock.json — generated)
|
|
156
|
+
|
|
157
|
+
- [ ] **Step 1: Install**
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm install
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Expected: `node_modules/` created, `package-lock.json` generated. No errors.
|
|
164
|
+
|
|
165
|
+
- [ ] **Step 2: Add .gitignore**
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
node_modules/
|
|
169
|
+
out/
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
- [ ] **Step 3: Commit**
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
git add .gitignore package-lock.json
|
|
176
|
+
git commit -m "chore: add gitignore and lock file"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### Task 4: Implement extension.ts
|
|
182
|
+
|
|
183
|
+
**Files:**
|
|
184
|
+
- Create: `src/extension.ts`
|
|
185
|
+
|
|
186
|
+
- [ ] **Step 1: Create src/extension.ts**
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import * as vscode from 'vscode';
|
|
190
|
+
|
|
191
|
+
export function activate(context: vscode.ExtensionContext): void {
|
|
192
|
+
const disposable = vscode.commands.registerCommand('removeDebugger.clean', () => {
|
|
193
|
+
const editor = vscode.window.activeTextEditor;
|
|
194
|
+
if (!editor) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const config = vscode.workspace.getConfiguration('removeDebugger');
|
|
199
|
+
const shouldRemoveDebugger = config.get<boolean>('removeDebugger', true);
|
|
200
|
+
const shouldRemoveConsole = config.get<boolean>('removeConsole', true);
|
|
201
|
+
const consoleMethods = config.get<string[]>('consoleMethodsToRemove', [
|
|
202
|
+
'log', 'warn', 'error', 'info', 'debug', 'trace',
|
|
203
|
+
]);
|
|
204
|
+
|
|
205
|
+
const text = editor.document.getText();
|
|
206
|
+
const cleaned = cleanText(text, shouldRemoveDebugger, shouldRemoveConsole, consoleMethods);
|
|
207
|
+
|
|
208
|
+
if (cleaned === text) {
|
|
209
|
+
vscode.window.showInformationMessage('No debugger statements or console calls found.');
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const edit = new vscode.WorkspaceEdit();
|
|
214
|
+
const fullRange = new vscode.Range(
|
|
215
|
+
editor.document.positionAt(0),
|
|
216
|
+
editor.document.positionAt(text.length)
|
|
217
|
+
);
|
|
218
|
+
edit.replace(editor.document.uri, fullRange, cleaned);
|
|
219
|
+
vscode.workspace.applyEdit(edit);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
context.subscriptions.push(disposable);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function cleanText(
|
|
226
|
+
text: string,
|
|
227
|
+
removeDebugger: boolean,
|
|
228
|
+
removeConsole: boolean,
|
|
229
|
+
consoleMethods: string[]
|
|
230
|
+
): string {
|
|
231
|
+
const lines = text.split('\n');
|
|
232
|
+
const filtered = lines.filter(line => {
|
|
233
|
+
if (removeDebugger && /^\s*debugger\s*;?\s*$/.test(line)) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (removeConsole && consoleMethods.length > 0) {
|
|
237
|
+
const methodPattern = consoleMethods.map(m => escapeRegex(m)).join('|');
|
|
238
|
+
const consoleRegex = new RegExp(
|
|
239
|
+
`^\\s*console\\.(${methodPattern})\\s*\\(.*\\)\\s*;?\\s*$`
|
|
240
|
+
);
|
|
241
|
+
if (consoleRegex.test(line)) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
});
|
|
247
|
+
return filtered.join('\n');
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function escapeRegex(s: string): string {
|
|
251
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function deactivate(): void {}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
- [ ] **Step 2: Compile**
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
npm run compile
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Expected: `out/extension.js` and `out/extension.js.map` created. No TypeScript errors.
|
|
264
|
+
|
|
265
|
+
- [ ] **Step 3: Commit**
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
git add src/extension.ts
|
|
269
|
+
git commit -m "feat: implement removal logic and command handler"
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
### Task 5: Manual verification
|
|
275
|
+
|
|
276
|
+
- [ ] **Step 1: Open VS Code in the project folder**
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
code .
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- [ ] **Step 2: Press F5** to launch the Extension Development Host (a new VS Code window with the extension loaded).
|
|
283
|
+
|
|
284
|
+
- [ ] **Step 3: Create a test file** in the dev host window. Save it as `test.js` with:
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
function example() {
|
|
288
|
+
console.log('hello');
|
|
289
|
+
debugger;
|
|
290
|
+
console.warn('oops');
|
|
291
|
+
const x = 1 + 1;
|
|
292
|
+
console.error('bad');
|
|
293
|
+
return x;
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
- [ ] **Step 4: Verify the trash-can button** appears in the editor title bar (top-right) while `test.js` is active.
|
|
298
|
+
|
|
299
|
+
- [ ] **Step 5: Click the button.** Expected result:
|
|
300
|
+
|
|
301
|
+
```javascript
|
|
302
|
+
function example() {
|
|
303
|
+
const x = 1 + 1;
|
|
304
|
+
return x;
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
- [ ] **Step 6: Press Ctrl+Z.** Expected: original file content restored.
|
|
309
|
+
|
|
310
|
+
- [ ] **Step 7: Open a `.json` file.** Verify the trash-can button does NOT appear.
|
|
311
|
+
|
|
312
|
+
- [ ] **Step 8: Test settings.** Open VS Code settings (Ctrl+,), search "Remove Debugger". Set `removeConsole` to `false`. Open `test.js` again, click the button. Expected: only `debugger;` removed, `console.*` lines kept.
|
|
313
|
+
|
|
314
|
+
- [ ] **Step 9: Commit**
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
git add -A
|
|
318
|
+
git commit -m "chore: verified extension works end-to-end"
|
|
319
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Remove Debugger VS Code Extension — Design Spec
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-06-03
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
A lightweight VS Code extension that removes `debugger;` statements and `console.*()` calls from the active JavaScript or TypeScript file via a single click on an editor title bar button.
|
|
8
|
+
|
|
9
|
+
## Target Languages
|
|
10
|
+
|
|
11
|
+
JavaScript, TypeScript, JSX, TSX (language IDs: `javascript`, `typescript`, `javascriptreact`, `typescriptreact`).
|
|
12
|
+
|
|
13
|
+
## Activation
|
|
14
|
+
|
|
15
|
+
The extension activates when a JS/TS file becomes the active editor. A button appears in the editor title bar (top-right) only for supported language IDs, registered via the `editor/title` contribution point in `package.json`.
|
|
16
|
+
|
|
17
|
+
## Removal Logic
|
|
18
|
+
|
|
19
|
+
Approach: regex-based line replacement. When the button is clicked, the extension:
|
|
20
|
+
|
|
21
|
+
1. Reads the full text of the active document.
|
|
22
|
+
2. Applies enabled regex patterns in sequence to remove matching lines.
|
|
23
|
+
3. Replaces the document content via a `WorkspaceEdit` — this preserves undo history.
|
|
24
|
+
|
|
25
|
+
**Known limitation:** Multi-line `console.*()` calls (arguments spanning multiple lines) are not removed — only the opening line is matched. This is acceptable for a dev-convenience tool.
|
|
26
|
+
|
|
27
|
+
### Patterns
|
|
28
|
+
|
|
29
|
+
| What | Regex (per line) |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `debugger;` | `/^\s*debugger\s*;?\s*$/` |
|
|
32
|
+
| `console.<method>(...)` | `/^\s*console\.(log\|warn\|error\|...)\s*\(.*\)\s*;?\s*$/` |
|
|
33
|
+
|
|
34
|
+
Lines that are entirely consumed by the match are deleted (including the trailing newline). Lines where a `console.*` call is embedded in a larger expression (e.g., `return console.log(x)`) are left untouched.
|
|
35
|
+
|
|
36
|
+
## Settings
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
"removeDebugger.removeDebugger": {
|
|
40
|
+
"type": "boolean",
|
|
41
|
+
"default": true,
|
|
42
|
+
"description": "Remove debugger; statements."
|
|
43
|
+
},
|
|
44
|
+
"removeDebugger.removeConsole": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"default": true,
|
|
47
|
+
"description": "Remove console.* calls."
|
|
48
|
+
},
|
|
49
|
+
"removeDebugger.consoleMethodsToRemove": {
|
|
50
|
+
"type": "array",
|
|
51
|
+
"default": ["log", "warn", "error", "info", "debug", "trace"],
|
|
52
|
+
"description": "Which console methods to remove when removeConsole is enabled."
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Users can keep `console.error` while removing `console.log` by editing `consoleMethodsToRemove`.
|
|
57
|
+
|
|
58
|
+
## Project Structure
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
remove-debugger-vs-extension/
|
|
62
|
+
├── src/
|
|
63
|
+
│ └── extension.ts # activate(), command handler, removal logic
|
|
64
|
+
├── package.json # manifest: commands, menus, settings, activationEvents
|
|
65
|
+
├── tsconfig.json
|
|
66
|
+
└── .vscodeignore
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
All logic lives in `extension.ts`. No external runtime dependencies — only the VS Code API and Node built-ins.
|
|
70
|
+
|
|
71
|
+
## Error Handling
|
|
72
|
+
|
|
73
|
+
- If no active editor is open, the command is a no-op (button is hidden by `when` clause).
|
|
74
|
+
- If the document is not a supported language, the button does not render.
|
|
75
|
+
- If no matches are found, the document is unchanged (no empty edit applied).
|
|
76
|
+
|
|
77
|
+
## Testing
|
|
78
|
+
|
|
79
|
+
Manual testing only for initial version:
|
|
80
|
+
- Open a JS/TS file with `debugger;` and `console.log()` lines, click the button, verify removal.
|
|
81
|
+
- Verify undo (`Ctrl+Z`) restores the original content.
|
|
82
|
+
- Verify settings (`removeConsole: false`) correctly skips console removal.
|
|
83
|
+
- Verify button does not appear on non-JS/TS files (e.g., `.json`, `.md`).
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@user231243/remove-debugger",
|
|
3
|
+
"publisher": "user231243",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"displayName": "Remove Debugger",
|
|
8
|
+
"description": "Remove debugger statements and console calls from JS/TS files",
|
|
9
|
+
"version": "0.0.1",
|
|
10
|
+
"engines": { "vscode": "^1.75.0" },
|
|
11
|
+
"categories": ["Other"],
|
|
12
|
+
"activationEvents": [
|
|
13
|
+
"onLanguage:javascript",
|
|
14
|
+
"onLanguage:typescript",
|
|
15
|
+
"onLanguage:javascriptreact",
|
|
16
|
+
"onLanguage:typescriptreact"
|
|
17
|
+
],
|
|
18
|
+
"main": "./out/extension.js",
|
|
19
|
+
"contributes": {
|
|
20
|
+
"commands": [
|
|
21
|
+
{
|
|
22
|
+
"command": "removeDebugger.clean",
|
|
23
|
+
"title": "Remove Debugger & Console",
|
|
24
|
+
"icon": "$(trash)"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"menus": {
|
|
28
|
+
"editor/title": [
|
|
29
|
+
{
|
|
30
|
+
"command": "removeDebugger.clean",
|
|
31
|
+
"when": "editorLangId == javascript || editorLangId == typescript || editorLangId == javascriptreact || editorLangId == typescriptreact",
|
|
32
|
+
"group": "navigation"
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"configuration": {
|
|
37
|
+
"title": "Remove Debugger",
|
|
38
|
+
"properties": {
|
|
39
|
+
"removeDebugger.removeDebugger": {
|
|
40
|
+
"type": "boolean",
|
|
41
|
+
"default": true,
|
|
42
|
+
"description": "Remove debugger; statements."
|
|
43
|
+
},
|
|
44
|
+
"removeDebugger.removeConsole": {
|
|
45
|
+
"type": "boolean",
|
|
46
|
+
"default": true,
|
|
47
|
+
"description": "Remove console.* calls."
|
|
48
|
+
},
|
|
49
|
+
"removeDebugger.consoleMethodsToRemove": {
|
|
50
|
+
"type": "array",
|
|
51
|
+
"default": ["log", "warn", "error", "info", "debug", "trace"],
|
|
52
|
+
"description": "Which console methods to remove when removeConsole is enabled."
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"vscode:prepublish": "npm run compile",
|
|
59
|
+
"compile": "tsc -p ./",
|
|
60
|
+
"watch": "tsc -watch -p ./"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/vscode": "^1.75.0",
|
|
64
|
+
"@types/node": "^18.0.0",
|
|
65
|
+
"typescript": "^5.0.0"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
Binary file
|
package/src/extension.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
|
|
3
|
+
export function activate(context: vscode.ExtensionContext): void {
|
|
4
|
+
const disposable = vscode.commands.registerCommand('removeDebugger.clean', () => {
|
|
5
|
+
const editor = vscode.window.activeTextEditor;
|
|
6
|
+
if (!editor) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const config = vscode.workspace.getConfiguration('removeDebugger');
|
|
11
|
+
const shouldRemoveDebugger = config.get<boolean>('removeDebugger', true);
|
|
12
|
+
const shouldRemoveConsole = config.get<boolean>('removeConsole', true);
|
|
13
|
+
const consoleMethods = config.get<string[]>('consoleMethodsToRemove', [
|
|
14
|
+
'log', 'warn', 'error', 'info', 'debug', 'trace',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
const text = editor.document.getText();
|
|
18
|
+
const cleaned = cleanText(text, shouldRemoveDebugger, shouldRemoveConsole, consoleMethods);
|
|
19
|
+
|
|
20
|
+
if (cleaned === text) {
|
|
21
|
+
vscode.window.showInformationMessage('No debugger statements or console calls found.');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const edit = new vscode.WorkspaceEdit();
|
|
26
|
+
const fullRange = new vscode.Range(
|
|
27
|
+
editor.document.positionAt(0),
|
|
28
|
+
editor.document.positionAt(text.length)
|
|
29
|
+
);
|
|
30
|
+
edit.replace(editor.document.uri, fullRange, cleaned);
|
|
31
|
+
vscode.workspace.applyEdit(edit);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
context.subscriptions.push(disposable);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function cleanText(
|
|
38
|
+
text: string,
|
|
39
|
+
removeDebugger: boolean,
|
|
40
|
+
removeConsole: boolean,
|
|
41
|
+
consoleMethods: string[]
|
|
42
|
+
): string {
|
|
43
|
+
const lines = text.split('\n');
|
|
44
|
+
const filtered = lines.filter(line => {
|
|
45
|
+
if (removeDebugger && /^\s*debugger\s*;?\s*$/.test(line)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (removeConsole && consoleMethods.length > 0) {
|
|
49
|
+
const methodPattern = consoleMethods.map(m => escapeRegex(m)).join('|');
|
|
50
|
+
const consoleRegex = new RegExp(
|
|
51
|
+
`^\\s*console\\.(${methodPattern})\\s*\\(.*\\)\\s*;?\\s*$`
|
|
52
|
+
);
|
|
53
|
+
if (consoleRegex.test(line)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
});
|
|
59
|
+
return filtered.join('\n');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function escapeRegex(s: string): string {
|
|
63
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function deactivate(): void {}
|