Skip to content

borela-tech/eslint-config

Repository files navigation

@borela-tech/eslint-config

CI npm version License: Apache-2.0 Node Version

Shared ESLint configuration for Borela Tech projects.

Features

Installation

npm install --save-dev @borela-tech/eslint-config

Usage

Create a file named eslint.config.ts in the root of your project and add the following code:

import {config} from '@borela-tech/eslint-config'
export {config as default}

Custom Rules

This package includes 17 custom ESLint rules to enforce consistent code organization. All custom rules are auto-fixable.

brace-style-control-statements

Enforces control statement bodies to be on a separate line from the condition.

Bad:

if (foo) return
if (foo) {return}

Good:

if (foo)
  return

if (foo) {
  return
}

export-filename-match

Enforces exported filenames match the default export name. Allows exceptions for index.ts, .test.ts, and .spec.ts files.

Bad:

// file: utils.ts
export default function helper() {}

Good:

// file: helper.ts
export default function helper() {}

function-call-argument-line-break

Enforces line breaks in function call arguments when the line exceeds 80 characters.

Bad:

const result = someFunctionWithAVeryLongName(arg1, arg2, arg3)

Good:

const result = someFunctionWithAVeryLongName(
  arg1,
  arg2,
  arg3,
)

function-parameter-line-break

Enforces line breaks in function parameters when the line exceeds 80 characters.

Bad:

function myFunctionWithAVeryLongName(param1, param2, param3) {}

Good:

function myFunctionWithAVeryLongName(
  param1,
  param2,
  param3,
) {}

imports-and-re-exports-at-top

Ensures all imports and re-exports appear at the top of the file before any other statements.

Bad:

const foo = 'bar'
import {baz} from 'module'

Good:

import {baz} from 'module'
const foo = 'bar'

individual-imports

Enforces one import per statement instead of grouped imports:

Bad:

import {foo, bar, baz} from 'module'

Good:

import {foo} from 'module'
import {bar} from 'module'
import {baz} from 'module'

individual-re-exports

Enforces one re-export per statement instead of grouped re-exports:

Bad:

export {foo, bar, baz} from 'module'

Good:

export {foo} from 'module'
export {bar} from 'module'
export {baz} from 'module'

interface-property-line-break

Enforces line breaks in interface properties when the line exceeds 80 characters.

Bad:

interface Config {foo: string; bar: number; baz: boolean}

Good:

interface Config {
  foo: string
  bar: number
  baz: boolean
}

multiline-union-type-aliases

Enforces multiline union type aliases.

Bad:

type Status = 'pending' | 'active' | 'completed'

Good:

type Status =
  | 'pending'
  | 'active'
  | 'completed'

no-inline-object-types

Disallows inline object types in function parameters and return types. Converts them to named interfaces.

Bad:

function foo(x: {a: string}) {}
let x: {a: string} = {a: ''}

Good:

interface X {a: string}
function foo(x: X) {}

interface InlineType {a: string}
let x: InlineType = {a: ''}

no-unnecessary-braces

Removes braces from single-line statements and adds braces to multi-line statements without braces.

Bad:

if (condition) {
  doSomething()
}

if (condition)
  return {
    a: 1,
    b: 2,
    c: 3,
 }

Good:

if (condition)
  doSomething()

if (condition) {
  return {
    a: 1,
    b: 2,
    c: 3,
 }
}

one-export-per-file

Enforces one export per file. Allows exceptions for index.ts, .test.ts, and .spec.ts files.

Bad:

export const foo = 'bar'
export const baz = 'qux'

Good:

// file: foo.ts
export const foo = 'bar'

// file: index.ts
export const foo = 'bar'
export const baz = 'qux'

prefer-inline-export

Prefers inline exports.

Bad:

class Foo {}
export {foo}

Good:

export class Foo {}

single-line-imports

Ensures imports are on a single line (converts multiline imports to single line).

Bad:

import {
  foo,
  bar,
} from 'module'

Good:

import {foo, bar} from 'module'

single-line-re-exports

Ensures re-exports are on a single line (converts multiline re-exports to single line).

Bad:

export {
  foo,
  bar,
} from 'module'

Good:

export {foo, bar} from 'module'

sorted-imports

Enforces imports are sorted alphabetically within their respective groups:

  1. Side-effect imports (e.g., import 'module')
  2. Default imports (e.g., import React from 'react')
  3. Named imports (e.g., import {useState} from 'react')
  4. Type imports (e.g., import type {Config} from 'module')

Within each group, imports are sorted alphabetically by module source. Named import specifiers within each import are also sorted alphabetically.

Bad:

import {z, a} from 'module'
import type {Config} from 'config'
import React from 'react'

Good:

import React from 'react'
import {a, z} from 'module'
import type {Config} from 'config' 

sorted-re-exports

Enforces re-exports are sorted alphabetically within their respective groups:

  1. Re-export all (e.g., export * from 'module')
  2. Re-export named (e.g., export {foo, bar} from 'module')
  3. Re-export type (e.g., export type {Type1, Type2} from 'module')

Within each group, re-exports are sorted alphabetically by module source. Named export specifiers are also sorted alphabetically.

Bad:

export {bar} from 'module'
export * from 'another'
export type {TypeB} from 'types'

Good:

export * from 'another'
export {bar} from 'module'
export type {TypeB} from 'types'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors