From b749f52ae56602fe0638585a1265775dd79a007c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 12 Sep 2025 11:55:24 +0200 Subject: [PATCH] chore: simplify string using backticks # Conflicts: # internal/extgen/classparser.go # internal/extgen/gofile_test.go --- caddy/app.go | 2 +- internal/extgen/cfile_test.go | 6 +++--- internal/extgen/constparser.go | 2 +- internal/extgen/constparser_test.go | 12 ++++++------ internal/extgen/stub_test.go | 2 +- internal/extgen/utils.go | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/caddy/app.go b/caddy/app.go index 01831c53..9170ff03 100644 --- a/caddy/app.go +++ b/caddy/app.go @@ -42,7 +42,7 @@ type FrankenPHPApp struct { logger *slog.Logger } -var iniError = errors.New("'php_ini' must be in the format: php_ini \"\" \"\"") +var iniError = errors.New(`"php_ini" must be in the format: php_ini "" ""`) // CaddyModule returns the Caddy module information. func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo { diff --git a/internal/extgen/cfile_test.go b/internal/extgen/cfile_test.go index f9d8c749..0a8d250f 100644 --- a/internal/extgen/cfile_test.go +++ b/internal/extgen/cfile_test.go @@ -313,7 +313,7 @@ func TestCFileSpecialCharacters(t *testing.T) { content, err := cGen.buildContent() require.NoError(t, err) - expectedInclude := "#include \"" + tt.expected + ".h\"" + expectedInclude := `#include "` + tt.expected + `.h"` assert.Contains(t, content, expectedInclude, "Content should contain include: %s", expectedInclude) }) } @@ -424,8 +424,8 @@ func TestCFileConstants(t *testing.T) { }, }, contains: []string{ - "REGISTER_LONG_CONSTANT(\"GLOBAL_INT\", 42, CONST_CS | CONST_PERSISTENT);", - "REGISTER_STRING_CONSTANT(\"GLOBAL_STRING\", \"test\", CONST_CS | CONST_PERSISTENT);", + `REGISTER_LONG_CONSTANT("GLOBAL_INT", 42, CONST_CS | CONST_PERSISTENT);`, + `REGISTER_STRING_CONSTANT("GLOBAL_STRING", "test", CONST_CS | CONST_PERSISTENT);`, }, }, } diff --git a/internal/extgen/constparser.go b/internal/extgen/constparser.go index a61f23de..2f304895 100644 --- a/internal/extgen/constparser.go +++ b/internal/extgen/constparser.go @@ -99,7 +99,7 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e func determineConstantType(value string) phpType { value = strings.TrimSpace(value) - if (strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"")) || + if (strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`)) || (strings.HasPrefix(value, "`") && strings.HasSuffix(value, "`")) { return phpString } diff --git a/internal/extgen/constparser_test.go b/internal/extgen/constparser_test.go index 549bc912..29f0e38f 100644 --- a/internal/extgen/constparser_test.go +++ b/internal/extgen/constparser_test.go @@ -250,7 +250,7 @@ func TestConstantParserTypeDetection(t *testing.T) { value string expectedType phpType }{ - {"string with double quotes", "\"hello world\"", phpString}, + {"string with double quotes", `"hello world"`, phpString}, {"string with backticks", "`hello world`", phpString}, {"boolean true", "true", phpBool}, {"boolean false", "false", phpBool}, @@ -443,13 +443,13 @@ func TestConstantParserDeclRegex(t *testing.T) { name string value string }{ - {"const MyConst = \"value\"", true, "MyConst", "\"value\""}, + {`const MyConst = "value"`, true, "MyConst", `"value"`}, {"const IntConst = 42", true, "IntConst", "42"}, {"const BoolConst = true", true, "BoolConst", "true"}, {"const IotaConst = iota", true, "IotaConst", "iota"}, {"const ComplexValue = someFunction()", true, "ComplexValue", "someFunction()"}, - {"const SpacedName = \"with spaces\"", true, "SpacedName", "\"with spaces\""}, - {"var notAConst = \"value\"", false, "", ""}, + {`const SpacedName = "with spaces"`, true, "SpacedName", `"with spaces"`}, + {`var notAConst = "value"`, false, "", ""}, {"const", false, "", ""}, {"const =", false, "", ""}, } @@ -518,10 +518,10 @@ func TestPHPConstantCValue(t *testing.T) { name: "string constant", constant: phpConstant{ Name: "StringConst", - Value: "\"hello\"", + Value: `"hello"`, PhpType: phpString, }, - expected: "\"hello\"", // strings should remain unchanged + expected: `"hello"`, // strings should remain unchanged }, { name: "boolean constant", diff --git a/internal/extgen/stub_test.go b/internal/extgen/stub_test.go index 418e9587..b9d689ff 100644 --- a/internal/extgen/stub_test.go +++ b/internal/extgen/stub_test.go @@ -134,7 +134,7 @@ func TestStubGenerator_BuildContent(t *testing.T) { contains: []string{ "