Outline
Linting is another task that has gained in popularity recently. Frequently linting your code can help find potential issues before deploying your application code. For example, if your file declares two variables of the same name, linting would find that. Or if you re-initialized a variable you were already using, linting would pick that up as well. Deno has a built in linter that you can use, just like the built in formatter. To lint your files, just use the lint
command. As of v1.6.3, the command also requires the --unstable
command as well. If you don't provide a file or files to the lint command, every file in the directory where the command is run will be linted. Here's an example:
$ deno lint --unstable my-file.ts
There are many linting rules that Deno provides, which can be viewed in the documentation. These rules are enabled by default, but you can disable them on a per file basis, or for a certain part of a file. To disable all linting for the whole file, the // deno-lint-ignore-file
before any JavaScript or TypeScript code on the page. To disable a particular linting rule for the whole file, add the rule after the deno-lint-ignore-file
. If you want to disable the no-explicit-any
rule for the entire file, add this comment to the top of the file: // deno-lint-ignore-file no-explicit-any
. With that, the no-explicit-any
rule will not be applied to the file.
If you just want to disable a rule for a small part of a file, you can add a comment right before the line that should be ignored. This comment is // deno-lint-ignore
, followed by the rule, like no-explicit-any
. At that point, the rule will only be ignored on the following line and not for the whole file. If you don't provide a rule with this comment, then the comment will be ignored and linting will still be done on the following line.
As of v1.6.3 there is no way to disable rules or have other control over the rules other than the above listed way to disable rules one at a time.