CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-solhint

Solidity code linter providing security and style guide validations for smart contract development

Pending
Overview
Eval results
Files

cli-interface.mddocs/

CLI Interface

Command-line interface with main command and subcommands for various linting operations. The CLI provides comprehensive control over linting behavior, configuration, and output formatting.

Capabilities

Main Command

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 banner

Usage 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/*.sol

Stdin Command

Process Solidity code from standard input for pipeline integration.

solhint stdin [--filename <name>]

Options:

  • --filename [file_name] - Name of file for reporting purposes

Usage 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.sol

Init Config Command

Create a default configuration file for the project.

solhint init-config

Usage Examples:

# Create default .solhint.json
solhint init-config

# Alternative syntax
solhint --init

Generated Configuration:

{
  "extends": "solhint:recommended"
}

List Rules Command

Display all rules covered by current configuration files.

solhint list-rules [-c <config_file>]

Options:

  • -c, --config [file_name] - Configuration file to analyze

Usage Examples:

# List rules from default config
solhint list-rules

# List rules from specific config
solhint list-rules -c .solhint-strict.json

Output 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

# Exit codes
0   # No errors found
1   # Linting errors found  
255 # Bad options or configuration errors

Usage 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

Configuration Options

Formatter Selection

# 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 Selection

# 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

Ignore Files

# Default ignore file
.solhintignore

# Custom ignore file
solhint --ignore-path .custom-ignore contracts/*.sol

Ignore File Format:

# Ignore patterns (one per line)
node_modules/
**/*.temp.sol
contracts/test/**
contracts/mocks/*

Warning Limits

# 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-fixing

Fix Command Options

# Auto-fix with confirmation prompt
solhint --fix contracts/*.sol

# Auto-fix without prompt (dangerous)
solhint --fix --noPrompt contracts/*.sol

Fixable Rules Examples:

  • func-visibility - Add missing visibility modifiers
  • var-name-mixedcase - Fix variable naming
  • quotes - Fix quote style consistency
  • visibility-modifier-order - Reorder modifiers

Safety Features:

  • Backup confirmation prompt by default
  • Only applies safe, well-tested fixes
  • Reports which fixes were applied
  • Original issues marked as [FIXED] in output

Fix Workflow

# 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

Caching

Cache Options

# Enable caching for faster repeat runs
solhint --cache contracts/**/*.sol

# Custom cache location
solhint --cache --cache-location .custom-cache contracts/*.sol

Cache Behavior:

  • Default location: node_modules/.cache/solhint/.solhintcache.json
  • Caches results for files with no errors
  • Considers file content hash and configuration hash
  • Skips unchanged files on subsequent runs
  • Automatically invalidated when files or config change

Cache Management

# Clear cache (delete cache file)
rm node_modules/.cache/solhint/.solhintcache.json

# Disable caching temporarily
solhint --no-cache contracts/*.sol  # (not available, use config)

Integration Examples

Package.json Scripts

{
  "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

# .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

CI/CD Integration

# 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

VS Code Integration

// .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
        }
      }
    }
  ]
}

Error Handling

Common Error Scenarios

# 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

Troubleshooting

# 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/*.sol

Install with Tessl CLI

npx tessl i tessl/npm-solhint

docs

cli-interface.md

configuration-management.md

core-processing.md

index.md

output-formatting.md

result-reporting.md

rules-system.md

tile.json