ESLint plugin that integrates CSpell spell checking capabilities directly into the ESLint workflow for catching spelling errors in code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Utility functions for defining configuration objects with proper type safety.
Helper function for defining plugin options with full type safety and IDE support.
/**
* Helper to define the options for the cspell-eslint-plugin.
* Provides type safety and IDE autocompletion for plugin options.
*
* @param options - The options to define (partial options object)
* @returns The same options object with proper typing
*/
function defineCSpellPluginOptions(options: Partial<Options>): Partial<Options>;Usage Examples:
import { defineCSpellPluginOptions } from '@cspell/eslint-plugin';
// Basic configuration with type safety
const pluginOptions = defineCSpellPluginOptions({
numSuggestions: 5,
autoFix: true,
checkComments: true,
checkStrings: true,
checkIdentifiers: false
});
// Advanced configuration
const advancedOptions = defineCSpellPluginOptions({
numSuggestions: 10,
generateSuggestions: true,
autoFix: false,
debugMode: true,
ignoreImports: true,
ignoreImportProperties: true,
checkIdentifiers: true,
checkStrings: true,
checkStringTemplates: true,
checkJSXText: true,
checkComments: true,
configFile: './cspell.config.js',
customWordListFile: './company-terms.txt',
checkScope: [
['YAMLPair[key] YAMLScalar', true],
['JSONProperty[value] JSONLiteral', true]
]
});
// Using in ESLint configuration
export default [
{
plugins: { '@cspell': cspellPlugin },
rules: {
'@cspell/spellchecker': ['warn', pluginOptions]
}
}
];Helper function for defining CSpell-specific configuration with type safety.
/**
* Helper to define the CSpell config section of the cspell-eslint-plugin.
* Provides type safety and IDE autocompletion for CSpell options.
*
* @param cfg - The CSpell config to define
* @returns The same config object with proper typing
*/
function defineCSpellConfig(cfg: CSpellOptions): CSpellOptions;Usage Examples:
import { defineCSpellConfig, defineCSpellPluginOptions } from '@cspell/eslint-plugin';
// Define CSpell configuration separately
const cspellConfig = defineCSpellConfig({
language: 'en-US',
allowCompoundWords: true,
caseSensitive: false,
words: ['webapi', 'nodejs', 'typescript'],
ignoreWords: ['deprecated-term'],
flagWords: ['badword:goodword'],
dictionaries: ['typescript', 'node', 'custom'],
dictionaryDefinitions: [
{
name: 'custom',
description: 'Custom company dictionary',
path: './dictionaries/company.txt'
}
],
ignoreRegExpList: [
'Email',
'Urls',
'/\\b[A-Z]{2,}\\b/g'
],
includeRegExpList: [
'Comments',
'Strings'
]
});
// Use in plugin options
const pluginOptions = defineCSpellPluginOptions({
numSuggestions: 8,
generateSuggestions: true,
autoFix: false,
cspell: cspellConfig
});
// Complex configuration example
const complexCSpellConfig = defineCSpellConfig({
language: 'en-US,en-GB',
allowCompoundWords: true,
enabled: true,
words: [
'webapi', 'microservice', 'kubernetes',
'dockerfile', 'nginx', 'postgresql'
],
ignoreWords: [
'outdated-api-term'
],
flagWords: [
'badpattern:goodpattern',
'typo->correction,alternative'
],
dictionaries: [
'typescript',
'node',
'software-terms',
'company-terms'
],
dictionaryDefinitions: [
{
name: 'software-terms',
description: 'Software development terms',
words: [
'microservice',
'containerization',
'orchestration',
'scalability'
],
supportNonStrictSearches: true
},
{
name: 'company-terms',
description: 'Company-specific terminology',
path: './dictionaries/company-dictionary.txt'
}
],
import: [
'./cspell-base.json',
'@cspell/dict-typescript/cspell-ext.json'
],
ignoreRegExpList: [
'Email',
'Urls',
'HexDigits',
'/\\b[A-Z]{3,}\\b/g', // Ignore acronyms
'/\\$[A-Za-z_][A-Za-z0-9_]*\\$/g' // Ignore template variables
]
});Using both helpers together for comprehensive configuration.
import {
defineCSpellPluginOptions,
defineCSpellConfig
} from '@cspell/eslint-plugin';
// Define CSpell configuration
const cspellSettings = defineCSpellConfig({
language: 'en-US',
words: ['customword', 'companyname'],
dictionaries: ['typescript', 'company-dict'],
dictionaryDefinitions: [
{
name: 'company-dict',
path: './company-dictionary.txt',
description: 'Company terminology'
}
]
});
// Define complete plugin options
const eslintPluginOptions = defineCSpellPluginOptions({
numSuggestions: 6,
generateSuggestions: true,
autoFix: true,
debugMode: false,
checkComments: true,
checkStrings: true,
checkIdentifiers: true,
checkStringTemplates: true,
checkJSXText: true,
ignoreImports: true,
ignoreImportProperties: true,
configFile: './cspell.config.js',
cspellOptionsRoot: import.meta.url,
cspell: cspellSettings
});
// Use in ESLint configuration
export default [
{
plugins: { '@cspell': cspellPlugin },
rules: {
'@cspell/spellchecker': ['warn', eslintPluginOptions]
}
}
];The helper functions provide several advantages:
Example with Type Errors:
// ❌ This would cause a TypeScript error
const badConfig = defineCSpellPluginOptions({
numSugestions: 5, // Typo: should be 'numSuggestions'
autoFx: true // Typo: should be 'autoFix'
});
// ✅ This is correct and type-safe
const goodConfig = defineCSpellPluginOptions({
numSuggestions: 5,
autoFix: true
});