or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdconfiguration.mdcore-api.mderror-reporting.mdindex.mdrule-management.md
tile.json

error-reporting.mddocs/

Error Reporting

CoffeeLint's error reporting system provides comprehensive tools for collecting, organizing, and managing linting results across multiple files and linting sessions. The system supports batch processing, result caching, and detailed error analysis.

Capabilities

Error Report Creation

Create error report instances for collecting and organizing linting results across multiple files.

/**
 * Create a new ErrorReport instance for collecting linting results
 * @returns ErrorReport instance with methods for batch linting and result analysis
 */
function getErrorReport();

Usage Example:

const coffeelint = require('coffeelint');

// Create error report for batch processing
const errorReport = coffeelint.getErrorReport();

// Lint multiple files
errorReport.lint('src/app.coffee', appSource);
errorReport.lint('src/utils.coffee', utilsSource, customConfig);
errorReport.lint('test/spec.coffee', specSource, testConfig, true); // literate

// Get summary of all results
const summary = errorReport.getSummary();
console.log(`Processed ${summary.pathCount} files`);
console.log(`Found ${summary.errorCount} errors and ${summary.warningCount} warnings`);

// Get appropriate exit code for CI/CD
const exitCode = errorReport.getExitCode();
process.exit(exitCode);

Result Caching

Set up caching to improve linting performance across repeated operations.

/**
 * Set cache object for linting results to improve performance
 * @param obj - Cache implementation object with get/set methods
 */
function setCache(obj);

Usage Example:

const coffeelint = require('coffeelint');
const fs = require('fs');
const crypto = require('crypto');

// Simple file-based cache implementation
const cache = {
  _cacheDir: '.coffeelint-cache',
  
  get: function(key) {
    try {
      const cachePath = `${this._cacheDir}/${key}.json`;
      if (fs.existsSync(cachePath)) {
        const cached = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
        return cached;
      }
    } catch (e) {
      return null;
    }
    return null;
  },
  
  set: function(key, value) {
    try {
      if (!fs.existsSync(this._cacheDir)) {
        fs.mkdirSync(this._cacheDir);
      }
      const cachePath = `${this._cacheDir}/${key}.json`;
      fs.writeFileSync(cachePath, JSON.stringify(value));
    } catch (e) {
      // Cache write failed, continue without caching
    }
  }
};

// Enable caching
coffeelint.setCache(cache);

// Now linting will use cache when source and config haven't changed
const errors = coffeelint.lint(source, config);

ErrorReport Class API

The ErrorReport class provides comprehensive methods for batch linting and result analysis:

/**
 * ErrorReport class for managing multiple linting operations
 */
class ErrorReport {
  /**
   * Lint a file and add results to the report
   * @param filename - File path for error reporting
   * @param source - CoffeeScript source code
   * @param config - Optional configuration object
   * @param literate - Optional literate CoffeeScript flag
   */
  lint(filename, source, config, literate);

  /**
   * Get appropriate exit code based on error severity
   * @returns 0 if no errors found, 1 if errors found
   */
  getExitCode();

  /**
   * Get summary statistics for all linted files
   * @returns Object with errorCount, warningCount, pathCount
   */
  getSummary();

  /**
   * Get all errors for a specific file path
   * @param path - File path to get errors for
   * @returns Array of error objects for the specified path
   */
  getErrors(path);

  /**
   * Check if a specific path has warnings
   * @param path - File path to check
   * @returns True if path has warnings
   */
  pathHasWarning(path);

  /**
   * Check if a specific path has errors
   * @param path - File path to check
   * @returns True if path has errors
   */
  pathHasError(path);

  /**
   * Check if any files have errors
   * @returns True if any linted files have errors
   */
  hasError();
}

Detailed Usage Examples:

const coffeelint = require('coffeelint');
const fs = require('fs');
const path = require('path');

// Create error report
const errorReport = coffeelint.getErrorReport();

// Lint multiple files with different configurations
const files = ['src/app.coffee', 'src/utils.coffee', 'test/app_test.coffee'];

files.forEach(filepath => {
  const source = fs.readFileSync(filepath, 'utf8');
  
  // Use test-specific config for test files
  const config = filepath.includes('test/') ? {
    'no_debugger': { 'level': 'ignore' },
    'max_line_length': { 'value': 120 }
  } : null;
  
  errorReport.lint(filepath, source, config);
});

// Analyze results
const summary = errorReport.getSummary();
console.log('Linting Summary:');
console.log(`Files processed: ${summary.pathCount}`);
console.log(`Errors: ${summary.errorCount}`);
console.log(`Warnings: ${summary.warningCount}`);

// Check individual files
files.forEach(filepath => {
  if (errorReport.pathHasError(filepath)) {
    const errors = errorReport.getErrors(filepath);
    console.log(`\n${filepath} has ${errors.length} issues:`);
    
    errors.forEach(error => {
      console.log(`  Line ${error.lineNumber}: ${error.level.toUpperCase()} - ${error.message} (${error.rule})`);
    });
  }
});

// Get exit code for CI/CD systems
if (errorReport.hasError()) {
  console.log('Linting failed with errors');
  process.exit(errorReport.getExitCode());
} else {
  console.log('Linting passed');
}

Types

/**
 * Summary statistics for error report
 */
interface ErrorSummary {
  /** Total number of error-level violations */
  errorCount: number;
  /** Total number of warning-level violations */
  warningCount: number;
  /** Number of files processed */
  pathCount: number;
}

/**
 * Cache interface for performance optimization
 */
interface CacheInterface {
  /**
   * Retrieve cached value by key
   * @param key - Cache key
   * @returns Cached value or null if not found
   */
  get(key: string): any | null;
  
  /**
   * Store value in cache
   * @param key - Cache key
   * @param value - Value to cache
   */
  set(key: string, value: any): void;
}

Advanced Usage Patterns

Conditional Error Processing

const errorReport = coffeelint.getErrorReport();

// Lint files
errorReport.lint('app.coffee', appSource);
errorReport.lint('utils.coffee', utilsSource);

// Process only files with errors
const summary = errorReport.getSummary();
if (summary.errorCount > 0) {
  // Handle errors differently than warnings
  console.log('Critical errors found, stopping build');
  process.exit(1);
} else if (summary.warningCount > 0) {
  console.log('Warnings found, continuing with caution');
}

Custom Cache Implementation

// Redis-based cache example
const redis = require('redis');
const client = redis.createClient();

const redisCache = {
  get: async function(key) {
    try {
      const result = await client.get(`coffeelint:${key}`);
      return result ? JSON.parse(result) : null;
    } catch (e) {
      return null;
    }
  },
  
  set: async function(key, value) {
    try {
      await client.setex(`coffeelint:${key}`, 3600, JSON.stringify(value));
    } catch (e) {
      // Continue without caching
    }
  }
};

coffeelint.setCache(redisCache);