Skip to content

Commit d353133

Browse files
KyeongJooniclaude
andcommitted
docs: restructure console.log debugging section
Reorganize the debugging documentation based on feedback: - Move ESLint rules to the top as the recommended approach - Add IDE search as a secondary option - Keep stack trace method as temporary debugging technique - Add warning notes about removing overrides after use 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent b8b969e commit d353133

File tree

1 file changed

+33
-31
lines changed
  • packages/docs/src/routes/docs/(qwikcity)/guides/debugging

1 file changed

+33
-31
lines changed

packages/docs/src/routes/docs/(qwikcity)/guides/debugging/index.mdx

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,38 @@ Under the hood [launch-editor library](https://github.com/yyx990803/launch-edito
2525

2626
When working on larger codebases, you might occasionally leave `console.log` statements in your code unintentionally. These can clutter your terminal output, and it's often difficult to identify which file and line number produced each log message.
2727

28-
### Using stack traces in client-side components
28+
### Using ESLint rules
29+
30+
The recommended approach is to configure ESLint to prevent `console.log` statements from being committed:
31+
32+
```js
33+
// eslint.config.js
34+
export default [
35+
{
36+
rules: {
37+
'no-console': ['error', { allow: ['warn', 'error'] }],
38+
},
39+
},
40+
];
41+
```
42+
43+
This will catch `console.log` statements during development, preventing them from being committed.
44+
45+
### Using IDE search
46+
47+
Most IDEs provide powerful search functionality to find all occurrences of `console.log` across your codebase:
48+
- **VS Code**: Press `Ctrl+Shift+F` (or `Cmd+Shift+F` on Mac) and search for `console\.log`
49+
- **Enable regex mode** to match only exact `console.log` calls and not `console.error` or `console.warn`
50+
51+
This approach is simple but requires manual review of each occurrence to determine if it's intentional or leftover debug code.
52+
53+
### Using stack traces (temporary debugging)
54+
55+
If you need to identify existing leftover console.logs in a codebase that's already cluttered, you can temporarily override `console.log` to include stack traces.
56+
57+
#### In client-side components
2958

30-
You can override `console.log` to include stack trace information in your component code. For example, in your root component or a layout component:
59+
You can override `console.log` in your component code:
3160

3261
```tsx
3362
// root.tsx or layout.tsx
@@ -49,9 +78,7 @@ export default component$(() => {
4978
});
5079
```
5180

52-
Now when you call `console.log("something")`, you'll see the stack trace pointing to the exact location where the log was called, making it much easier to locate and remove leftover debug statements.
53-
54-
### Using stack traces in server-side entry files
81+
#### In server-side entry files
5582

5683
For entry files like `entry.express.tsx`, `entry.dev.tsx`, or `entry.preview.tsx`, you can override `console.log` at the module level:
5784

@@ -70,29 +97,4 @@ console.log = (...args: any[]) => {
7097
// Rest of your entry file code...
7198
```
7299

73-
> **Note:** The filter regex should be adjusted based on your specific build setup. Common patterns to filter out include `.vite`, `.main.jsx`, `node_modules`, and `internal` paths.
74-
75-
### Using ESLint rules
76-
77-
You can configure ESLint to warn or error on `console.log` statements in production code:
78-
79-
```js
80-
// eslint.config.js
81-
export default [
82-
{
83-
rules: {
84-
'no-console': ['error', { allow: ['warn', 'error'] }],
85-
},
86-
},
87-
];
88-
```
89-
90-
This will catch `console.log` statements during development, preventing them from being committed.
91-
92-
### Using IDE search
93-
94-
Most IDEs provide powerful search functionality to find all occurrences of `console.log` across your codebase. For example:
95-
- **VS Code**: Press `Ctrl+Shift+F` (or `Cmd+Shift+F` on Mac) and search for `console\.log`
96-
- **Enable regex mode** to match only exact `console.log` calls and not `console.error` or `console.warn`
97-
98-
This approach is simple but requires manual review of each occurrence to determine if it's intentional or leftover debug code.
100+
> **Note:** Remember to remove these overrides after debugging. The filter regex should be adjusted based on your specific build setup.

0 commit comments

Comments
 (0)