Skip to content

Commit 7001ce7

Browse files
committed
Apply go fmt on all files
1 parent 622bc12 commit 7001ce7

8 files changed

Lines changed: 39 additions & 39 deletions

File tree

src/nodejs/hooks/dynatrace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package hooks
22

33
import (
4-
"github.com/cloudfoundry/libbuildpack"
54
"github.com/Dynatrace/libbuildpack-dynatrace"
5+
"github.com/cloudfoundry/libbuildpack"
66
)
77

88
func init() {

src/nodejs/hooks/sealights.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,40 +198,40 @@ func (sl *SealightsHook) ExtractNpmRunScriptName(command string) (string, error)
198198
if strings.HasPrefix(cleanCommand, "web:") {
199199
cleanCommand = strings.TrimSpace(cleanCommand[4:])
200200
}
201-
201+
202202
// Handle commands with cd prefix (e.g., "cd app && npm run start")
203203
if strings.Contains(cleanCommand, "&&") {
204204
parts := strings.Split(cleanCommand, "&&")
205205
if len(parts) >= 2 {
206206
cleanCommand = strings.TrimSpace(parts[len(parts)-1])
207207
}
208208
}
209-
209+
210210
// Extract script name from npm commands
211211
// Patterns to match:
212212
// - "npm start" -> "start"
213213
// - "npm run start-dev" -> "start-dev"
214214
// - "npm run dev" -> "dev"
215215
patterns := []string{
216-
`^npm\s+run\s+([a-zA-Z0-9\-_]+)`, // npm run <script>
217-
`^npm\s+([a-zA-Z0-9\-_]+)`, // npm <script>
216+
`^npm\s+run\s+([a-zA-Z0-9\-_]+)`, // npm run <script>
217+
`^npm\s+([a-zA-Z0-9\-_]+)`, // npm <script>
218218
}
219-
219+
220220
for _, pattern := range patterns {
221221
re, err := regexp.Compile(pattern)
222222
if err != nil {
223223
sl.Log.Warning("Failed to compile regex pattern %s: %s", pattern, err)
224224
continue
225225
}
226-
226+
227227
matches := re.FindStringSubmatch(cleanCommand)
228228
if len(matches) >= 2 {
229229
scriptName := matches[1]
230230
sl.Log.Debug("Extracted npm script name: %s from command: %s", scriptName, command)
231231
return scriptName, nil
232232
}
233233
}
234-
234+
235235
return "", fmt.Errorf("failed to extract npm script name from command: %s", command)
236236
}
237237

@@ -240,11 +240,11 @@ func (sl *SealightsHook) ValidateNpmRunScript(packageJson map[string]interface{}
240240
if !ok || scripts == nil {
241241
return fmt.Errorf("no scripts section found in package.json")
242242
}
243-
243+
244244
if _, exists := scripts[scriptName]; !exists {
245245
return fmt.Errorf("script '%s' not found in package.json", scriptName)
246246
}
247-
247+
248248
return nil
249249
}
250250

