From 698724208f18b9d11bcefc622fb5cf7623cf67d7 Mon Sep 17 00:00:00 2001 From: NinjaPug <36635276+programmingPug@users.noreply.github.com> Date: Tue, 10 Jun 2025 16:51:45 -0400 Subject: [PATCH] Update LC and Readme --- LICENSE | 4 +- README.md | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 193 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index fa4f02e..d840308 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 NinjaPug +Copyright (c) 2025 Christopher Koch (programmingPug) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 220d524..0583a88 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,191 @@ -# angular-unused-styles-analyzer -Analyzes Angular components for unused CSS/SCSS styles and highlights them in real-time +# 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 + +