From 856d457cefd91db6658e6cb6a2f8bee86082c700 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 8 Oct 2025 19:03:30 -0400 Subject: [PATCH 1/2] add `fileExtensions` to config --- src/formatter/Cli.hx | 7 +++++-- src/formatter/config/Config.hx | 8 ++++++++ src/formatter/config/FormatterConfig.hx | 6 ++++++ src/formatter/import.hx | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/formatter/Cli.hx b/src/formatter/Cli.hx index 17c4c6df..5d8d850c 100644 --- a/src/formatter/Cli.hx +++ b/src/formatter/Cli.hx @@ -202,8 +202,11 @@ class Cli { } function formatFile(path:String) { - if (path.endsWith(extension)) { - var config = Formatter.loadConfig(path); + var config = Formatter.loadConfig(path); + var fileExtensions = config.fileExtensions; + fileExtensions.push(extension); + + if (fileExtensions.exists(fileExtension -> path.endsWith(fileExtension))) { if (verbose) { verboseLogFile(path, config); } diff --git a/src/formatter/config/Config.hx b/src/formatter/config/Config.hx index a19ba76b..7b0081a9 100644 --- a/src/formatter/config/Config.hx +++ b/src/formatter/config/Config.hx @@ -14,10 +14,12 @@ class Config { public var whitespace:WhitespaceConfig; public var wrapping:WrapConfig; public var disableFormatting:Bool; + public var fileExtensions:Array; public var excludes:Array; public var configFileName:String; public function new() { + fileExtensions = []; excludes = []; readConfigFromString("{}", "hxformat.json"); } @@ -41,8 +43,14 @@ class Config { whitespace = data.whitespace; wrapping = data.wrapping; disableFormatting = data.disableFormatting; + fileExtensions = []; excludes = []; configFileName = fileName; + + for (fileExtension in data.fileExtensions) { + fileExtensions.push(fileExtension); + } + for (exclude in data.excludes) { excludes.push(new EReg(exclude, "")); } diff --git a/src/formatter/config/FormatterConfig.hx b/src/formatter/config/FormatterConfig.hx index a50802ec..5dc8add3 100644 --- a/src/formatter/config/FormatterConfig.hx +++ b/src/formatter/config/FormatterConfig.hx @@ -14,6 +14,12 @@ typedef FormatterConfig = { @:default(auto) @:optional var whitespace:WhitespaceConfig; @:default(auto) @:optional var wrapping:WrapConfig; + /** + * Additional file extensions to format. + * Example: hxp files from OpenFL + */ + @:default(["hx"]) @:optional var fileExtensions:Array; + /** regular expressions matching files to exclude from formatting default is to exclude any `.haxelib`, `.git` and `node_modules` folder diff --git a/src/formatter/import.hx b/src/formatter/import.hx index ef92f20e..70e83ccf 100644 --- a/src/formatter/import.hx +++ b/src/formatter/import.hx @@ -11,6 +11,7 @@ import tokentree.utils.TokenTreeCheckUtils; import formatter.codedata.ParsedCode; import formatter.codedata.TokenInfo; +using Lambda; using StringTools; using tokentree.TokenTreeAccessHelper; using formatter.config.WhitespacePolicy; From 67a38532242b36ab1463a59e70a34a4179f55ebe Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Wed, 8 Oct 2025 19:03:30 -0400 Subject: [PATCH 2/2] generate schema and default json file --- resources/default-hxformat.json | 3 +++ resources/hxformat-schema.json | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/resources/default-hxformat.json b/resources/default-hxformat.json index ce9c13bd..afdcb493 100644 --- a/resources/default-hxformat.json +++ b/resources/default-hxformat.json @@ -116,6 +116,9 @@ "\\.git", "node_modules" ], + "fileExtensions": [ + "hx" + ], "indentation": { "character": "tab", "conditionalPolicy": "aligned", diff --git a/resources/hxformat-schema.json b/resources/hxformat-schema.json index e353a7be..4cff3ed9 100644 --- a/resources/hxformat-schema.json +++ b/resources/hxformat-schema.json @@ -256,6 +256,13 @@ }, "type": "array" }, + "fileExtensions": { + "description": "Additional file extensions to format. * Example: hxp files from OpenFL", + "items": { + "type": "string" + }, + "type": "array" + }, "sameLine": { "$ref": "#/definitions/formatter.config.SameLineConfig" },