Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@typescript-eslint/naming-convention: How to mix error and warn rules?

I am trying to set up naming conventions for my project.

I have some variables in snake_case that I would like ESLint to warn me about such as:

const { order_id } = req.params;

I removed typescript-eslint/camelcase as it is deprecated and trying to set up naming-convention and added a new error rule for boolean.

 '@typescript-eslint/naming-convention': [
          'error',
          {
            selector: 'variable',
            types: ['boolean'],
            format: ['PascalCase'],
            prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
          },
        ],

How can I add a warning for snake_case variables?

like image 381
Kevin Amiranoff Avatar asked Jul 14 '20 20:07

Kevin Amiranoff


Video Answer


1 Answers

If you want ESLint to warn you about variable names which are not in camelCase it is as simple as:

"@typescript-eslint/naming-convention": [
  "warn",
  {
    selector: "variable",
    format: ["camelCase"]
  },
],

Respective warning shown in VS Code:

enter image description here

like image 63
Telmo Trooper Avatar answered Oct 16 '22 16:10

Telmo Trooper