Skip to main content
The deno lint command analyzes your source code for potential errors and style issues.

Usage

deno lint [OPTIONS] [FILES]...

Basic Examples

# Lint all files in current directory
deno lint

# Lint specific files
deno lint src/main.ts

# Lint and auto-fix issues
deno lint --fix

# List all available rules
deno lint --rules

# Output as JSON
deno lint --json

Rule Management

--rules
boolean
List all available lint rules
deno lint --rules
--rules-tags
string
Show rules from specific tags
deno lint --rules --rules-tags=recommended
--rules-include
string
Include specific rules
deno lint --rules-include=no-unused-vars,no-debugger
--rules-exclude
string
Exclude specific rules
deno lint --rules-exclude=no-explicit-any,ban-types

Auto-fix

--fix
boolean
Automatically fix lint issues where possible
# Fix all auto-fixable issues
deno lint --fix

# Fix specific files
deno lint --fix src/main.ts

Output Formats

--json
boolean
Output lint results as JSON
deno lint --json > lint-results.json
--compact
boolean
Output in compact format
deno lint --compact

Watch Mode

--watch
string
Watch for file changes and re-lint automatically
# Watch mode
deno lint --watch

# Watch specific paths
deno lint --watch=src/
--no-clear-screen
boolean
Don’t clear the screen on watch mode restart

File Filtering

--ignore
string
Ignore files or directories
deno lint --ignore=build/,dist/,**/*_test.ts

Configuration

Configure linting in deno.json:
{
  "lint": {
    "include": ["src/"],
    "exclude": ["src/testdata/", "build/"],
    "rules": {
      "tags": ["recommended"],
      "include": ["ban-untagged-todo"],
      "exclude": ["no-unused-vars"]
    }
  }
}

Common Rules

  • no-unused-vars - Disallow unused variables
  • no-debugger - Disallow debugger statements
  • no-explicit-any - Disallow explicit any type
  • no-undef - Disallow undefined variables
  • no-unreachable - Disallow unreachable code
  • eqeqeq - Require === and !==
  • no-empty - Disallow empty block statements
  • no-prototype-builtins - Disallow calling built-in object methods directly
  • no-throw-literal - Disallow throwing non-Error values
  • prefer-as-const - Prefer as const over literal type

Fresh-Specific Rules

  • fresh-server-event-handlers - Validate Fresh server event handlers
  • fresh-handler-export - Ensure Fresh handlers are exported correctly

Ignoring Code

Ignore File

Add a comment at the top of the file:
// deno-lint-ignore-file

function problematic() {
  var x = 1; // normally would warn about 'var'
}

Ignore Next Line

// deno-lint-ignore no-unused-vars
const unused = "this variable is not used";

Ignore Multiple Rules

// deno-lint-ignore no-explicit-any no-unused-vars
const data: any = {};

Ignore in Configuration

{
  "lint": {
    "rules": {
      "exclude": ["no-explicit-any", "no-unused-vars"]
    }
  }
}

Examples

Lint with Auto-fix in CI

#!/bin/bash
# Check if linting would make changes
if ! deno lint --check; then
  echo "Linting issues found. Run 'deno lint --fix' to fix them."
  exit 1
fi

Custom Rule Configuration

{
  "lint": {
    "rules": {
      "tags": ["recommended"],
      "include": [
        "ban-untagged-todo",
        "camelcase",
        "explicit-function-return-type"
      ],
      "exclude": [
        "no-explicit-any"
      ]
    }
  }
}

Lint Specific File Types

# Lint only TypeScript files
deno lint **/*.ts

# Lint excluding test files
deno lint --ignore="**/*_test.ts"

Output Lint Results

# Generate JSON report
deno lint --json > lint-report.json

# Compact output for CI
deno lint --compact src/

Pre-commit Hook

#!/bin/bash
# .git/hooks/pre-commit

if ! deno lint; then
  echo "Please fix linting issues before committing"
  exit 1
fi

Build docs developers (and LLMs) love