@@ -322,7 +322,7 @@ func (sl *SealightsHook) SetApplicationStartInPackageJson(stager *libbuildpack.S
322322
if err != nil {
323323
return err
324324
}
325-
325+
326326
// Validate that the target script exists
327327
err = sl.ValidateNpmRunScript(packageJson, targetScript)
328328
if err != nil {
@@ -338,20 +338,20 @@ func (sl *SealightsHook) SetApplicationStartInPackageJson(stager *libbuildpack.S
338338
return err
339339
}
340340
}
341-
341+
342342
scripts := packageJson["scripts"].(map[string]interface{})
343343
originalStartScript, _ := scripts[targetScript].(string)
344344
if originalStartScript == "" {
345345
return fmt.Errorf("failed to read %s script from %s", targetScript, PackageJsonFile)
346346
}
347-
347+
348348
// Update the command with Sealights injection
349349
var newCmd string
350350
newCmd, err = sl.updateStartCommand(originalStartScript)
351351
if err != nil {
352352
return err
353353
}
354-
354+
355355
sl.Log.Debug("Injecting Sealights into '%s' script: %s -> %s", targetScript, originalStartScript, newCmd)
356356
scripts[targetScript] = newCmd
357357

@@ -529,13 +529,13 @@ func (sl *SealightsHook) injectSealights(stager *libbuildpack.Stager) error {
529529
sl.Log.Info("Integrating sealights into manifest.yml")
530530
return sl.SetApplicationStartInManifest(stager)
531531
} else {
532-
sl.Log.Info("Integrating sealights into package.json")
533-
// Use configured script name or default to "start"
534-
scriptName := sl.parameters.NpmRunScript
535-
if scriptName == "" {
536-
scriptName = "start"
537-
}
538-
return sl.SetApplicationStartInPackageJson(stager, scriptName)
532+
sl.Log.Info("Integrating sealights into package.json")
533+
// Use configured script name or default to "start"
534+
scriptName := sl.parameters.NpmRunScript
535+
if scriptName == "" {
536+
scriptName = "start"
537+
}
538+
return sl.SetApplicationStartInPackageJson(stager, scriptName)
539539
}
540540
}
541541

