or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cspell-integration.mdhelper-functions.mdindex.mdplugin-configuration.mdrule-system.md
tile.json

rule-system.mddocs/

Rule System

The spell checking rule implementation that performs the actual linting and provides suggestions.

Capabilities

Plugin Structure

Main ESLint plugin implementing the standard ESLint plugin interface.

/**
 * Main ESLint plugin for CSpell spell checking
 */
const plugin: ESLint.Plugin;

/**
 * Plugin metadata
 */
const meta: { name: "@cspell" };

/**
 * Available rules provided by the plugin
 */
const rules: { spellchecker: Rule.RuleModule };

Predefined Configurations

Ready-to-use configuration presets for different use cases.

/**
 * Predefined configurations for the CSpell ESLint plugin
 */
const configs: {
  /**
   * Standard recommended configuration
   * Uses '@cspell/spellchecker' rule with 'warn' level
   */
  recommended: ESLint.ConfigData;

  /**
   * Legacy format recommended configuration
   * Compatible with .eslintrc format
   */
  'recommended-legacy': ESLint.ConfigData;

  /**
   * Debug mode configuration
   * Enables debug logging and additional diagnostics
   */
  debug: ESLint.ConfigData;

  /**
   * Legacy format debug configuration
   * Compatible with .eslintrc format
   */
  'debug-legacy': ESLint.ConfigData;
};

Spellchecker Rule

The core rule that performs spell checking on JavaScript/TypeScript code.

/**
 * The main spell checking rule
 * Analyzes AST nodes for spelling errors in various contexts
 */
const spellchecker: Rule.RuleModule;

Rule Metadata:

  • Rule name: @cspell/spellchecker
  • Category: "Possible Errors"
  • Recommended: false (enabled via configurations)
  • Has suggestions: true
  • Fixable: "code"
  • Schema: Validates Options interface

Usage Examples:

// Using predefined recommended configuration
import cspellESLintPluginRecommended from '@cspell/eslint-plugin/recommended';

export default [
  cspellESLintPluginRecommended
];

// Using configs object
import cspellConfigs from '@cspell/eslint-plugin/configs';

export default [
  cspellConfigs.recommended,
  // or
  cspellConfigs.debug
];

// Manual plugin configuration
import cspellPlugin from '@cspell/eslint-plugin';

export default [
  {
    plugins: { '@cspell': cspellPlugin },
    rules: {
      '@cspell/spellchecker': ['warn', {
        checkComments: true,
        checkStrings: true,
        autoFix: false
      }]
    }
  }
];

Rule Messages

Standard error and suggestion messages provided by the rule.

/**
 * Message templates used by the spellchecker rule
 */
const messages: {
  /**
   * Message for unknown words
   * Placeholders: {{word}}
   */
  wordUnknown: 'Unknown word: "{{word}}"';

  /**
   * Message for forbidden words
   * Placeholders: {{word}}
   */
  wordForbidden: 'Forbidden word: "{{word}}"';

  /**
   * Message for suggestions
   * Placeholders: {{word}}, {{preferred}}
   */
  suggestWord: '{{word}}{{preferred}}';
};

Rule Context Information

Information about spelling issues found during linting.

/**
 * Represents a spelling issue found in the code
 */
interface Issue {
  /** Start position in the source text */
  start: number;
  /** End position in the source text */
  end: number;
  /** The word that triggered the issue */
  word: string;
  /** Severity level of the issue */
  severity: 'Forbidden' | 'Unknown' | 'Hint';
  /** Suggested corrections for the word */
  suggestions: Suggestions;
  /** Type of AST node where the issue was found */
  nodeType: NodeType;
  /** Reference to the AST node (may be undefined) */
  node: ASTNode | undefined;
}

/**
 * Results from spell checking operation
 */
interface SpellCheckResults {
  /** Array of spelling issues found */
  issues: Issue[];
  /** Any errors encountered during spell checking */
  errors?: Error[];
}

/**
 * Suggestion for correcting a spelling error
 */
interface ExtendedSuggestion {
  /** The suggested word */
  word: string;
  /** Whether this suggestion is preferred above others */
  isPreferred?: boolean;
  /** The suggested word adjusted to match the original case */
  wordAdjustedToMatchCase?: string;
}

/**
 * Array of suggestions or undefined if no suggestions available
 */
type Suggestions = ExtendedSuggestion[] | undefined;

Spell Check Function

Core spell checking functionality that analyzes AST nodes for spelling errors.

/**
 * Core spell checking functionality that analyzes AST nodes for spelling errors
 * @param filename - Name of the file being checked
 * @param text - Full source text of the file
 * @param root - Root AST node to analyze
 * @param options - Worker options for spell checking configuration
 * @returns Results containing issues and any errors encountered
 */
function spellCheckAST(
  filename: string, 
  text: string, 
  root: Node, 
  options: WorkerOptions
): SpellCheckResults;

Configuration Examples:

// Error level with auto-fix enabled
export default [
  {
    plugins: { '@cspell': cspellPlugin },
    rules: {
      '@cspell/spellchecker': ['error', {
        autoFix: true,
        numSuggestions: 5,
        generateSuggestions: true
      }]
    }
  }
];

// Debug configuration for troubleshooting
export default [
  {
    plugins: { '@cspell': cspellPlugin },
    rules: {
      '@cspell/spellchecker': ['warn', {
        debugMode: true,
        checkIdentifiers: true,
        checkComments: true,
        checkStrings: true
      }]
    }
  }
];

// Selective checking configuration
export default [
  {
    plugins: { '@cspell': cspellPlugin },
    rules: {
      '@cspell/spellchecker': ['warn', {
        checkComments: true,
        checkStrings: false,
        checkIdentifiers: false,
        ignoreImports: true,
        ignoreImportProperties: true
      }]
    }
  }
];