CoffeeLint provides a comprehensive command-line interface for linting CoffeeScript files and directories. The CLI supports batch processing, multiple output formats, configuration management, and integration with build systems and editors.
# Lint a single file
coffeelint file.coffee
# Lint multiple files
coffeelint app.coffee utils.coffee main.coffee
# Lint directories (recursively finds .coffee files)
coffeelint src/ test/ lib/
# Lint mixed files and directories
coffeelint src/ test/spec.coffee lib/utils.coffee# Use custom configuration file
coffeelint -f coffeelint.json src/
coffeelint --file coffeelint.json src/
# Generate default configuration file
coffeelint --makeconfig > coffeelint.json
# Generate minimal configuration (non-default values only)
coffeelint --trimconfig
# Configuration must be provided via file or auto-discovery
# (there is no --configfromstdin option)Configuration File Examples:
# Create a basic configuration file
coffeelint --makeconfig > .coffeelintrc
# Create project-specific configuration
cat > coffeelint.json << EOF
{
"max_line_length": {
"level": "error",
"value": 100
},
"no_tabs": {
"level": "error"
},
"indentation": {
"level": "error",
"value": 2
}
}
EOF
# Use the configuration
coffeelint -f coffeelint.json src/# Lint from standard input
cat app.coffee | coffeelint --stdin
# Read from stdin (errors reported as 'stdin')
echo 'console.log "test"' | coffeelint --stdin
# Combine stdin with file linting
cat lib.coffee | coffeelint --stdin src/ test/CoffeeLint supports multiple output formats for integration with different tools and workflows:
# Default human-readable output
coffeelint src/
# CSV format for spreadsheet analysis
coffeelint --reporter csv src/
# JSLint XML format for IDE integration
coffeelint --reporter jslint src/
# Checkstyle XML format for CI/CD systems
coffeelint --reporter checkstyle src/
# Raw JSON format for programmatic processing
coffeelint --reporter raw src/Output Format Examples:
# Default output
$ coffeelint app.coffee
app.coffee:5:1: error: Unnecessary double quotes (no_unnecessary_double_quotes)
app.coffee:8:15: warn: Line exceeds maximum allowed length (max_line_length)
# CSV output
$ coffeelint --reporter csv app.coffee
filename,lineNumber,level,message,rule
app.coffee,5,error,Unnecessary double quotes,no_unnecessary_double_quotes
app.coffee,8,warn,Line exceeds maximum allowed length,max_line_length
# JSON output for automation
$ coffeelint --reporter raw app.coffee
[
{
"filename": "app.coffee",
"lineNumber": 5,
"level": "error",
"message": "Unnecessary double quotes",
"rule": "no_unnecessary_double_quotes"
}
]# Recursive directory processing (default .coffee extension)
coffeelint src/
# Include additional file extensions
coffeelint --ext coffee,litcoffee src/
# Process literate CoffeeScript files
coffeelint --literate docs/
# Exclude patterns using .coffeelintignore file
echo '**/node_modules/**' > .coffeelintignore
coffeelint src/# Standard exit codes:
# 0 - No errors found
# 1 - Errors found
# 2 - Invalid usage or configuration
# CI/CD pipeline integration
coffeelint src/ test/
if [ $? -eq 0 ]; then
echo "Linting passed"
else
echo "Linting failed"
exit 1
fi
# Git pre-commit hook
#!/bin/sh
coffeelint --reporter csv $(git diff --cached --name-only --diff-filter=ACM | grep '\.coffee$')# Suppress warnings, show only errors
coffeelint --quiet src/The CLI automatically discovers configuration in this order:
-f/--file configuration filecoffeelint.json in current directory or parent directoriescoffeelintConfig section in package.json~/.coffeelint.json in user home directory# Use only built-in defaults (ignore configuration files)
coffeelint --noconfig src/Makefile:
lint:
coffeelint src/ test/
lint-ci:
coffeelint --reporter checkstyle src/ test/ > coffeelint-results.xml
.PHONY: lint lint-cinpm scripts (package.json):
{
"scripts": {
"lint": "coffeelint src test",
"lint:fix": "coffeelint src test --fix",
"lint:ci": "coffeelint --reporter checkstyle src test > reports/coffeelint.xml"
}
}Grunt task:
grunt.loadNpmTasks('grunt-coffeelint');
grunt.initConfig({
coffeelint: {
app: ['src/**/*.coffee'],
tests: ['test/**/*.coffee'],
options: {
configFile: 'coffeelint.json'
}
}
});VS Code settings.json:
{
"coffeelint.enable": true,
"coffeelint.configPath": "./coffeelint.json",
"coffeelint.lintOnSave": true
}Vim/Neovim with ALE:
let g:ale_linters = {'coffee': ['coffeelint']}
let g:ale_coffee_coffeelint_options = '-f coffeelint.json'# Show version information
coffeelint --version
# Display help information
coffeelint --helpCommon Issues:
# Configuration file not found
$ coffeelint -f missing.json src/
# Process continues with default configuration
# Invalid CoffeeScript syntax
$ coffeelint broken.coffee
broken.coffee:3:1: error: unexpected INDENT
# No files found in directory
$ coffeelint empty-dir/
# No output, exit code 0# Enable caching for improved performance
coffeelint --cache src/