Skip to content

@codewaveinnovation/formatter


@codewaveinnovation/formatter

Clases

abstract BaseFormattingRule

Definido en: rules/BaseFormattingRule.ts:8

Clase base abstracta para reglas (Patrón Template Method) Reduce la duplicación de código

Extendida por

Implementa

Constructores

Constructor

new BaseFormattingRule(): BaseFormattingRule

Retorna

BaseFormattingRule

Propiedades

description

abstract readonly description: string

Definido en: rules/BaseFormattingRule.ts:10

Descripción de lo que hace la regla

Implementación de

IFormattingRule.description

name

abstract readonly name: string

Definido en: rules/BaseFormattingRule.ts:9

Nombre único de la regla

Implementación de

IFormattingRule.name

Métodos

apply()

apply(context): FormatResult

Definido en: rules/BaseFormattingRule.ts:12

Aplicar la regla de formateo al contenido

Parámetros
context

FormatContext

Retorna

FormatResult

Implementación de

IFormattingRule.apply

format()

abstract protected format(context): string

Defined in: rules/BaseFormattingRule.ts:23

Parameters
context

FormatContext

Returns

string


abstract BasePlugin

Defined in: plugins/BasePlugin.ts:8

Abstract base plugin class Follows Open/Closed Principle - plugins extend without modifying core

Extended by

Implements

Constructors

Constructor

new BasePlugin(): BasePlugin

Returns

BasePlugin

Properties

name

abstract readonly name: string

Defined in: plugins/BasePlugin.ts:9

Plugin name

Implementation of

IPlugin.name

version

abstract readonly version: string

Defined in: plugins/BasePlugin.ts:10

Plugin version

Implementation of

IPlugin.version

Methods

getRules()

abstract getRules(): IFormattingRule[]

Defined in: plugins/BasePlugin.ts:12

Get the rules provided by this plugin

Returns

IFormattingRule[]

Implementation of

IPlugin.getRules


CodeFormatter

Defined in: formatters/CodeFormatter.ts:9

Main formatter implementation (Dependency Inversion Principle) Depends on abstractions (IRuleRegistry) not concretions

Implements

Constructors

Constructor

new CodeFormatter(ruleRegistry): CodeFormatter

Defined in: formatters/CodeFormatter.ts:10

Parameters
ruleRegistry

IRuleRegistry

Returns

CodeFormatter

Methods

format()

format(content, config?): Promise<FormatResult>

Defined in: formatters/CodeFormatter.ts:12

Format content according to the configured rules

Parameters
content

string

config?

FormatterConfig

Returns

Promise<FormatResult>

Implementation of

IFormatter.format


CorePlugin

Defined in: plugins/CorePlugin.ts:14

Default plugin with core formatting rules

Extends

Constructors

Constructor

new CorePlugin(): CorePlugin

Returns

CorePlugin

Inherited from

BasePlugin.constructor

Properties

name

readonly name: "core" = 'core'

Defined in: plugins/CorePlugin.ts:15

Plugin name

Overrides

BasePlugin.name

version

readonly version: "1.0.0" = '1.0.0'

Defined in: plugins/CorePlugin.ts:16

Plugin version

Overrides

BasePlugin.version

Methods

getRules()

getRules(): IFormattingRule[]

Defined in: plugins/CorePlugin.ts:18

Get the rules provided by this plugin

Returns

IFormattingRule[]

Overrides

BasePlugin.getRules


FinalNewlineRule

Defined in: rules/FinalNewlineRule.ts:7

Rule to ensure final newline

Extends

Constructors

Constructor

new FinalNewlineRule(): FinalNewlineRule

Returns

FinalNewlineRule

Inherited from

BaseFormattingRule.constructor

Properties

description

readonly description: "Ensures file ends with a newline" = 'Ensures file ends with a newline'

Defined in: rules/FinalNewlineRule.ts:9

Description of what the rule does

Overrides

BaseFormattingRule.description

name

readonly name: "final-newline" = 'final-newline'

Defined in: rules/FinalNewlineRule.ts:8

Unique name of the rule

Overrides

BaseFormattingRule.name

Methods

apply()

apply(context): FormatResult

Defined in: rules/BaseFormattingRule.ts:12

Apply the formatting rule to the content

Parameters
context

FormatContext

Returns

FormatResult

Inherited from

BaseFormattingRule.apply

format()

protected format(context): string

Defined in: rules/FinalNewlineRule.ts:11

Parameters
context

FormatContext

Returns

string

Overrides

BaseFormattingRule.format


IndentationRule

Defined in: rules/IndentationRule.ts:7

Rule to normalize indentation

Extends

Constructors

Constructor

new IndentationRule(): IndentationRule

Returns

IndentationRule

Inherited from

BaseFormattingRule.constructor

