@codewaveinnovation/formatter
@codewaveinnovation/formatter
Classes
abstract BaseFormattingRule
Defined in: rules/BaseFormattingRule.ts:8
Abstract base class for rules (Template Method Pattern) Reduces code duplication
Extended by
Implements
Constructors
Constructor
new BaseFormattingRule():
BaseFormattingRule
Returns
Properties
description
abstractreadonlydescription:string
Defined in: rules/BaseFormattingRule.ts:10
Description of what the rule does
Implementation of
name
abstractreadonlyname:string
Defined in: rules/BaseFormattingRule.ts:9
Unique name of the rule
Implementation of
Methods
apply()
apply(
context):FormatResult
Defined in: rules/BaseFormattingRule.ts:12
Apply the formatting rule to the content
Parameters
context
Returns
Implementation of
format()
abstractprotectedformat(context):string
Defined in: rules/BaseFormattingRule.ts:23
Parameters
context
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
Properties
name
abstractreadonlyname:string
Defined in: plugins/BasePlugin.ts:9
Plugin name
Implementation of
version
abstractreadonlyversion:string
Defined in: plugins/BasePlugin.ts:10
Plugin version
Implementation of
Methods
getRules()
abstractgetRules():IFormattingRule[]
Defined in: plugins/BasePlugin.ts:12
Get the rules provided by this plugin
Returns
Implementation of
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
Returns
Methods
format()
format(
content,config?):Promise<FormatResult>
Defined in: formatters/CodeFormatter.ts:12
Format content according to the configured rules
Parameters
content
string
config?
Returns
Promise<FormatResult>
Implementation of
CorePlugin
Defined in: plugins/CorePlugin.ts:14
Default plugin with core formatting rules
Extends
Constructors
Constructor
new CorePlugin():
CorePlugin
Returns
Inherited from
Properties
name
readonlyname:"core"='core'
Defined in: plugins/CorePlugin.ts:15
Plugin name
Overrides
version
readonlyversion:"1.0.0"='1.0.0'
Defined in: plugins/CorePlugin.ts:16
Plugin version
Overrides
Methods
getRules()
getRules():
IFormattingRule[]
Defined in: plugins/CorePlugin.ts:18
Get the rules provided by this plugin
Returns
Overrides
FinalNewlineRule
Defined in: rules/FinalNewlineRule.ts:7
Rule to ensure final newline
Extends
Constructors
Constructor
new FinalNewlineRule():
FinalNewlineRule
Returns
Inherited from
BaseFormattingRule.constructor
Properties
description
readonlydescription:"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
readonlyname:"final-newline"='final-newline'
Defined in: rules/FinalNewlineRule.ts:8
Unique name of the rule
Overrides
Methods
apply()
apply(
context):FormatResult
Defined in: rules/BaseFormattingRule.ts:12
Apply the formatting rule to the content
Parameters
context
Returns
Inherited from
format()
protectedformat(context):string
Defined in: rules/FinalNewlineRule.ts:11
Parameters
context
Returns
string
Overrides
IndentationRule
Defined in: rules/IndentationRule.ts:7
Rule to normalize indentation
Extends
Constructors
Constructor
new IndentationRule():
IndentationRule
Returns
Inherited from
BaseFormattingRule.constructor
Properties
description
readonlydescription:"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
readonlyname:"indentation"="indentation"
Defined in: rules/IndentationRule.ts:8
Unique name of the rule
Overrides
Methods
apply()
apply(
context):FormatResult
Defined in: rules/BaseFormattingRule.ts:12
Apply the formatting rule to the content
Parameters
context
Returns
Inherited from
format()
protectedformat(context):string
Defined in: rules/IndentationRule.ts:11
Parameters
context
Returns
string
Overrides
LineEndingRule
Defined in: rules/LineEndingRule.ts:7
Rule to normalize line endings
Extends
Constructors
Constructor
new LineEndingRule():
LineEndingRule
Returns
Inherited from
BaseFormattingRule.constructor
Properties
description
readonlydescription:"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
readonlyname:"line-ending"='line-ending'
Defined in: rules/LineEndingRule.ts:8
Unique name of the rule
Overrides
Methods
apply()
apply(
context):FormatResult
Defined in: rules/BaseFormattingRule.ts:12
Apply the formatting rule to the content
Parameters
context
Returns
Inherited from
format()
protectedformat(context):string
Defined in: rules/LineEndingRule.ts:11
Parameters
context
Returns
string
Overrides
MaxLineLengthRule
Defined in: rules/MaxLineLengthRule.ts:7
Rule to normalize max line length
Extends
Constructors
Constructor
new MaxLineLengthRule():
MaxLineLengthRule
Returns
Inherited from
BaseFormattingRule.constructor
Properties
description
readonlydescription:"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
readonlyname:"max-line-length"="max-line-length"
Defined in: rules/MaxLineLengthRule.ts:8
Unique name of the rule
Overrides
Methods
apply()
apply(
context):FormatResult
Defined in: rules/BaseFormattingRule.ts:12
Apply the formatting rule to the content
Parameters
context
Returns
Inherited from
format()
protectedformat(context):string
Defined in: rules/MaxLineLengthRule.ts:11
Parameters
context
Returns
string
Overrides
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
Returns
Methods
loadPlugin()
loadPlugin(
plugin):void
Defined in: plugins/PluginManager.ts:13
Load and register a plugin
Parameters
plugin
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
Methods
getAllRules()
getAllRules():
IFormattingRule[]
Defined in: formatters/RuleRegistry.ts:19
Get all registered rules
Returns
Implementation of
getRule()
getRule(
name):IFormattingRule|undefined
Defined in: formatters/RuleRegistry.ts:15
Get a rule by name
Parameters
name
string
Returns
IFormattingRule | undefined
Implementation of
register()
register(
rule):void
Defined in: formatters/RuleRegistry.ts:11
Register a new rule
Parameters
rule
Returns
void
Implementation of
TrailingWhitespaceRule
Defined in: rules/TrailingWhitespaceRule.ts:7
Rule to trim trailing whitespace
Extends
Constructors
Constructor
new TrailingWhitespaceRule():
TrailingWhitespaceRule
Returns
Inherited from
BaseFormattingRule.constructor
Properties
description
readonlydescription:"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
readonlyname:"trailing-whitespace"='trailing-whitespace'
Defined in: rules/TrailingWhitespaceRule.ts:8
Unique name of the rule
Overrides
Methods
apply()
apply(
context):FormatResult
Defined in: rules/BaseFormattingRule.ts:12
Apply the formatting rule to the content
Parameters
context
Returns
Inherited from
format()
protectedformat(context):string
Defined in: rules/TrailingWhitespaceRule.ts:11
Parameters
context
Returns
string
Overrides
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?
optionalfilePath: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?
optionalplugins: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?
Returns
Promise<FormatResult>
IFormattingRule
Defined in: interfaces/IFormattingRule.ts:6
Interface for formatting rules (Interface Segregation Principle)
Properties
description
readonlydescription:string
Defined in: interfaces/IFormattingRule.ts:15
Description of what the rule does
name
readonlyname: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
Returns
IPlugin
Defined in: interfaces/IPlugin.ts:6
Interface for plugin system (Open/Closed Principle)
Properties
name
readonlyname:string
Defined in: interfaces/IPlugin.ts:10
Plugin name
version
readonlyversion: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
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
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
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?
optionaloptions: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
getDefaultConfig()
getDefaultConfig():
FormatterConfig
Defined in: index.ts:37
Default configuration