Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-ts-naming-convention

hjcostabr76175MIT2.0.1-betaTypeScript support: included

Builds config for @typescript-eslint/naming-convention rule

eslint, lint, typescript, naming-convention

readme

eslint-ts-naming-conventions

Config generator for typescript-eslint plugin @typescript-eslint/naming-convention rule.

This package helps to keep code naming conventions up to date as your projects grow. If you use eslint shared configs you can update it to share your updates among many projects but still keep the small differences from one project to another different.

It generates a .js file containing the @typescript-eslint/naming-convention rule definition ready to be extended in your .eslintrc.js file.

Allows full customization upon its default config.

Table of contents:

Installation

$ yarn install eslint-ts-naming-conventions

Usage

You can set how your rule configuration should be

import eslintTsNamingConventions from 'eslint-ts-naming-convention'

await eslintTsNamingConventions({

    reportLevel: 'warn',
    filePath: '.eslint-ts-naming-conventions.js',

    // Here you can set variables shared across multiple configs for the rule
    general: {
        functionPrefixes: ['create', 'retrieve', 'search', 'delete'],
        booleanPrefixesLC: ['is', 'should', 'enable', 'require'],
        booleanPrefixesUC: ['IS', 'ENABLE'],
        arraySuffixesLC: ['s', 'List'],
        arraySuffixesUC: ['S', 'LIST'],
    },

    // Here you provide your own configs to overwrite defaults as you like
    specific: [
        {
            selector: 'variable',
            format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
            leadingUnderscore: 'allow',
        },
    ]
)

The above code will generate the .eslint-ts-naming-conventions.js file whose content will look like:

module.exports = {
    rules: {
        "@typescript-eslint/naming-convention": [
            "warn",
            {
                "selector": "variable",
                "format": [
                    "camelCase",
                    "PascalCase",
                    "UPPER_CASE"
                ],
                "leadingUnderscore": "allow"
            },
            {
                "selector": "variable",
                "types": [
                    "boolean"
                ],
                "format": [
                    "camelCase",
                    "PascalCase",
                    "UPPER_CASE"
                ],
                "custom": {
                    "match": true,
                    "regex": "^[is|should|enable|require|force|IS|ENABLE]"
                }
            },
            {
                "selector": "variable",
                "types": [
                    "array"
                ],
                "format": [
                    "camelCase",
                    "PascalCase",
                    "UPPER_CASE"
                ],
                "custom": {
                    "match": true,
                    "regex": "[s|List|S|LIST]$"
                }
            },
            {
                "selector": "function",
                "format": [
                    "camelCase"
                ],
                "custom": {
                    "match": true,
                    "regex": "^[create|retrieve|search|delete]"
                }
            },
        ]
    }
}

Finally in your .eslintrc.js file you extend your fresh generated config:

module.exports = {
    parserOptions: {
        project: './tsconfig.json',
        tsconfigRootDir: __dirname,
    },
    extends: './.eslint-ts-naming-convention.js',
}

Default general settings

Here is the default value for 'general' configuration property.

export const DEFAULT_SETTINGS: Required<GeneralSettingsTP> = {

    classSuffixes: [],

    enumSuffixes: ['Enum'],
    interfacePrefixes: ['I'],
    typeSuffixes: ['TP'],
    typeSuffixesGenerics: ['GTP'],

    arraySuffixesUC: ['S', 'ARRAY', 'LIST'],
    arraySuffixesLC: ['s', 'array', 'Array', 'List'],
    booleanPrefixesUC: ['IS', 'ENABLE', 'REQUIRE', 'FORCE', 'DONT'],
    booleanPrefixesLC: ['is', 'are', 'should', 'must', 'can', 'have', 'has', 'did', 'dont', 'will', 'enable', 'require', 'force'],

    functionPrefixes: [
        'add',
        'are',
        'bond',
        'build',
        'check',
        'concat',
        'create',
        'delete',
        'disable',
        'divide',
        'does',
        'enable',
        'execute',
        'find',
        'finish',
        'fix',
        'get',
        'grant',
        'handle',
        'has',
        'initialize',
        'is',
        'list',
        'merge',
        'mount',
        'multiply',
        'onChange',
        'onError',
        'parse',
        'preValidate',
        'register',
        'remove',
        'run',
        'save',
        'search',
        'send',
        'set',
        'sort',
        'split',
        'start',
        'strip',
        'subtract',
        'sum',
        'throw',
        'transform',
        'update',
        'validate',
        'verify',
        'warn',
    ],
}

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.0.0 (2021-06-11)

Features

Code Refactoring

  • novos prefixos padrao para funcoes (83a0e8f)

BREAKING CHANGES

  • novos prefixos da configuracao padrao podem alterar validacoes ja existentes
  • atualizando propriedade de configuracao specific para specifics