ESLint config based on AirBnB for TypeScript & CDK.
yarn add --dev @sdc-production/eslint-config-typescript
# Or with npm
npm install --save-dev @sdc-production/eslint-config-typescript
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, as it can lead to name clashes.
Using default exports can lead to different names in imports. Therefore, named imports are preferred.
Value: off
π Don't
// bar-1.ts
import foo from 'foo';
foo.bar();
// bar-2.ts
import bar from 'foo';
bar.bar();
π Do
import { bar } from 'foo';
bar();
Functions with too many parameters either do too much or introduce too many variables.
Value: ['error', 3]
π Don't
function foo(a: string, b: string, c: string, d: string): void {}
π Do
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, ...)
Logging should never be considered bad.
Value: off
There should only be one delimiter for members in interfaces or types.
Value: ;
Value: PascalCase
with no I prefix (/^(?![I][A-Z])/
)
Guideline by TypeScript for contributors.
Value: PascalCase
Value: PascalCase
Value: camelCase, UPPER_CASE
Value: camelCase
Value: camelCase
Value: camelCase
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
new Bucket(myStack, 'Bucket');
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
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.
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.