Usage of linters/linting tools within Deno
Asked Answered
H

3

10

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.

Hipbone answered 27/5, 2020 at 0:59 Comment(0)
U
7

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"]
      }
    }
  ]
}
Unstop answered 27/5, 2020 at 14:51 Comment(2)
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!Hipbone
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 scriptsCarmacarmack
S
4

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

Starspangled answered 16/7, 2020 at 13:45 Comment(0)
A
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.

Atkins answered 27/5, 2020 at 12:54 Comment(1)
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..Hipbone

© 2022 - 2024 — McMap. All rights reserved.