aboutsummaryrefslogtreecommitdiff
path: root/formatter.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-05 08:37:11 +0000
committerFuwn <[email protected]>2026-02-05 08:37:11 +0000
commit9f39211f307a078e07e476d694fcfeed7d5abad3 (patch)
tree6c8d7a696281f417abb2091fbb27c9b3bc41db5a /formatter.go
parentfeat(adapter): Add EcmaScript adapter for JS/TS/JSX/TSX formatting (diff)
downloadiku-9f39211f307a078e07e476d694fcfeed7d5abad3.tar.xz
iku-9f39211f307a078e07e476d694fcfeed7d5abad3.zip
feat(formatter): Dispatch adapter by file extension for multi-language support
Diffstat (limited to 'formatter.go')
-rw-r--r--formatter.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/formatter.go b/formatter.go
index c6b5902..3d4e873 100644
--- a/formatter.go
+++ b/formatter.go
@@ -1,6 +1,9 @@
package main
-import "github.com/Fuwn/iku/engine"
+import (
+ "github.com/Fuwn/iku/engine"
+ "path/filepath"
+)
type CommentMode int
@@ -21,9 +24,8 @@ type lineInformation struct {
isStartLine bool
}
-func (f *Formatter) Format(source []byte) ([]byte, error) {
- adapter := &GoAdapter{}
- _, events, err := adapter.Analyze(source)
+func (f *Formatter) Format(source []byte, filename string) ([]byte, error) {
+ _, events, err := analyzeSource(source, filename)
if err != nil {
return nil, err
@@ -33,3 +35,12 @@ func (f *Formatter) Format(source []byte) ([]byte, error) {
return []byte(formattingEngine.FormatToString(events)), nil
}
+
+func analyzeSource(source []byte, filename string) ([]byte, []engine.LineEvent, error) {
+ switch filepath.Ext(filename) {
+ case ".js", ".ts", ".jsx", ".tsx":
+ return (&EcmaScriptAdapter{}).Analyze(source)
+ default:
+ return (&GoAdapter{}).Analyze(source)
+ }
+}