Skip to content

forcedotcom/sf-skills / plugins/builder/experience-lwc/skills/experience-lwc-generate

experience-lwc-generate

Unverified

Lightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use platform-apex-generate), Aura components, or Visualforce.

FileKindSize
README.mdmarkdown4.1 KB
SKILL.mdskill md9.6 KB
assets/apex-controller/LwcController.clsother12.0 KB
assets/basic-component/basicComponent.cssother1.5 KB
assets/basic-component/basicComponent.htmlother4.5 KB
assets/basic-component/basicComponent.jsscript7.3 KB
assets/basic-component/basicComponent.js-meta.xmlconfig4.5 KB
assets/datatable-component/datatableComponent.htmlother4.1 KB
assets/datatable-component/datatableComponent.jsscript13.1 KB
assets/flow-screen-component/flowScreenComponent.cssother1.7 KB
assets/flow-screen-component/flowScreenComponent.htmlother7.1 KB
assets/flow-screen-component/flowScreenComponent.jsscript13.9 KB
assets/flow-screen-component/flowScreenComponent.js-meta.xmlconfig3.9 KB
assets/form-component/formComponent.htmlother6.4 KB
assets/form-component/formComponent.jsscript11.3 KB
assets/graphql-component/graphqlComponent.htmlother4.8 KB
assets/graphql-component/graphqlComponent.jsscript10.7 KB
assets/jest-test/componentName.test.js.exampleother15.6 KB
assets/message-channel/RecordSelected.messageChannel-meta.xmlconfig2.4 KB
assets/message-channel/lmsPublisher.jsscript3.8 KB
assets/message-channel/lmsSubscriber.jsscript7.0 KB
assets/modal-component/modalComponent.htmlother3.2 KB
assets/modal-component/modalComponent.jsscript5.5 KB
assets/record-picker/recordPicker.htmlother2.0 KB
assets/record-picker/recordPicker.jsscript5.4 KB
assets/state-store/store.jsscript9.1 KB
assets/typescript-component/typescriptComponent.cssother1.3 KB
assets/typescript-component/typescriptComponent.htmlother4.3 KB
assets/typescript-component/typescriptComponent.js-meta.xmlconfig2.4 KB
assets/typescript-component/typescriptComponent.test.ts.exampleother13.6 KB
assets/typescript-component/typescriptComponent.tsscript11.7 KB
assets/workspace-api/workspaceComponent.htmlother3.4 KB
assets/workspace-api/workspaceComponent.jsscript8.0 KB
references/accessibility-guide.mdmarkdown22.3 KB
references/advanced-features.mdmarkdown2.8 KB
references/async-notification-patterns.mdmarkdown19.7 KB
references/cli-commands.mdmarkdown12.6 KB
references/component-patterns.mdmarkdown44.5 KB
references/flow-integration-guide.mdmarkdown19.0 KB
references/jest-testing.mdmarkdown25.3 KB
references/lms-guide.mdmarkdown21.9 KB
references/lwc-best-practices.mdmarkdown36.3 KB
references/performance-guide.mdmarkdown20.3 KB
references/scoring-and-testing.mdmarkdown3.8 KB
references/slds-blueprints.jsonconfig781.3 KB
references/slds-design-guide.mdmarkdown10.7 KB
references/state-management.mdmarkdown19.9 KB
references/template-anti-patterns.mdmarkdown20.1 KB
references/triangle-pattern.mdmarkdown12.5 KB
scripts/local-dev-preview.shscript1.1 KB
scripts/lwc-lsp-validate.pyscript8.6 KB
scripts/post-tool-validate.pyscript14.7 KB
scripts/slds_data/deprecated_patterns.jsonconfig3.4 KB
scripts/slds_data/styling_hooks.jsonconfig2.9 KB
scripts/slds_data/valid_slds_classes.jsonconfig7.4 KB
scripts/slds_linter_wrapper.pyscript8.9 KB
scripts/slds_rules/__init__.pyscript593 B
scripts/template_validator.pyscript13.5 KB
scripts/validate_slds.pyscript26.5 KB

scripts/slds_linter_wrapper.py

View on GitHub
#!/usr/bin/env python3
"""
Wrapper for official @salesforce-ux/slds-linter npm package.

Provides integration with SLDS Linter for:
- HTML template validation
- CSS styling hooks validation
- Automated linting with structured output

The SLDS Linter is optional - if not installed, validation gracefully
degrades to custom Python-based validators.

Installation:
    npm install -g @salesforce-ux/slds-linter
"""

import subprocess
import json
import os
from typing import Dict, List, Any, Optional


