Skip to content

Commit ec072a6

Browse files
authored
fix(internal/librarian/nodejs): remove Format step (#4792)
The old OwlBot pipeline never ran eslint on generated code. Removes Format to match the existing pipeline behavior and avoid diffs during migration. For #4743
1 parent 4942c12 commit ec072a6

File tree

3 files changed

+0
-127
lines changed

3 files changed

+0
-127
lines changed

internal/librarian/generate.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ func generateLibraries(ctx context.Context, cfg *config.Config, libraries []*con
204204
if err := nodejs.Generate(gctx, cfg, library, src); err != nil {
205205
return fmt.Errorf("generate library %q (%s): %w", library.Name, cfg.Language, err)
206206
}
207-
if err := nodejs.Format(gctx, library); err != nil {
208-
return fmt.Errorf("format library %q (%s): %w", library.Name, cfg.Language, err)
209-
}
210207
return nil
211208
})
212209
}

internal/librarian/nodejs/generate.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -465,35 +465,6 @@ func copySamplesFromStaging(stagingDir, outDir string) error {
465465
return nil
466466
}
467467

468-
// Format runs gts (npm run fix) on the library directory.
469-
func Format(ctx context.Context, library *config.Library) error {
470-
if err := ctx.Err(); err != nil {
471-
return err
472-
}
473-
474-
// ESLint exit codes:
475-
// 0: No issues found.
476-
// 1: Lint issues found (warnings or unfixable errors).
477-
// 2: Configuration or fatal error.
478-
//
479-
// Exit code 1 is tolerated because generated code may contain expected,
480-
// unfixable warnings (e.g., @typescript-eslint/no-explicit-any).
481-
err := command.RunInDir(ctx, library.Output, "eslint",
482-
"--fix",
483-
"--ignore-pattern", "node_modules/",
484-
"--no-error-on-unmatched-pattern",
485-
"src/**/*.ts", "src/**/*.js")
486-
487-
if err != nil {
488-
var exitErr *exec.ExitError
489-
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
490-
return nil
491-
}
492-
return fmt.Errorf("eslint failed: %w", err)
493-
}
494-
return nil
495-
}
496-
497468
// DerivePackageName returns the npm package name for a library. It uses
498469
// nodejs.package_name if set, otherwise derives it by splitting the library
499470
// name on the second dash (e.g. "google-cloud-batch" → "@google-cloud/batch").

internal/librarian/nodejs/generate_test.go

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package nodejs
1616

1717
import (
18-
"context"
1918
"encoding/json"
2019
"errors"
2120
"fmt"
@@ -535,45 +534,6 @@ func TestRunPostProcessor_CustomScripts(t *testing.T) {
535534
}
536535
}
537536

538-
func TestFormat(t *testing.T) {
539-
testhelper.RequireCommand(t, "eslint")
540-
outDir := t.TempDir()
541-
srcDir := filepath.Join(outDir, "src")
542-
if err := os.MkdirAll(srcDir, 0755); err != nil {
543-
t.Fatal(err)
544-
}
545-
eslintConfig := `{
546-
"rules": {
547-
"semi": ["error", "always"]
548-
},
549-
"parserOptions": {
550-
"ecmaVersion": 2020,
551-
"sourceType": "module"
552-
}
553-
}`
554-
if err := os.WriteFile(filepath.Join(outDir, ".eslintrc.json"), []byte(eslintConfig), 0644); err != nil {
555-
t.Fatal(err)
556-
}
557-
testFile := filepath.Join(srcDir, "index.ts")
558-
if err := os.WriteFile(testFile, []byte("export const foo = 'bar'"), 0644); err != nil {
559-
t.Fatal(err)
560-
}
561-
library := &config.Library{
562-
Name: "google-cloud-test",
563-
Output: outDir,
564-
}
565-
if err := Format(t.Context(), library); err != nil {
566-
t.Fatal(err)
567-
}
568-
got, err := os.ReadFile(testFile)
569-
if err != nil {
570-
t.Fatal(err)
571-
}
572-
if !strings.Contains(string(got), "bar';") {
573-
t.Errorf("expected fixed content with semicolon, got: %q", string(got))
574-
}
575-
}
576-
577537
func TestRunPostProcessor_PreservesFiles(t *testing.T) {
578538
testhelper.RequireCommand(t, "gapic-node-processing")
579539
testhelper.RequireCommand(t, "compileProtos")
@@ -892,61 +852,6 @@ func TestCopySamplesFromStaging_NonExistentDir(t *testing.T) {
892852
}
893853
}
894854

895-
func TestFormat_CanceledContext(t *testing.T) {
896-
ctx, cancel := context.WithCancel(t.Context())
897-
cancel()
898-
899-
library := &config.Library{
900-
Name: "google-cloud-test",
901-
Output: t.TempDir(),
902-
}
903-
err := Format(ctx, library)
904-
if err == nil {
905-
t.Fatal("expected error from canceled context, got nil")
906-
}
907-
if !errors.Is(err, context.Canceled) {
908-
t.Errorf("expected context.Canceled, got: %v", err)
909-
}
910-
}
911-
912-
func TestFormat_ExitCode1(t *testing.T) {
913-
testhelper.RequireCommand(t, "eslint")
914-
915-
outDir := t.TempDir()
916-
srcDir := filepath.Join(outDir, "src")
917-
if err := os.MkdirAll(srcDir, 0755); err != nil {
918-
t.Fatal(err)
919-
}
920-
921-
// Configure eslint with an "error" rule that cannot be auto-fixed.
922-
// eslint exits 1 when unfixable errors remain after --fix.
923-
eslintConfig := `{
924-
"rules": {
925-
"no-eval": "error"
926-
},
927-
"parserOptions": {
928-
"ecmaVersion": 2020,
929-
"sourceType": "module"
930-
}
931-
}`
932-
if err := os.WriteFile(filepath.Join(outDir, ".eslintrc.json"), []byte(eslintConfig), 0644); err != nil {
933-
t.Fatal(err)
934-
}
935-
// eval() triggers no-eval warning which --fix cannot remove.
936-
if err := os.WriteFile(filepath.Join(srcDir, "index.js"), []byte("eval('1+1');\n"), 0644); err != nil {
937-
t.Fatal(err)
938-
}
939-
940-
library := &config.Library{
941-
Name: "google-cloud-test",
942-
Output: outDir,
943-
}
944-
// Format should tolerate exit code 1 (lint warnings).
945-
if err := Format(t.Context(), library); err != nil {
946-
t.Fatal(err)
947-
}
948-
}
949-
950855
func TestGenerateAPI_NoProtos(t *testing.T) {
951856
googleapisDir := t.TempDir()
952857
repoRoot := t.TempDir()

0 commit comments

Comments
 (0)