In an ideal world, your code is always clean, consistent, and free of pesky errors. That's the promise of Deno's built-in linting and formatting tools. By integrating these features directly into the runtime, Deno eliminates the need for external dependencies and complex configurations in your projects. These inbuilt tools are fast and performant, not only saving time but also ensuring that every line of code adheres to best practices.
With deno fmt
and deno lint
, you can focus on writing great code, knowing that Deno has your back. It's like having a vigilant assistant who keeps your codebase in top shape, allowing you to concentrate on what truly matters: building amazing applications.
Linting is the process of analyzing your code for potential errors, bugs, and stylistic issues. Deno's built-in linter, deno lint
, supports recommended set of rules from ESLint to provide comprehensive feedback on your code. This includes identifying syntax errors, enforcing coding conventions, and highlighting potential issues that could lead to bugs.
To run the linter, use the following command in your terminal:
By default, deno lint
analyzes all TypeScript and JavaScript files in the current directory and its subdirectories. If you want to lint specific files or directories, you can pass them as arguments to the command. For example:
This command will lint all files in the src/
directory.
The linter can be configured in a deno.json
file. You can specify custom rules, plugins, and settings to tailor the linting process to your needs.
You can view and search the list of available rules and their usage on the List of rules documentation page.
Formatting Jump to heading#Formatting is the process of automatically adjusting the layout of your code to adhere to a consistent style. Deno's built-in formatter, deno fmt
, uses the powerful dprint engine to ensure that your code is always clean, readable, and consistent.
To format your code, simply execute the following command in your terminal:
By default, deno fmt
formats all TypeScript and JavaScript files in the current directory and its subdirectories. If you want to format specific files or directories, you can pass them as arguments to the command. For example:
This command will format all files in the src/
directory.
The deno fmt --check
command is used to verify if your code is properly formatted according to Deno's default formatting rules. Instead of modifying the files, it checks them and reports any formatting issues. This is particularly useful for integrating into continuous integration (CI) pipelines or pre-commit hooks to ensure code consistency across your project.
If there are formatting issues, deno fmt --check
will list the files that need formatting. If all files are correctly formatted, it will simply exit without any output.
You can add deno fmt --check
to your CI pipeline to automatically check for formatting issues. For example, in a GitHub Actions workflow:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- run: deno fmt --check
This ensures that any code changes adhere to the project's formatting standards before being merged.
Integration in VS Code Jump to heading#To enable Deno as your formatter in VS Code, you have to set it up as your default formatter in the settings, and then add a .vscode/settings.json
file in the root of your project with the following configuration:
{
"deno.enablePaths": [
"./deno.json"
]
}
If your deno.json(c)
file is located in a subdirectory of your project, provide the correct relative path to it instead.
bracePosition
Jump to heading#
Define brace position for blocks
sameLine
maintain
, sameLine
, nextLine
, sameLineUnlessHanging
jsx.bracketPosition
Jump to heading#
Define bracket position for JSX
nextLine
maintain
, sameLine
, nextLine
jsx.forceNewLinesSurroundingContent
Jump to heading#
Forces newlines surrounding the content of JSX elements
false
true
, false
jsx.multiLineParens
Jump to heading#
Surrounds the top-most JSX element or fragment in parentheses when it spans multiple lines
prefer
never
, prefer
, always
indentWidth
Jump to heading#
Define indentation width
2
number
lineWidth
Jump to heading#
Define maximum line width
80
number
newLineKind
Jump to heading#
The newline character to use
lf
auto
, crlf
, lf
, system
nextControlFlowPosition
Jump to heading#
Define position of next control flow
sameLine
sameLine
, nextLine
, maintain
semiColons
Jump to heading#
Whether to prefer using semicolons.
true
true
, false
operatorPosition
Jump to heading#
Where to place the operator for expressions that span multiple lines
sameLine
sameLine
, nextLine
, maintain
proseWrap
Jump to heading#
Define how prose should be wrapped
always
always
, never
, preserve
quoteProps
Jump to heading#
Control quoting of object properties
asNeeded
asNeeded
, consistent
, preserve
singleBodyPosition
Jump to heading#
The position of the body in single body blocks
sameLineUnlessHanging
sameLine
, nextLine
, maintain
, sameLineUnlessHanging
singleQuote
Jump to heading#
Use single quotes
false
true
, false
spaceAround
Jump to heading#
Control spacing around enclosed expressions
false
true
, false
spaceSurroundingProperties
Jump to heading#
Control spacing surrounding single line object-like nodes
true
true
, false
trailingCommas
Jump to heading#
Control trailing commas in multi-line arrays/objects
always
always
, never
typeLiteral.separatorKind
Jump to heading#
Define separator kind for type literals
semiColon
comma
, semiColon
unstable-component
Jump to heading#
Enable formatting Svelte, Vue, Astro and Angular files
unstable-sql
Jump to heading#
Enable formatting SQL files
useTabs
Jump to heading#
Use tabs instead of spaces for indentation
false
true
, false
useBraces
Jump to heading#
Whether to use braces for if statements, for statements, and while statements
whenNotSingleLine
maintain
, whenNotSingleLine
, always
, preferNoneThe formatter can be configured in a deno.json
file. You can specify custom settings to tailor the formatting process to your needs.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4