src/nodejs/hooks/sealights_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ var _ = Describe("Sealights hook", func() {
293293
It("should use custom npmRunScript parameter for npm commands", func() {
294294
err = os.WriteFile(filepath.Join(stager.BuildDir(), procfileName), []byte("web: npm run dev"), 0755)
295295
Expect(err).To(BeNil())
296-
296+
297297
customPackageJson := "{\n \"scripts\": {\n \"dev\": \"" + originalStartCommand + "\",\n \"start\": \"node index.js\"\n }\n}"
298298
err = os.WriteFile(filepath.Join(stager.BuildDir(), packageJsonName), []byte(customPackageJson), 0755)
299299
Expect(err).To(BeNil())
@@ -314,10 +314,10 @@ var _ = Describe("Sealights hook", func() {
314314

315315
err = sealights.AfterCompile(stager)
316316
Expect(err).To(BeNil())
317-
317+
318318
packageJson, err := sealights.ReadPackageJson(stager)
319319
Expect(err).To(BeNil())
320-
320+
321321
devScript := packageJson["scripts"].(map[string]interface{})["dev"].(string)
322322
Expect(devScript).To(ContainSubstring("slnodejs"))
323323
Expect(devScript).To(ContainSubstring("index.js --build 192 --name Good"))
@@ -649,10 +649,10 @@ var _ = Describe("Sealights hook", func() {
649649
BeforeEach(func() {
650650
packageJson = map[string]interface{}{
651651
"scripts": map[string]interface{}{
652-
"start": "node server.js",
653-
"test": "mocha",
654-
"dev": "nodemon server.js",
655-
"build": "webpack",
652+
"start": "node server.js",
653+
"test": "mocha",
654+
"dev": "nodemon server.js",
655+
"build": "webpack",
656656
},
657657
}
658658
})
@@ -696,7 +696,7 @@ var _ = Describe("Sealights hook", func() {
696696
BeforeEach(func() {
697697
err = os.WriteFile(filepath.Join(stager.BuildDir(), procfileName), []byte("web: npm run custom-script"), 0755)
698698
Expect(err).To(BeNil())
699-
699+
700700
customPackageJson := "{\n \"scripts\": {\n \"custom-script\": \"" + originalStartCommand + "\",\n \"start\": \"node index.js\"\n }\n}"
701701
err = os.WriteFile(filepath.Join(stager.BuildDir(), packageJsonName), []byte(customPackageJson), 0755)
702702
Expect(err).To(BeNil())
@@ -731,7 +731,7 @@ var _ = Describe("Sealights hook", func() {
731731

732732
packageJson, err := sealights.ReadPackageJson(stager)
733733
Expect(err).To(BeNil())
734-
734+
735735
customScript := packageJson["scripts"].(map[string]interface{})["custom-script"].(string)
736736
cleanResult := strings.ReplaceAll(customScript, " ", "")
737737
Expect(cleanResult).To(Equal(expected))
@@ -746,7 +746,7 @@ var _ = Describe("Sealights hook", func() {
746746

747747
packageJson, err := sealights.ReadPackageJson(stager)
748748
Expect(err).To(BeNil())
749-
749+
750750
startScript := packageJson["scripts"].(map[string]interface{})["start"].(string)
751751
Expect(startScript).To(ContainSubstring("slnodejs"))
752752
})

src/nodejs/hooks/snyk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func init() {
4949
})
5050
}
5151

52-
//Snyk hook
52+
// Snyk hook
5353
func (h SnykHook) AfterCompile(stager *libbuildpack.Stager) error {
5454
if h.isTokenExists() == false {
5555
h.Log.Debug("Snyk token wasn't found...")

src/nodejs/integration/pnpm_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func testPNPM(platform switchblade.Platform, fixtures string) func(*testing.T, s
4747
Expect(logs).To(ContainLines(
4848
ContainSubstring("Installing node modules (pnpm-lock.yaml)"),
4949
))
50-
50+
5151
// Verify store directory is used
5252
Expect(logs).To(ContainLines(
5353
ContainSubstring("Using pnpm store directory:"),
@@ -70,7 +70,7 @@ func testPNPM(platform switchblade.Platform, fixtures string) func(*testing.T, s
7070
Expect(err).NotTo(HaveOccurred())
7171

7272
Expect(filepath.Join(source, "node_modules")).ToNot(BeADirectory())
73-
73+
7474
Expect(logs).To(ContainLines(
7575
ContainSubstring("Installing node modules (pnpm-lock.yaml)"),
7676
))

src/nodejs/integration/sealights_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func testSealights(platform switchblade.Platform, fixtures string) func(*testing
103103
Expect(json.Unmarshal(content, &pkg)).To(Succeed())
104104

105105
pkg["scripts"] = map[string]string{
106-
"start": "node server.js",
106+
"start": "node server.js",
107107
"start-app": "node app.js",
108108
}
109109

@@ -134,7 +134,7 @@ func testSealights(platform switchblade.Platform, fixtures string) func(*testing
134134
WithEnv(map[string]string{"SL_BUILD_SESSION_ID": "bs1"}).
135135
WithServices(map[string]switchblade.Service{
136136
"sealights-service": {
137-
"token": "token1",
137+
"token": "token1",
138138
"npmRunScript": "start-app",
139139
},
140140
}).

src/nodejs/pnpm/pnpm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var _ = Describe("PNPM", func() {
126126

127127
Expect(buffer.String()).To(ContainSubstring("Found vendored pnpm store"))
128128
Expect(buffer.String()).To(ContainSubstring("Running pnpm in offline mode"))
129-
129+
130130
Expect(pnpmConfig).To(HaveKeyWithValue("store-dir", filepath.Join(buildDir, ".pnpm-store")))
131131
Expect(pnpmInstallArgs).To(ContainElement("--offline"))
132132
})

src/nodejs/supply/supply_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ var _ = Describe("Supply", func() {
692692
Context("pnpm version is not set", func() {
693693
It("installs latest pnpm via npm", func() {
694694
supplier.UsePNPM = true
695-
695+
696696
// Mock corepack check failure to fallback to npm
697697
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "corepack", "enable").Return(fmt.Errorf("not found"))
698698

@@ -708,7 +708,7 @@ var _ = Describe("Supply", func() {
708708
Context("pnpm version is set", func() {
709709
It("installs requested pnpm version via npm", func() {
710710
supplier.UsePNPM = true
711-
711+
712712
// Mock corepack check failure to fallback to npm
713713
mockCommand.EXPECT().Execute(buildDir, gomock.Any(), gomock.Any(), "corepack", "enable").Return(fmt.Errorf("not found"))
714714

0 commit comments

Comments
 (0)