Solidity code linter providing security and style guide validations for smart contract development
—
Command-line interface with main command and subcommands for various linting operations. The CLI provides comprehensive control over linting behavior, configuration, and output formatting.
Primary command for linting Solidity files with extensive configuration options.
solhint [options] <file> [...other_files]Options:
-f, --formatter [name] - Report formatter (stylish, table, tap, unix, json, compact, sarif)-w, --max-warnings [number] - Maximum number of allowed warnings-c, --config [file_name] - Configuration file to use-q, --quiet - Report errors only (suppress warnings)--ignore-path [file_name] - File to use as .solhintignore--fix - Automatically fix problems where possible--cache - Only lint files that changed since last run--cache-location [file_name] - Path to cache file--noPrompt - Skip confirmation prompt for fix operations--init - Create configuration file--disc - Skip update checking--save - Save report to timestamped file--noPoster - Remove Discord community bannerUsage Examples:
# Basic linting
solhint contracts/Token.sol
# Lint multiple files
solhint contracts/Token.sol contracts/Crowdsale.sol
# Use glob patterns
solhint 'contracts/**/*.sol'
solhint 'contracts/*.sol' 'test/*.sol'
# With configuration file
solhint -c .solhint-strict.json contracts/*.sol
# Different output formats
solhint -f json contracts/*.sol
solhint -f table contracts/*.sol > report.txt
# Auto-fix issues
solhint --fix contracts/*.sol
# Quiet mode (errors only)
solhint -q contracts/*.sol
# With caching for performance
solhint --cache contracts/**/*.sol
# Limit warnings
solhint -w 5 contracts/*.sol
# Save report to file
solhint --save contracts/*.solProcess Solidity code from standard input for pipeline integration.
solhint stdin [--filename <name>]Options:
--filename [file_name] - Name of file for reporting purposesUsage Examples:
# Process from stdin
echo "contract Test {}" | solhint stdin
# With filename for better error reporting
echo "contract Test {}" | solhint stdin --filename Test.sol
# From file via pipe
cat contracts/Token.sol | solhint stdin --filename Token.sol
# With formatting
cat contracts/Token.sol | solhint stdin -f json
# In build pipelines
curl -s https://example.com/contract.sol | solhint stdin --filename remote.solCreate a default configuration file for the project.
solhint init-configUsage Examples:
# Create default .solhint.json
solhint init-config
# Alternative syntax
solhint --initGenerated Configuration:
{
"extends": "solhint:recommended"
}Display all rules covered by current configuration files.
solhint list-rules [-c <config_file>]Options:
-c, --config [file_name] - Configuration file to analyzeUsage Examples:
# List rules from default config
solhint list-rules
# List rules from specific config
solhint list-rules -c .solhint-strict.jsonOutput Format:
Configuration File:
{
"extends": "solhint:recommended",
"rules": {
"func-visibility": "error",
"max-line-length": ["warn", 120]
}
}
Rules:
- avoid-call-value: error
- avoid-low-level-calls: error
- func-visibility: error
- max-line-length: ["warn", 120]# Exit codes
0 # No errors found
1 # Linting errors found
255 # Bad options or configuration errorsUsage Examples:
# Check exit code in scripts
if solhint contracts/*.sol; then
echo "No errors found"
else
echo "Linting failed with exit code $?"
fi
# In CI/CD pipelines
solhint contracts/*.sol || exit 1# Available formatters
solhint -f stylish contracts/*.sol # Default, human-readable
solhint -f json contracts/*.sol # Machine-readable JSON
solhint -f table contracts/*.sol # Tabular format
solhint -f compact contracts/*.sol # One-line per issue
solhint -f unix contracts/*.sol # Editor-friendly format
solhint -f tap contracts/*.sol # Test Anything Protocol
solhint -f sarif contracts/*.sol # Security tools format# Configuration file hierarchy (searched in order)
# 1. Command line: -c option
solhint -c custom-config.json contracts/*.sol
# 2. Project files (searched automatically)
# - package.json (solhint property)
# - .solhint.json
# - .solhintrc
# - .solhintrc.json
# - .solhintrc.yaml/.yml
# - .solhintrc.js
# - solhint.config.js# Default ignore file
.solhintignore
# Custom ignore file
solhint --ignore-path .custom-ignore contracts/*.solIgnore File Format:
# Ignore patterns (one per line)
node_modules/
**/*.temp.sol
contracts/test/**
contracts/mocks/*# Fail if more than 5 warnings
solhint -w 5 contracts/*.sol
# Allow unlimited warnings
solhint -w -1 contracts/*.sol
# No warnings allowed (fail on any warning)
solhint -w 0 contracts/*.sol# Auto-fix with confirmation prompt
solhint --fix contracts/*.sol
# Auto-fix without prompt (dangerous)
solhint --fix --noPrompt contracts/*.solFixable Rules Examples:
func-visibility - Add missing visibility modifiersvar-name-mixedcase - Fix variable namingquotes - Fix quote style consistencyvisibility-modifier-order - Reorder modifiersSafety Features:
[FIXED] in output# 1. Review issues first
solhint contracts/*.sol
# 2. Apply fixes with confirmation
solhint --fix contracts/*.sol
# Prompts: "FIX option detected. Please BACKUP your contracts first. Continue? (y/n)"
# 3. Review changes
git diff
# 4. Run again to see remaining issues
solhint contracts/*.sol# Enable caching for faster repeat runs
solhint --cache contracts/**/*.sol
# Custom cache location
solhint --cache --cache-location .custom-cache contracts/*.solCache Behavior:
node_modules/.cache/solhint/.solhintcache.json# Clear cache (delete cache file)
rm node_modules/.cache/solhint/.solhintcache.json
# Disable caching temporarily
solhint --no-cache contracts/*.sol # (not available, use config){
"scripts": {
"lint": "solhint 'contracts/**/*.sol'",
"lint:fix": "solhint --fix 'contracts/**/*.sol'",
"lint:json": "solhint -f json 'contracts/**/*.sol'",
"lint:ci": "solhint -f json 'contracts/**/*.sol' > lint-results.json"
}
}# .git/hooks/pre-commit
#!/bin/sh
echo "Running Solhint..."
solhint -q 'contracts/**/*.sol'
if [ $? -ne 0 ]; then
echo "Linting failed. Commit aborted."
exit 1
fi# GitHub Actions
- name: Run Solhint
run: |
solhint -f json 'contracts/**/*.sol' > lint-results.json
- name: Check Results
run: |
if [ $(jq '.[] | .errorCount' lint-results.json | jq -s 'add') -gt 0 ]; then
echo "Linting errors found"
exit 1
fi// .vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "solhint",
"type": "shell",
"command": "solhint",
"args": ["${file}"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": {
"owner": "solhint",
"fileLocation": "relative",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error)\\s+(.*)\\s+([a-z-]+)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
}
}
]
}# Configuration file not found
solhint -c missing.json contracts/*.sol
# Exit code: 255
# No files match pattern
solhint 'nonexistent/**/*.sol'
# Exit code: 255
# Invalid formatter
solhint -f invalid-formatter contracts/*.sol
# Exit code: 255
# Linting errors found
solhint contracts/*.sol # (when errors exist)
# Exit code: 1# Verbose error information
DEBUG=solhint* solhint contracts/*.sol
# Check configuration loading
solhint list-rules
# Test with minimal config
echo '{"extends": "solhint:recommended"}' > .test-config.json
solhint -c .test-config.json contracts/*.solInstall with Tessl CLI
npx tessl i tessl/npm-solhint