class SLDSLinterWrapper:
    """Wrapper for npm-based SLDS Linter."""

    def __init__(self, project_root: Optional[str] = None):
        """
        Initialize the SLDS Linter wrapper.

        Args:
            project_root: Root directory for linting context (optional)
        """
        self.project_root = project_root or os.getcwd()
        self._available: Optional[bool] = None

    def is_available(self) -> bool:
        """
        Check if slds-linter is installed and available.

        Returns:
            True if linter is available, False otherwise
        """
        if self._available is not None:
            return self._available

        try:
            result = subprocess.run(
                ['npx', '@salesforce-ux/slds-linter', '--version'],
                capture_output=True,
                text=True,
                timeout=10
            )
            self._available = result.returncode == 0
        except (subprocess.TimeoutExpired, FileNotFoundError, Exception):
            self._available = False

        return self._available

    def lint_file(self, file_path: str) -> Dict[str, Any]:
        """
        Lint a single file using SLDS Linter.

        Args:
            file_path: Path to HTML or CSS file to lint

        Returns:
            dict with success status, violations list, and any errors
        """
        if not self.is_available():
            return {
                'success': False,
                'error': 'slds-linter not installed. Install with: npm i -g @salesforce-ux/slds-linter',
                'violations': []
            }

        try:
            # Run SLDS Linter with JSON output
            result = subprocess.run(
                [
                    'npx', '@salesforce-ux/slds-linter', 'lint',
                    file_path,
                    '--format', 'json'
                ],
                capture_output=True,
                text=True,
                timeout=30,
                cwd=self.project_root
            )

            violations = self._parse_output(result.stdout, result.stderr)

            return {
                'success': True,
                'violations': violations,
                'exit_code': result.returncode
            }

        except subprocess.TimeoutExpired:
            return {
                'success': False,
                'error': 'slds-linter timed out after 30 seconds',
                'violations': []
            }
        except FileNotFoundError:
            return {
                'success': False,
                'error': 'npx not found - ensure Node.js is installed',
                'violations': []
            }
        except Exception as e:
            return {
                'success': False,
                'error': str(e),
                'violations': []
            }

    def lint_directory(self, dir_path: str, extensions: List[str] = None) -> Dict[str, Any]:
        """
        Lint all matching files in a directory.

        Args:
            dir_path: Directory path to lint
            extensions: File extensions to lint (default: ['.html', '.css'])

        Returns:
            dict with success status, file_results, and total violations
        """
        if extensions is None:
            extensions = ['.html', '.css']

        if not self.is_available():
            return {
                'success': False,
                'error': 'slds-linter not installed',
                'file_results': {},
                'total_violations': 0
            }

        file_results = {}
        total_violations = 0

        for root, dirs, files in os.walk(dir_path):
            for file in files:
                if any(file.endswith(ext) for ext in extensions):
                    file_path = os.path.join(root, file)
                    result = self.lint_file(file_path)
                    file_results[file_path] = result
                    total_violations += len(result.get('violations', []))

        return {
            'success': True,
            'file_results': file_results,
            'total_violations': total_violations
        }

    def _parse_output(self, stdout: str, stderr: str) -> List[Dict]:
        """
        Parse SLDS Linter JSON output into structured violations.

        Args:
            stdout: Standard output from linter
            stderr: Standard error from linter

        Returns:
            List of violation dictionaries
        """
        violations = []

        # Try to parse JSON output
        try:
            if stdout.strip():
                data = json.loads(stdout)

                # Handle ESLint-style JSON output
                if isinstance(data, list):
                    for file_result in data:
                        for message in file_result.get('messages', []):
                            violations.append({
                                'rule': message.get('ruleId', 'unknown'),
                                'message': message.get('message', ''),
                                'line': message.get('line', 0),
                                'column': message.get('column', 0),
                                'severity': self._map_severity(message.get('severity', 1)),
                                'source': 'slds-linter',
                                'file': file_result.get('filePath', '')
                            })

                # Handle single object output
                elif isinstance(data, dict):
                    for message in data.get('messages', []):
                        violations.append({
                            'rule': message.get('ruleId', 'unknown'),
                            'message': message.get('message', ''),
                            'line': message.get('line', 0),
                            'column': message.get('column', 0),
                            'severity': self._map_severity(message.get('severity', 1)),
                            'source': 'slds-linter'
                        })

        except json.JSONDecodeError:
            # If not valid JSON, try to extract violations from text output
            violations.extend(self._parse_text_output(stdout))
            violations.extend(self._parse_text_output(stderr))

        return violations

    def _parse_text_output(self, output: str) -> List[Dict]:
        """
        Parse plain text linter output for violations.

        Args:
            output: Text output from linter

        Returns:
            List of violation dictionaries
        """
        violations = []

        if not output:
            return violations

        # Common patterns for linter output
        # Example: "filename.html:10:5: error - message"
        import re
        pattern = r'(\S+):(\d+):(\d+):\s*(error|warning|info)\s*[-:]\s*(.+)'

        for line in output.splitlines():
            match = re.match(pattern, line, re.IGNORECASE)
            if match:
                violations.append({
                    'file': match.group(1),
                    'line': int(match.group(2)),
                    'column': int(match.group(3)),
                    'severity': match.group(4).upper(),
                    'message': match.group(5).strip(),
                    'rule': 'slds',
                    'source': 'slds-linter'
                })

        return violations

    def _map_severity(self, level: int) -> str:
        """
        Map ESLint severity levels to our labels.

        Args:
            level: ESLint severity (1=warning, 2=error)

        Returns:
            Severity label string
        """
        return {
            0: 'INFO',
            1: 'WARNING',
            2: 'HIGH'
        }.get(level, 'INFO')


def is_slds_linter_available() -> bool:
    """
    Convenience function to check if SLDS Linter is available.

    Returns:
        True if available, False otherwise
    """
    wrapper = SLDSLinterWrapper()
    return wrapper.is_available()


def lint_lwc_file(file_path: str) -> Dict[str, Any]:
    """
    Convenience function to lint a single LWC file.

    Args:
        file_path: Path to file to lint

    Returns:
        Linting results dictionary
    """
    wrapper = SLDSLinterWrapper()
    return wrapper.lint_file(file_path)


if __name__ == "__main__":
    import sys

    if len(sys.argv) < 2:
        print("Usage: python slds_linter_wrapper.py <file.html|file.css>")
        print("\nChecking SLDS Linter availability...")
        print(f"Available: {is_slds_linter_available()}")
        sys.exit(0)

    result = lint_lwc_file(sys.argv[1])
    print(json.dumps(result, indent=2))
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall