Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 344
wentjun Avatar asked May 27 '20 00:05

wentjun


People also ask

What is the use of linters in JavaScript?

JavaScript linters are tools that you can use to help you debug your code. They scan your scripts for common issues and errors, and give you back a report with line numbers that you can use to fix things. In addition to actual bugs and errors, they also check for subjective, stylistic preferences as well.

Which of the following is linting tools in JavaScript?

JSLint. First released by Douglas Crockford in 2002, JSLint is a reliable JavaScript linting tool that can process JSON text and JavaScript source code. It also comes ready with a configuration that, according to Crockford, follows the JS best practices.

What is linting in node JS?

A linter is a computer program that analyzes and checks source code. It flags programming errors, indentation errors, formatting errors, bugs, and suspicious constructs.

What is ESLint used for?

ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs. In many ways, it is similar to JSLint and JSHint with a few exceptions: ESLint uses Espree for JavaScript parsing.


Video Answer


1 Answers

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"]
      }
    }
  ]
}
like image 194
Marcos Casagrande Avatar answered Oct 07 '22 01:10

Marcos Casagrande