F
F
feeler2020-06-19 12:55:36
Node.js
feeler, 2020-06-19 12:55:36

How to make ESLint accept snake_case?

Gives an error message

16:3  error  Property name `my_var` must match one of the following formats: camelCase, UPPER_CASE, PascalCase    @typescript-eslint/naming-convention
  16:3  error  Identifier 'type_array' is not in camel case 
16:3  error  Property name `my_var_id` must match one of the following formats: camelCase, UPPER_CASE, PascalCase


https://eslint.org/docs/2.0.0/rules/camelcase
according to the docs in .eslintrc.js, the options

rules: {
camelcase: ['error', {properties: 'never'}],
},

rules: {
camelcase: ['error', {allow: ['aa_bb']}],
},

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Vokhmyanin, 2020-06-19
@Delagen

@typescript-eslint/naming-convention is a separate rule not of the core, but of a separate package for parsing, including typescript code https://github.com/typescript-eslint/typescript-es...

A
abberati, 2020-06-19
@abberati

The @typescript-eslint/naming-convention rule throws an error, not camelcase, and you need to configure it in rules

F
feelter, 2020-06-19
@feelter

glued the tips together, it turned out to set up! thank. It is not clear why snake_case is not used by default?
in the .eslintrc.js file we write

module.exports = {
  env: {
    es6: true,
    node: true,
  },

  rules: {
    '@typescript-eslint/naming-convention': [
      'error',
      {
        selector: 'default',
        format: [
          'camelCase',
          'strictCamelCase',
          'PascalCase',
          'StrictPascalCase',
          'snake_case',
          'UPPER_CASE',
        ],
        leadingUnderscore: 'allow',
        trailingUnderscore: 'allow',
      },
    ],
  },
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question