wentjun
wentjun

Reputation: 42566

Usage of linters/linting tools within Deno

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.

Upvotes: 10

Views: 5506

Answers (3)

Marcos Casagrande
Marcos Casagrande

Reputation: 40444

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"]
      }
    }
  ]
}

Upvotes: 7

Luca Casonato
Luca Casonato

Reputation: 386

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

Upvotes: 3

cvng
cvng

Reputation: 1878

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.

Upvotes: 2

Related Questions