9

I am currently exploring Deno as proof-of-concept, and I am trying to find suitable way to setup linting within the project.

Here is part of the eslint configuration that I am thinking of setting up, but I do understand that this can cause more problems due to the differences between Node.JS and Deno:

parser: '@typescript-eslint/parser',
extends: [
  'eslint:recommended',
  'plugin:@typescript-eslint/eslint-recommended',
  'plugin:@typescript-eslint/recommended',
],

That being said, what are some of practices/methods to set up linting and formatting within Deno/ TypeScript projects?

I understand that deno lint is still a work in progress, and the lack of documentation is hindering me from adopting it at this moment.

jps
  • 20,041
  • 15
  • 75
  • 79
wentjun
  • 40,384
  • 10
  • 95
  • 107

3 Answers3

6

This is the eslint config Deno uses, and works perfectly for std/ which uses Deno.

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "createDefaultProgram": true
  },
  "plugins": ["@typescript-eslint"],
  "extends": [
    "plugin:@typescript-eslint/recommended",
    "prettier",
    "prettier/@typescript-eslint"
  ],
  "rules": {
    "@typescript-eslint/array-type": ["error", { "default": "array-simple" }],
    "@typescript-eslint/ban-ts-comment": ["off"],
    "@typescript-eslint/explicit-member-accessibility": ["off"],
    "@typescript-eslint/explicit-module-boundary-types": ["off"],
    "@typescript-eslint/no-non-null-assertion": ["off"],
    "@typescript-eslint/no-use-before-define": ["off"],
    "@typescript-eslint/no-parameter-properties": ["off"],
    "@typescript-eslint/no-unused-vars": [
      "error",
      { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
    ],
    "@typescript-eslint/ban-ts-ignore": ["off"],
    "@typescript-eslint/no-empty-function": ["off"],
    "no-return-await": "error",
    "require-await": "error",
    "no-async-promise-executor": "error"
  },
  "overrides": [
    {
      "files": ["*.js"],
      "rules": {
        "@typescript-eslint/explicit-function-return-type": ["off"]
      }
    },
    {
      "files": ["tools/node_*.js"],
      "rules": {
        "@typescript-eslint/no-var-requires": ["off"]
      }
    }
  ]
}
Richie Bendall
  • 7,738
  • 4
  • 38
  • 58
Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98
  • Hey! Thanks for the answer. Yes, I have been trying something like what you have been working on, and it seems like we will have to make do with this, until they have released v1 of the linter! – wentjun May 28 '20 at 02:52
  • But it doesn't seem to be working. I've put an .eslintrc file in the root of my Deno project, with the exact contents from this answer, and added a few more rules to test, like `"indent": ["error", 4]` and `"@typescript-eslint/quotes": ["error", "single"]` and when I run `deno lint` it completely ignores that .eslintrc file it seems. Also, I don't know how to tell `deno fmt` to use eslint rules. In my regular frontend projects I have `"eslint --format **/*.ts` to format ts files using eslint, but not sure how to do that in a Deno project, without Node/npm and npm scripts – MrCroft Jun 13 '21 at 14:06
4

You can now use deno lint to lint code: https://deno.land/manual/tools/linter

Luca Casonato
  • 378
  • 3
  • 7
3

You can format your Deno project files by running this command:

Check if the source files are formatted

deno fmt --check

Auto-format JavaScript/TypeScript source code

deno fmt

I think this is our best option for now, since deno_lint is not ready yet.

cvng
  • 1,822
  • 17
  • 23
  • Hey, thanks for the answer! Yes, I agree. I guess we will have to make do with the existing eslint rules, with the `deno fmt` command, to format out code. Hope they will release the linter soon.. – wentjun May 28 '20 at 02:54