Formatting with deno fmt
Basic Usage
Supported File Types
Deno’s formatter supports:- TypeScript (
.ts,.tsx) - JavaScript (
.js,.jsx,.mjs) - JSON (
.json,.jsonc) - Markdown (
.md,.markdown)
Configuration
Configure formatting indeno.json:
deno.json
Formatting Options
Basic Options
Basic Options
useTabs- Use tabs instead of spaces (default:false)lineWidth- Maximum line width (default:80)indentWidth- Number of spaces per indent (default:2)singleQuote- Use single quotes (default:false)semiColons- Add semicolons (default:true)
Advanced Options
Advanced Options
proseWrap- How to wrap prose in Markdown:"always","never","preserve"(default:"always")quoteProps- When to quote object properties:"asNeeded","consistent","preserve"(default:"preserve")newLineKind- Newline character:"auto","crlf","lf","system"(default:"lf")
Brace Styles
Brace Styles
useBraces- Use braces for single-line blocks:"maintain","whenNotSingleLine","always","preferNone"(default:"whenNotSingleLine")bracePosition- Opening brace position:"maintain","sameLine","nextLine","sameLineUnlessHanging"(default:"sameLine")singleBodyPosition- Single body position:"maintain","sameLine","nextLine","sameLineUnlessHanging"(default:"sameLineUnlessHanging")nextControlFlowPosition- Next control flow position:"maintain","sameLine","nextLine"(default:"sameLine")
JSX Options
JSX Options
jsx.bracketPosition- JSX bracket position:"maintain","sameLine","nextLine"(default:"nextLine")jsx.forceNewLineSurroundingContent- Force newlines around JSX content (default:false)jsx.multiLineParens- Wrap multi-line JSX in parentheses:"never","prefer","always"(default:"prefer")
Other Options
Other Options
operatorPosition- Binary operator position:"maintain","sameLine","nextLine"(default:"sameLine")trailingCommas- Add trailing commas:"never","always","onlyMultiLine"(default:"onlyMultiLine")spaceAround- Spaces around enclosed expressions (default:false)spaceSurroundingProperties- Spaces in object literals (default:true)
Include/Exclude Files
deno.json
Ignore Formatting
Use comments to ignore specific code:Linting with deno lint
Basic Usage
Configuration
deno.json
Rule Configuration
- Include Specific Rules
- Exclude Rules
Available Rules
View all available rules:ban-ts-comment- Disallow@ts-ignoreand similar commentsban-untagged-todo- Require TODO comments to have an issue numberno-unused-vars- Disallow unused variablesno-explicit-any- Disallow explicitanytypeno-await-in-sync-fn- Disallowawaitin non-async functionseqeqeq- Require===and!==no-const-assign- Disallow reassigningconstvariablesno-debugger- Disallowdebuggerstatements
Report Formats
deno.json:
deno.json
Ignore Linting
Use comments to ignore specific rules:Lint Plugins
Load custom lint plugins (unstable):deno.json
CI/CD Integration
GitHub Actions
.github/workflows/lint.yml
Pre-commit Hook
Create.git/hooks/pre-commit:
VS Code Integration
The Deno VS Code extension automatically:- Formats on save
- Shows lint errors inline
- Provides quick fixes
.vscode/settings.json:
.vscode/settings.json
Task Configuration
Add tasks todeno.json:
deno.json
Best Practices
Format before committing
Always run
deno fmt before committing codeUse recommended rules
Start with recommended lint rules and customize as needed
Automate in CI
Add formatting and linting checks to your CI pipeline
Configure editor
Set up format-on-save in your editor
Document exceptions
Add comments explaining why rules are disabled
Keep config minimal
Only override defaults when necessary
Example Configuration
deno.json
Migration from Other Tools
From Prettier
Deno’s formatter is similar to Prettier with sensible defaults:deno.json
From ESLint
Map common ESLint rules to Deno lint:no-unused-vars→no-unused-vars@typescript-eslint/no-explicit-any→no-explicit-anyeqeqeq→eqeqeqno-debugger→no-debuggerprefer-const→prefer-const