Properties

description

readonly description: "Normalizes indentation to spaces or tabs" = "Normalizes indentation to spaces or tabs"

Defined in: rules/IndentationRule.ts:9

Description of what the rule does

Overrides

BaseFormattingRule.description

name

readonly name: "indentation" = "indentation"

Defined in: rules/IndentationRule.ts:8

Unique name of the rule

Overrides

BaseFormattingRule.name

Methods

apply()

apply(context): FormatResult

Defined in: rules/BaseFormattingRule.ts:12

Apply the formatting rule to the content

Parameters
context

FormatContext

Returns

FormatResult

Inherited from

BaseFormattingRule.apply

format()

protected format(context): string

Defined in: rules/IndentationRule.ts:11

Parameters
context

FormatContext

Returns

string

Overrides

BaseFormattingRule.format


LineEndingRule

Defined in: rules/LineEndingRule.ts:7

Rule to normalize line endings

Extends

Constructors

Constructor

new LineEndingRule(): LineEndingRule

Returns

LineEndingRule

Inherited from

BaseFormattingRule.constructor

Properties

description

readonly description: "Normalizes line endings (LF, CRLF, or CR)" = 'Normalizes line endings (LF, CRLF, or CR)'

Defined in: rules/LineEndingRule.ts:9

Description of what the rule does

Overrides

BaseFormattingRule.description

name

readonly name: "line-ending" = 'line-ending'

Defined in: rules/LineEndingRule.ts:8

Unique name of the rule

Overrides

BaseFormattingRule.name

Methods

apply()

apply(context): FormatResult

Defined in: rules/BaseFormattingRule.ts:12

Apply the formatting rule to the content

Parameters
context

FormatContext

Returns

FormatResult

Inherited from

BaseFormattingRule.apply

format()

protected format(context): string

Defined in: rules/LineEndingRule.ts:11

Parameters
context

FormatContext

Returns

string

Overrides

BaseFormattingRule.format


MaxLineLengthRule

Defined in: rules/MaxLineLengthRule.ts:7

Rule to normalize max line length

Extends

Constructors

Constructor

new MaxLineLengthRule(): MaxLineLengthRule

Returns

MaxLineLengthRule

Inherited from

BaseFormattingRule.constructor

Properties

description

readonly description: "Warns or wraps lines exceeding maximum length" = "Warns or wraps lines exceeding maximum length"

Defined in: rules/MaxLineLengthRule.ts:9

Description of what the rule does

Overrides

BaseFormattingRule.description

name

readonly name: "max-line-length" = "max-line-length"

Defined in: rules/MaxLineLengthRule.ts:8

Unique name of the rule

Overrides

BaseFormattingRule.name

Methods

apply()

apply(context): FormatResult

Defined in: rules/BaseFormattingRule.ts:12

Apply the formatting rule to the content

Parameters
context

FormatContext

Returns

FormatResult

Inherited from

BaseFormattingRule.apply

format()

protected format(context): string

Defined in: rules/MaxLineLengthRule.ts:11

Parameters
context

FormatContext

Returns

string

Overrides

BaseFormattingRule.format


PluginManager

Defined in: plugins/PluginManager.ts:7

Plugin manager to handle plugin loading and registration

Constructors

Constructor

new PluginManager(ruleRegistry): PluginManager

Defined in: plugins/PluginManager.ts:8

Parameters
ruleRegistry

IRuleRegistry

Returns

PluginManager

Methods

loadPlugin()

loadPlugin(plugin): void

Defined in: plugins/PluginManager.ts:13

Load and register a plugin

Parameters
plugin

IPlugin

Returns

void

loadPlugins()

loadPlugins(plugins): void

Defined in: plugins/PluginManager.ts:21

Load multiple plugins

Parameters
plugins

IPlugin[]

Returns

void


RuleRegistry

Defined in: formatters/RuleRegistry.ts:8

Rule registry implementation (Single Responsibility Principle) Responsible only for managing the collection of rules

Implements

Constructors

Constructor

new RuleRegistry(): RuleRegistry

Returns

RuleRegistry

Methods

getAllRules()

getAllRules(): IFormattingRule[]

Defined in: formatters/RuleRegistry.ts:19

Get all registered rules

Returns

IFormattingRule[]

Implementation of

IRuleRegistry.getAllRules

getRule()

getRule(name): IFormattingRule | undefined

Defined in: formatters/RuleRegistry.ts:15

Get a rule by name

Parameters
name

string

Returns

IFormattingRule | undefined

Implementation of

IRuleRegistry.getRule

register()

register(rule): void

Defined in: formatters/RuleRegistry.ts:11

Register a new rule

Parameters
rule

IFormattingRule

Returns

void

Implementation of

IRuleRegistry.register


TrailingWhitespaceRule

