Linting and formatting
Ende ships a linter and a formatter in the ende binary. No packages to
install, no config files required:
ende lint # catch bugs and anti-patterns
ende fmt # format code, markdown, and JSON
Both are fast, run the same way locally and in CI, and are configured (when you
need to configure anything at all) in the same ende.json as the rest of your
project.
Linting
Linting is the process of analyzing your code for potential errors, bugs, and
stylistic issues. Ende's built-in linter,
ende 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:
ende lint
By default, ende 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:
ende lint src/
This command will lint all files in the src/ directory.
A finding shows the rule name, the offending code, and a hint:
$ ende lint main.ts
error[require-await]: Async function 'fetchData' has no 'await' expression
--> /project/main.ts:1:1
|
1 | async function fetchData() {
| ^^^^^
= hint: Remove 'async' keyword from the function or use 'await' expression inside.
docs: https://docs.ende.sh/lint/rules/require-await
Found 1 problem
Checked 1 file
Some rules can fix the problem for you: run ende lint --fix to apply those
fixes automatically. To silence a rule for one line, add an ignore directive
naming the rule above it:
// deno-lint-ignore require-await
async function fetchData() {
return "data";
}
See the ende lint reference for all flags and
directive forms.
The linter can be configured in a
ende.json file. You can specify
custom rules, plugins, and settings to tailor the linting process to your needs.
Linting rules
You can view and search the list of available rules and their usage on the List of rules documentation page.
Formatting
Formatting is the process of automatically adjusting the layout of your code to
adhere to a consistent style. Ende's built-in formatter, ende 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:
ende fmt
By default, ende 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:
ende fmt src/
This command will format all files in the src/ directory.
Checking your formatting
The ende fmt --check command is used to verify if your code is properly
formatted according to Ende'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, ende fmt --check will list the files that need
formatting. If all files are correctly formatted, it will simply exit without
any output.
Integration in CI
You can add ende 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
- name: Install Ende
run: |
curl -fsSL https://ende.sh/install.sh | sh
echo "$HOME/.ende/bin" >> "$GITHUB_PATH"
- run: ende fmt --check
This ensures that any code changes adhere to the project's formatting standards before being merged.
Configuration
The formatter is configured with the fmt field in your
ende.json file. See
all formatting options for the full
list of settings and their defaults.
ende fmt also reads .editorconfig files and
uses them to fill in any option you have not set through a CLI flag or the
ende.json fmt block. The precedence is CLI flags, then ende.json, then
.editorconfig, then the built-in defaults, so an .editorconfig value only
applies when nothing higher up has set it. See
Inheriting settings from .editorconfig
for the property mappings.