# Angular Unused Styles Analyzer A Visual Studio Code extension that automatically detects and highlights unused CSS/SCSS styles in Angular components. Keep your stylesheets clean and optimized by identifying dead code in real-time. ## Features β¨ **Real-time Analysis** - Automatically analyzes styles as you type π **Multi-file Detection** - Scans HTML templates, TypeScript components, and stylesheets π― **Angular-aware** - Understands Angular-specific patterns like `[class.myClass]`, `[ngClass]`, and `@HostBinding` β‘ **Performance Optimized** - Lightweight analysis that won't slow down your development π¨ **SCSS Support** - Works with both CSS and SCSS files π« **Smart Ignoring** - Configurable ignored selectors (`:host`, `::ng-deep`, etc.) ## How It Works The extension analyzes your Angular component files in three steps: 1. **Extracts CSS selectors** from your `.component.scss` or `.component.css` files 2. **Scans for usage** in your `.component.html` templates and `.component.ts` files 3. **Highlights unused styles** with warning diagnostics directly in your editor ### Supported Usage Patterns **HTML Template Detection:** - `class="my-class another-class"` - `id="my-element"` - `[class.dynamic-class]="condition"` - `[ngClass]="classObject"` **TypeScript Component Detection:** - `renderer.addClass(element, 'my-class')` - `element.classList.add('my-class')` - `@HostBinding('class.my-class')` - String literals that look like CSS classes ## Installation ### From VS Code Marketplace 1. Open VS Code 2. Go to Extensions (`Ctrl+Shift+X`) 3. Search for "Angular Unused Styles Analyzer" 4. Click Install ### From Command Line ```bash code --install-extension programmingPug.angular-unused-styles-analyzer ``` ## Usage ### Automatic Analysis The extension automatically analyzes your Angular component styles when you: - Open a `.component.scss` or `.component.css` file - Make changes to component files - Save files (if enabled in settings) ### Manual Analysis - **Single Component**: Right-click on a style file β "Angular: Analyze Unused Styles" - **Entire Workspace**: `Ctrl+Shift+P` β "Angular: Analyze Entire Workspace" ### Visual Indicators Unused styles are marked with: - πΈ Yellow warning squiggles under the selector - π‘ Hover tooltip explaining why the style appears unused ## Configuration Configure the extension through VS Code settings (`Ctrl+,`): ```json { "angularUnusedStyles.enableRealTimeanalysis": true, "angularUnusedStyles.analyzeOnSave": true, "angularUnusedStyles.showInformationMessages": true, "angularUnusedStyles.ignoredSelectors": [ "::ng-deep", ":host", ":host-context", ":host(.*)" ] } ``` ### Settings Reference | Setting | Type | Default | Description | |---------|------|---------|-------------| | `enableRealTimeanalysis` | boolean | `true` | Enable real-time analysis as you type | | `analyzeOnSave` | boolean | `true` | Automatically analyze when files are saved | | `showInformationMessages` | boolean | `true` | Show completion messages after analysis | | `ignoredSelectors` | array | See above | CSS selectors to ignore (supports regex) | ## Examples ### Before (Unused Styles Highlighted) ```scss .used-class { color: blue; } .unused-class { // β οΈ Warning: appears to be unused color: red; } :host { // β Ignored (in default config) display: block; } ``` ### Component Usage Detection ```typescript // TypeScript - These classes will be detected as "used" @Component({...}) export class MyComponent { @HostBinding('class.dynamic-class') isDynamic = true; toggleClass() { this.renderer.addClass(this.elementRef.nativeElement, 'added-class'); } } ``` ```html