Defined in: rules/TrailingWhitespaceRule.ts:7

Rule to trim trailing whitespace

Extends

Constructors

Constructor

new TrailingWhitespaceRule(): TrailingWhitespaceRule

Returns

TrailingWhitespaceRule

Inherited from

BaseFormattingRule.constructor

Properties

description

readonly description: "Removes trailing whitespace from lines" = 'Removes trailing whitespace from lines'

Defined in: rules/TrailingWhitespaceRule.ts:9

Description of what the rule does

Overrides

BaseFormattingRule.description

name

readonly name: "trailing-whitespace" = 'trailing-whitespace'

Defined in: rules/TrailingWhitespaceRule.ts:8

Unique name of the rule

Overrides

BaseFormattingRule.name

Methods

apply()

apply(context): FormatResult

Defined in: rules/BaseFormattingRule.ts:12

Apply the formatting rule to the content

Parameters
context

FormatContext

Returns

FormatResult

Inherited from

BaseFormattingRule.apply

format()

protected format(context): string

Defined in: rules/TrailingWhitespaceRule.ts:11

Parameters
context

FormatContext

Returns

string

Overrides

BaseFormattingRule.format

Interfaces

FormatContext

Defined in: interfaces/types.ts:30

Context passed to rules during formatting

Properties

config

config: FormatterConfig

Defined in: interfaces/types.ts:32

content

content: string

Defined in: interfaces/types.ts:31

filePath?

optional filePath: string

Defined in: interfaces/types.ts:33


FormatResult

Defined in: interfaces/types.ts:4

Represents the result of a formatting operation

Properties

appliedRules

appliedRules: string[]

Defined in: interfaces/types.ts:7

changed

changed: boolean

Defined in: interfaces/types.ts:6

content

content: string

Defined in: interfaces/types.ts:5


FormatterConfig

Defined in: interfaces/types.ts:22

Represents the formatter configuration

Properties

plugins?

optional plugins: string[]

Defined in: interfaces/types.ts:24

rules

rules: RuleConfig[]

Defined in: interfaces/types.ts:23


IFormatter

Defined in: interfaces/IFormatter.ts:6

Interface for the main formatter (Dependency Inversion Principle)

Methods

format()

format(content, config?): Promise<FormatResult>

Defined in: interfaces/IFormatter.ts:10

Format content according to the configured rules

Parameters
content

string

config?

FormatterConfig

Returns

Promise<FormatResult>


IFormattingRule

Defined in: interfaces/IFormattingRule.ts:6

Interface for formatting rules (Interface Segregation Principle)

Properties

description

readonly description: string

Defined in: interfaces/IFormattingRule.ts:15

Description of what the rule does

name

readonly name: string

Defined in: interfaces/IFormattingRule.ts:10

Unique name of the rule

Methods

apply()

apply(context): FormatResult

Defined in: interfaces/IFormattingRule.ts:20

Apply the formatting rule to the content

Parameters
context

FormatContext

Returns

FormatResult


IPlugin

Defined in: interfaces/IPlugin.ts:6

Interface for plugin system (Open/Closed Principle)

Properties

name

readonly name: string

Defined in: interfaces/IPlugin.ts:10

Plugin name

version

readonly version: string

Defined in: interfaces/IPlugin.ts:15

Plugin version

Methods

getRules()

getRules(): IFormattingRule[]

Defined in: interfaces/IPlugin.ts:20

Get the rules provided by this plugin

Returns

IFormattingRule[]


IRuleRegistry

Defined in: interfaces/IRuleRegistry.ts:6

Interface for rule registry (Single Responsibility Principle)

Methods

getAllRules()

getAllRules(): IFormattingRule[]

Defined in: interfaces/IRuleRegistry.ts:20

Get all registered rules

Returns

IFormattingRule[]

getRule()

getRule(name): IFormattingRule | undefined

Defined in: interfaces/IRuleRegistry.ts:15

Get a rule by name

Parameters
name

string

Returns

IFormattingRule | undefined

register()

register(rule): void

Defined in: interfaces/IRuleRegistry.ts:10

Register a new rule

Parameters
rule

IFormattingRule

Returns

void


RuleConfig

Defined in: interfaces/types.ts:13

Represents a formatting rule configuration

Properties

enabled

enabled: boolean

Defined in: interfaces/types.ts:15

name

name: string

Defined in: interfaces/types.ts:14

options?

optional options: Record<string, unknown>

Defined in: interfaces/types.ts:16

Functions

createFormatter()

createFormatter(): CodeFormatter

Defined in: index.ts:24

Create a formatter instance with core rules loaded

Returns

CodeFormatter


getDefaultConfig()

getDefaultConfig(): FormatterConfig

Defined in: index.ts:37

Default configuration

Returns

FormatterConfig