Formatting and linting
Linting and formatting are two capacities considered crucial for maintaining consistency and enforcing good practices in any code base. With this in mind, Deno has embedded the tools to enable both in its CLI. We'll get to know them in this section.
Formatting
To format Deno's code, the CLI provides the fmt
command. This is an opinionated formatter that aims to solve any questions regarding code formatting. The main goal is for developers to not have to care about the format of their code – not when writing code nor when reviewing pull requests.
Running the following command with no argument formats all the files in the current directory:
$ deno fmt /Users/alexandre/Deno-Web-Development/Chapter02/my-first-deno-program.js /Users/alexandre/Deno-Web-Development/Chapter02/bundle.js
If we want to format a single file, we can send it as an argument.
To check files for formatting errors, we can use this together with the --check
flag...