CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-lit-analyzer

CLI that type checks bindings in lit-html templates

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

cli-interface.mddocs/

CLI Interface

The CLI interface provides command-line analysis capabilities with multiple output formats, extensive configuration options, and flexible rule management for analyzing Lit templates in development workflows and CI/CD pipelines.

Capabilities

Main CLI Function

Entry point function for the command-line interface.

/**
 * Main CLI entry point function
 * Parses command-line arguments, configures analyzer, and executes analysis
 * @returns Promise that resolves when analysis is complete
 * @throws Exits process with code 0 on success, 1 on failure
 */
function cli(): Promise<void>;

CLI Configuration

Extended configuration interface for command-line specific options.

type FormatterFormat = "code" | "list" | "markdown";

/**
 * CLI-specific configuration interface
 * Contains options for command-line interface control
 */
interface LitAnalyzerCliConfig {
  /** Enable debug mode for detailed logging */
  debug?: boolean;
  /** Show help message and exit */
  help?: boolean;
  /** Disable colored output */
  noColor?: boolean;
  /** Maximum number of warnings before failing (-1 for unlimited) */
  maxWarnings?: number;
  /** Output file path (stdout if not specified) */
  outFile?: string;
  /** Exit immediately after finding the first problem */
  failFast?: boolean;
  /** Only report errors, suppress warnings */
  quiet?: boolean;
  /** Enable strict mode (changes default rule severities) */
  strict?: boolean;
  /** Output format for diagnostic results */
  format?: FormatterFormat;
  /** Rule configuration mapping rule IDs to severities */
  rules?: LitAnalyzerRules;
  /** Maximum depth for project import traversal */
  maxProjectImportDepth?: number;
  /** Maximum depth for node_modules import traversal */
  maxNodeModuleImportDepth?: number;
}

CLI Usage

Basic Commands

# Analyze all TypeScript/JavaScript files in src directory (default glob)
lit-analyzer

# Analyze specific directory
lit-analyzer src

# Analyze with glob patterns
lit-analyzer "src/**/*.{js,ts,jsx,tsx}"

# Analyze specific files
lit-analyzer my-element.js another-component.ts

Output Formats

Control how diagnostics are displayed:

# Default code format with syntax highlighting
lit-analyzer --format code src

# Compact list format
lit-analyzer --format list src

# Markdown format for documentation
lit-analyzer --format markdown src

# Output to file
lit-analyzer --format markdown --outFile results.md src

Rule Configuration

Configure individual rules from the command line:

# Disable specific rule
lit-analyzer --rules.no-unknown-tag-name off src

# Set rule to warning level
lit-analyzer --rules.no-missing-import warn src

# Set rule to error level
lit-analyzer --rules.no-incompatible-type-binding error src

# Multiple rule configurations
lit-analyzer \
  --rules.no-unknown-tag-name error \
  --rules.no-missing-import warn \
  --rules.no-unknown-attribute off \
  src

Strict Mode

Enable strict mode for more comprehensive validation:

# Enable strict mode (changes default rule severities)
lit-analyzer --strict src

Process Control

Control CLI behavior and output:

# Suppress warnings, show only errors
lit-analyzer --quiet src

# Exit after first problem found
lit-analyzer --failFast src

# Disable colored output
lit-analyzer --noColor src

# Fail if more than 10 warnings
lit-analyzer --maxWarnings 10 src

# Allow unlimited warnings
lit-analyzer --maxWarnings -1 src

Help and Information

# Show help message with all available options
lit-analyzer --help

Configuration File Integration

The CLI can also read configuration from tsconfig.json files using the TypeScript Language Service plugin configuration format:

{
  "compilerOptions": {
    "plugins": [
      {
        "name": "ts-lit-plugin",
        "strict": true,
        "rules": {
          "no-unknown-tag-name": "error",
          "no-missing-import": "warn",
          "no-incompatible-type-binding": "error"
        },
        "logging": "debug"
      }
    ]
  }
}

