Skip to content

Commit 4ff1aed

Browse files
github-actions[bot]Copilotrijeshagithub-actions
authored
Creating Pre-Release: 2.0.1 (#163)
* Implement unused code detection feature for static analysis (command-line only) (#121) * Initial plan * Implement comprehensive unused code detection feature Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> * Remove VS Code extension command for unused code detection - Removed command definition from package.json - Removed command registration from extension.ts - Removed unused spawn import - Keeping npm script and detection functionality available --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> * Update issue templates * Added files .vscodeignore and added bundling to release.yml (#159) * Added files .vscodeignore and added bundling to release.yml * Further chanages to .vscodeignore * 2.0.1 (#162) - Testing new packaging Co-authored-by: github-actions <github-actions@github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: rijesha <7819200+rijesha@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent eec0718 commit 4ff1aed

File tree

8 files changed

+500
-6
lines changed

8 files changed

+500
-6
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Maintenance
3+
about: Code maintenance related issues
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+

β€Ž.github/workflows/release.ymlβ€Ž

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ jobs:
4040

4141
# Optional build (ensure dist/extension.js exists if using bundler)
4242
- name: Build Extension
43-
run: npm run esbuild --if-present
43+
run: npm run esbuild
44+
45+
- name: Package extension
46+
run: npx vsce package
4447

4548
# Capture version from package.json for later release creation
4649
- name: Extract Version

β€Ž.vscodeignoreβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
.vscode/**
22
.vscode-test/**
3-
3+
.git/
44
.gitignore
5+
.github/
56
.yarnrc
67
vsc-extension-quickstart.md
78
**/tsconfig.json
89
**/.eslintrc.json
910
**/*.map
1011
**/*.ts
1112
**/.vscode-test.*
13+
14+
docs/**
15+
CHANGELOG.md
16+
LICENSE.md
17+
README.md

β€ŽREADME.mdβ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ You can read a little bit more about the motivation behind the project [here](ht
2525
- Provides the user with a terminal to manually run west commands
2626
- Saves/loads project structure to workspace in a human readable and editable file
2727
- Works with all platforms zephyr supports
28+
- **Code Quality Tools**: Includes unused code detection to help maintain clean codebases
29+
30+
## Code Quality
31+
32+
This extension includes tools to help maintain code quality:
33+
34+
- **Unused Code Detection**: Static analysis tool to identify potentially unused files and exports
35+
- Available via command palette: "Zephyr IDE: Detect Unused Code"
36+
- Also available via npm script: `npm run detect-unused`
37+
- See [detailed documentation](docs/unused-code-detection.md) for more information
2838

2939

3040
## Getting Started
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Unused Code Detection
2+
3+
This project includes a static analysis tool to detect potentially unused code and dead files. This helps maintain a clean codebase by identifying exports and files that may no longer be needed.
4+
5+
## Features
6+
7+
The unused code detector analyzes:
8+
- **Unused Files**: TypeScript files that are never imported by other files
9+
- **Unused Exports**: Functions, classes, variables, and types that are exported but never imported
10+
- **VS Code Integration**: Smart detection of VS Code extension patterns like `activate`/`deactivate` functions
11+
12+
## Usage
13+
14+
### Command Line
15+
16+
Run the detection script from the command line:
17+
18+
```bash
19+
npm run detect-unused
20+
```
21+
22+
### VS Code Command
23+
24+
1. Open the Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`)
25+
2. Search for "Zephyr IDE: Detect Unused Code"
26+
3. Run the command
27+
4. View results in the Output panel (select "Zephyr IDE" from the dropdown)
28+
29+
## Understanding the Results
30+
31+
### Report Sections
32+
33+
**πŸ—‚οΈ Potentially Unused Files**
34+
- Lists TypeScript files that are never imported
35+
- Excludes test files and the main extension entry point
36+
- These files might be safe to remove, but review carefully
37+
38+
**πŸ“€ Potentially Unused Exports**
39+
- Lists exported functions, classes, variables that are never imported
40+
- Shows the file, export name, type, and line number
41+
- Includes smart filtering for VS Code extension patterns
42+
43+
**πŸ“ˆ Summary**
44+
- Total files analyzed
45+
- Count of potentially unused files and exports
46+
47+
### Important Notes
48+
49+
⚠️ **This analysis is static and may show false positives**
50+
51+
The tool cannot detect:
52+
- Dynamic imports using `import()` statements
53+
- Reflection-based usage
54+
- External references from other packages
55+
- Command handlers registered via strings in package.json
56+
- Functions called via VS Code's command system
57+
58+
### Best Practices
59+
60+
1. **Review before removing**: Always manually verify that flagged code is truly unused
61+
2. **Check git history**: Look at recent usage patterns before removing old code
62+
3. **Consider API boundaries**: Some exports might be intended for external use
63+
4. **Test thoroughly**: After removing code, run all tests and verify functionality
64+
65+
## Technical Details
66+
67+
The detection script:
68+
1. Scans all `.ts` files in the `src` directory
69+
2. Parses import/export statements using regex patterns
70+
3. Builds a dependency graph
71+
4. Identifies unused files and exports
72+
5. Applies VS Code extension-specific filtering rules
73+
74+
### Limitations
75+
76+
- Does not use TypeScript compiler API for performance reasons
77+
- Regex-based parsing may miss complex import/export patterns
78+
- Cannot detect runtime-only dependencies
79+
- May not catch all dynamic usage patterns
80+
81+
## Example Output
82+
83+
```
84+
πŸ“Š UNUSED CODE DETECTION REPORT
85+
==================================================
86+
87+
πŸ—‚οΈ POTENTIALLY UNUSED FILES:
88+
βœ… No unused files detected!
89+
90+
πŸ“€ POTENTIALLY UNUSED EXPORTS:
91+
92+
πŸ“ utilities/utils.ts:
93+
πŸ”Έ unusedHelper (declaration, line 42)
94+
πŸ”Έ oldFunction (declaration, line 156)
95+
96+
πŸ“ˆ SUMMARY:
97+
πŸ“ Total files analyzed: 36
98+
πŸ—‚οΈ Potentially unused files: 0
99+
πŸ“€ Potentially unused exports: 2
100+
```
101+
102+
This report suggests reviewing `unusedHelper` and `oldFunction` in the utils file to determine if they can be safely removed.

β€Žpackage-lock.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "zephyr-ide",
33
"displayName": "Zephyr IDE",
44
"description": "A VS Code extension that streamlines setup, build, flashing, and debugging of Zephyr Projects",
5-
"version": "2.0.0",
5+
"version": "2.0.1",
66
"license": "Apache-2.0",
77
"publisher": "mylonics",
88
"icon": "media/logo.png",
@@ -615,7 +615,8 @@
615615
"watch": "tsc -watch -p ./",
616616
"pretest": "npm run compile && npm run esbuild && npm run lint",
617617
"lint": "eslint src --ext ts",
618-
"test": "vscode-test"
618+
"test": "vscode-test",
619+
"detect-unused": "node scripts/detect-unused-code.js"
619620
},
620621
"devDependencies": {
621622
"@types/fs-extra": "^11.0.4",

0 commit comments

Comments
Β (0)