UNPKG

@bmacher/eslint-config-typescript

Version:

ESLint config based on AirBnB for TypeScript & CDK.

213 lines (139 loc) • 5.37 kB
[![npm version](https://img.shields.io/npm/v/@bmacher/eslint-config-typescript)](https://www.npmjs.com/package/@bmacher/eslint-config-typescript/v/latest) [![GitHub license](https://img.shields.io/github/license/bmacher/eslint-config-typescript.svg)](https://github.com/bmacher/eslint-config-typescript/blob/master/LICENSE) # ESLint Config Typescript > ESLint config based on [AirBnB](https://github.com/airbnb/javascript) for TypeScript & CDK. ## Table of contents - [Installation](#installation) - [Usage](#usage) - [Default Rules](#default-rules) - [import/prefer-default-export](#importprefer-default-export) - [max-params](#max-params) - [no-console](#no-console) - [@typescript-eslint/member-delimiter-style](#typescript-eslintmember-delimiter-style) - [@typescript-eslint/naming-convention](#typescript-eslintnaming-convention) - [Interface](#interface) - [Class](#class) - [Enum](#enum) - [Variable](#variable) - [Function](#function) - [ClassProperty](#classproperty) - [ObjectLiteralProperty](#objectliteralproperty) - [CDK Rules](#cdk-rules) - [no-new](#no-new) - [@typescript-eslint/naming-convention](#typescript-eslintnaming-convention-1) - [ObjectLiteralProperty](#objectliteralproperty-1) - [Rules only](#rules-only) - [Overrides](#overrides) - [import/no-extraneous-dependencies](#importno-extraneous-dependencies) ## Installation ```sh yarn add --dev @sdc-production/eslint-config-typescript # Or with npm npm install --save-dev @sdc-production/eslint-config-typescript ``` ## Usage ```ts module.exports = { root: true, parserOptions: { project: './tsconfig.json' }, extends: [ "@sdc-production/eslint-config-typescript", // Use this in CDK projects instead "@sdc-production/eslint-config-typescript/cdk", // Use this if you only need the rules and overrides. "@sdc-production/eslint-config-typescript/rules-only", ], } ``` The short version `@sdc-production/typescript` does also work. However, that is [not recommended by ESLint](https://eslint.org/docs/developer-guide/shareable-configs#npm-scoped-modules), as it can lead to name clashes. ## Default Rules <!-- Template Title Description... šŸ‘Ž Don't ```ts ``` šŸ‘ Do ```ts ``` --> ### [import/prefer-default-export](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md) Using default exports can lead to different names in imports. Therefore, named imports are preferred. Value: `off` šŸ‘Ž Don't ```ts // bar-1.ts import foo from 'foo'; foo.bar(); // bar-2.ts import bar from 'foo'; bar.bar(); ``` šŸ‘ Do ```ts import { bar } from 'foo'; bar(); ``` ### [max-params](https://eslint.org/docs/rules/max-params) Functions with too many parameters either do too much or introduce too many variables. Value: `['error', 3]` šŸ‘Ž Don't ```ts function foo(a: string, b: string, c: string, d: string): void {} ``` šŸ‘ Do ```ts interface FooProps { a: string; b: string; c: string; d: string; } function foo(props: FooProps): void {} // OR if possible function foo(a: string, b: string): Something {} function bar(foo: Something, c: string, d: string): void {} const resultOfFoo = foo(...); bar(resultOfFoo, ...) ``` ### [no-console](https://eslint.org/docs/rules/no-console) Logging should never be considered bad. Value: `off` ### [@typescript-eslint/member-delimiter-style](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/member-delimiter-style.md) There should only be one delimiter for members in interfaces or types. Value: `;` ### [@typescript-eslint/naming-convention](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/naming-convention.md) #### *Interface* Value: `PascalCase` with no I prefix (`/^(?![I][A-Z])/`) [Guideline](https://github.com/microsoft/TypeScript/wiki/Coding-guidelines#names) by TypeScript for contributors. #### *Class* Value: `PascalCase` #### *Enum* Value: `PascalCase` #### *Variable* Value: `camelCase, UPPER_CASE` #### *Function* Value: `camelCase` #### *ClassProperty* Value: `camelCase` #### *ObjectLiteralProperty* Value: `camelCase` ## CDK Rules ### no-new Either `no-new` or `no-unused-var` would be thrown when you only need to create a resource but not using it elsewhere. Value: `off` Example ```ts new Bucket(myStack, 'Bucket'); ``` ### @typescript-eslint/naming-convention #### *ObjectLiteralProperty* Environments of Lambdas (and any other place) should be UPPER_CASE and properties of CFN resources can be PascalCase as well. Value: `camelCase, UPPER_CASE, PascalCase` ## Rules only Only provides the `rules` and `overrides` from the base config and no other configuration. This can be used when the e.g. the parser is configured elsewhere but you still want to have the rules. ## Overrides ### [import/no-extraneous-dependencies](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md) Provides only the `Rules` and `Overrides` from the base configuration and no other configuration. This can be used if e.g. the parser is configured elsewhere but you still want to have the rules. Common use case would be inside frontend configurations like in Vue.