Output Examples

Code Format (Default)

src/my-element.ts:15:7 - error TS0: Unknown tag name "unknow-element" (no-unknown-tag-name)

15     return html`<unknow-element></unknow-element>`;
          ~~~~~~~~~~~~~

  Did you mean "unknown-element"?

src/my-element.ts:20:25 - warning TS0: Property "invalidProp" does not exist on element "input" (no-unknown-property)

20     return html`<input .invalidProp=${value}>`;
                           ~~~~~~~~~~~~

List Format

src/my-element.ts:15:7: error: Unknown tag name "unknow-element" (no-unknown-tag-name)
src/my-element.ts:20:25: warning: Property "invalidProp" does not exist on element "input" (no-unknown-property)

Markdown Format

## Analysis Results

### src/my-element.ts

**Error** at line 15, column 7 - `no-unknown-tag-name`
Unknown tag name "unknow-element"

**Warning** at line 20, column 25 - `no-unknown-property`  
Property "invalidProp" does not exist on element "input"

Exit Codes

The CLI uses standard exit codes:

  • 0: Success - No errors found (warnings may be present)
  • 1: Failure - Errors found or analysis failed

Environment Integration

CI/CD Pipeline Integration

# Fail build on any errors
lit-analyzer --failFast src && npm run build

# Allow warnings but fail on errors
lit-analyzer --quiet src || exit 1

# Generate markdown report for PR comments
lit-analyzer --format markdown --outFile analysis-report.md src

IDE Integration

The CLI can be integrated with editors and IDEs:

# VS Code task configuration
{
  "type": "shell",
  "command": "lit-analyzer",
  "args": ["src"],
  "group": "build",
  "presentation": {
    "echo": true,
    "reveal": "always",
    "focus": false,
    "panel": "shared"
  },
  "problemMatcher": {
    "owner": "lit-analyzer",
    "fileLocation": "relative",
    "pattern": {
      "regexp": "^(.*):(\\d+):(\\d+)\\s+-\\s+(error|warning)\\s+.*:\\s+(.*)\\s+\\((.*)\\)$",
      "file": 1,
      "line": 2,
      "column": 3,
      "severity": 4,
      "message": 5,
      "code": 6
    }
  }
}

Package.json Scripts

{
  "scripts": {
    "lint:lit": "lit-analyzer src",
    "lint:lit:strict": "lit-analyzer --strict src",
    "lint:lit:report": "lit-analyzer --format markdown --outFile lit-analysis.md src"
  }
}

Advanced Usage

Custom Rule Sets

Create reusable rule configurations:

# Development mode - warnings only
lit-analyzer \
  --rules.no-unknown-tag-name warn \
  --rules.no-missing-import warn \
  --rules.no-incompatible-type-binding warn \
  src

# Production mode - strict validation
lit-analyzer \
  --strict \
  --rules.no-unknown-tag-name error \
  --rules.no-missing-import error \
  --rules.no-incompatible-type-binding error \
  --failFast \
  src

Batch Analysis

# Analyze multiple projects
for project in packages/*/; do
  echo "Analyzing $project"
  lit-analyzer "$project/src"
done

# Parallel analysis with different configurations
lit-analyzer --format list src > analysis-list.txt &
lit-analyzer --format markdown src > analysis-report.md &
wait

Error Handling

The CLI provides detailed error information:

  • Rule violations: Specific rule ID and description
  • Type errors: TypeScript type mismatch information
  • Template syntax errors: HTML/CSS parsing errors
  • Configuration errors: Invalid rule names or values
  • File system errors: Missing files or permission issues

Performance Considerations

For large codebases:

# Use failFast to exit early
lit-analyzer --failFast src

# Limit warnings to avoid excessive output
lit-analyzer --maxWarnings 50 src

# Use quiet mode for faster processing
lit-analyzer --quiet src

docs

cli-interface.md

configuration.md

context-integration.md

core-analysis.md

index.md

tile.json