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

tessl/npm-coffeelint

A style checker that helps keep CoffeeScript code clean and consistent

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coffeelint@2.1.x

To install, run

npx @tessl/cli install tessl/npm-coffeelint@2.1.0

index.mddocs/

CoffeeLint

CoffeeLint is a style checker that helps keep CoffeeScript code clean and consistent. It analyzes CoffeeScript source code and reports style violations based on configurable rules, supporting both programmatic API usage and command-line interface.

Package Information

  • Package Name: coffeelint
  • Package Type: npm
  • Language: CoffeeScript/JavaScript
  • Installation: npm install coffeelint

Core Imports

const coffeelint = require('coffeelint');

For browser usage (via browserify):

// CoffeeLint is available as window.coffeelint
const coffeelint = window.coffeelint;

Basic Usage

const coffeelint = require('coffeelint');

// Lint CoffeeScript source code
const source = `
class Person
  constructor: (@name) ->
  greet: -> console.log "Hello, #{@name}!"
`;

// Basic linting with default configuration
const errors = coffeelint.lint(source);

// Linting with custom configuration
const config = {
  "max_line_length": {
    "level": "error",
    "value": 80
  },
  "no_tabs": {
    "level": "error"
  }
};

const configErrors = coffeelint.lint(source, config);

// Check for errors
console.log(`Found ${errors.length} style issues`);
errors.forEach(error => {
  console.log(`Line ${error.lineNumber}: ${error.message}`);
});

Architecture

CoffeeLint is built around several key components:

  • Core Linting Engine: Main lint() function that orchestrates three types of linters
  • Rule System: Extensible rule architecture with built-in rules and external rule loading
  • Configuration System: Hierarchical configuration discovery and merging
  • Reporting System: Multiple output formats for different use cases
  • Command Line Interface: Full-featured CLI with file discovery and batch processing
  • Caching System: Optional result caching for improved performance

Capabilities

Core Linting API

Main programmatic interface for linting CoffeeScript code with configurable rules and error reporting.

/**
 * Lint CoffeeScript source code and return array of errors
 * @param source - CoffeeScript source code to lint
 * @param userConfig - Optional configuration object with rule settings
 * @param literate - Optional flag to treat source as literate CoffeeScript
 * @returns Array of error objects with rule, lineNumber, level, message, context
 */
function lint(source, userConfig, literate);

/**
 * Current version of CoffeeLint
 */
const VERSION;

/**
 * Get all available rules with their default configurations
 * @returns Object mapping rule names to rule configurations
 */
function getRules();

Core Linting API

Rule Management

System for registering custom rules and managing the built-in rule set.

/**
 * Register a new linting rule
 * @param RuleConstructor - Constructor function for the rule
 * @param ruleName - Optional override name for the rule
 */
function registerRule(RuleConstructor, ruleName);

/**
 * Object containing all rule definitions
 */
const RULES;

Rule Management

Configuration System

Tools for loading, merging, and managing linting configurations from various sources.

/**
 * Remove default values from config to produce minimal configuration
 * @param userConfig - User configuration object
 * @returns Minimal configuration object with only non-default values
 */
function trimConfig(userConfig);

/**
 * Convert literate CoffeeScript to regular CoffeeScript format
 * @param source - Literate CoffeeScript source
 * @returns Regular CoffeeScript source string
 */
function invertLiterate(source);

Configuration System

Error Reporting

Comprehensive error reporting system for collecting, formatting, and outputting linting results.

/**
 * Create a new ErrorReport instance for collecting linting results
 * @returns ErrorReport instance
 */
function getErrorReport();

/**
 * Set cache object for linting results
 * @param obj - Cache implementation object
 */
function setCache(obj);

Error Reporting

Command Line Interface

Full-featured CLI for linting files and directories with various output formats and configuration options.

# Basic usage
coffeelint file.coffee

# Lint multiple files and directories
coffeelint src/ test/ lib/main.coffee

# Use custom configuration file
coffeelint -f coffeelint.json src/

# Output in different formats
coffeelint --reporter csv src/
coffeelint --reporter jslint src/
coffeelint --reporter checkstyle src/

# Lint from stdin
cat file.coffee | coffeelint --stdin

# Generate configuration files
coffeelint --makeconfig > coffeelint.json
coffeelint --trimconfig

Command Line Interface

Types

/**
 * Error object returned by lint function
 */
interface LintError {
  /** Name of the violated rule */
  rule: string;
  /** Line number where violation occurred */
  lineNumber: number;
  /** Error level: 'error', 'warn', or 'ignore' */
  level: 'error' | 'warn' | 'ignore';
  /** Human-readable error message */
  message: string;
  /** Optional additional context about the violation */
  context?: string;
  /** Optional end line number for multi-line violations */
  lineNumberEnd?: number;
}

/**
 * Configuration object for linting rules
 */
interface LintConfig {
  [ruleName: string]: {
    /** Rule severity level */
    level: 'error' | 'warn' | 'ignore';
    /** Optional custom error message */
    message?: string;
    /** Rule-specific configuration options */
    [option: string]: any;
  };
  /** Global coffeelint configuration */
  coffeelint?: {
    /** Source code transformers to apply before linting */
    transforms?: string[];
    /** Custom CoffeeScript compiler module */
    coffeescript?: string;
  };
}

/**
 * Rule definition object
 */
interface RuleDefinition {
  /** Unique rule name */
  name: string;
  /** Default severity level */
  level: 'error' | 'warn' | 'ignore';
  /** Default error message */
  message: string;
  /** Human-readable rule description */
  description: string;
  /** Rule-specific default options */
  [option: string]: any;
}