Skip to content

feat: migrate generated packages to root ESLint config and ignore current violations#8067

Open
shivanee-p wants to merge 22 commits intomainfrom
shivaneep-generated-packages-linter
Open

feat: migrate generated packages to root ESLint config and ignore current violations#8067
shivanee-p wants to merge 22 commits intomainfrom
shivaneep-generated-packages-linter

Conversation

@shivanee-p
Copy link
Copy Markdown
Contributor

@shivanee-p shivanee-p commented Apr 16, 2026

This PR migrates the generated libraries in the monorepo to use a centralized ESLint configuration based on Google TypeScript Style (GTS) standards. The previous linter checks were not sufficient to maintain consistent code quality across all packages.
Addresses #7920 🦕

Key Changes

  • Centralized Configuration: Moved ESLint and TypeScript configurations to the repository root, removing package-specific .eslintrc.json files.
  • GTS Adoption: Configured ESLint to extend ./node_modules/gts, applying these rules to files in packages/ via overrides.
  • Ignore Handwritten: Explicitly ignored the handwritten/ directory in the root .eslintignore to avoid affecting those libraries in this phase.
  • Baselining: Automated the discovery of existing violations and add ESLint disable comments to affected TypeScript files to baseline the project state.
  • Generator Update: Added prettier as a dependency to gapic-generator-typescript and updated templater.ts to run Prettier on generated TypeScript files in memory before returning them to protoc
  • CI Check: Added ESLint check for changed packages whenever a PR is opened (doesn't apply to handwritten libraries for right now)

Next Steps

  1. Regenerate clients using the updated generator to verify reduction in linter violations.
  2. Update and apply the same standards to the handwritten libraries.

For Reviewers

Note: the logic changes within this PR lives in the following files:

ESLint Configuration & CI Pipeline

  • .eslintrc.json: Centralizes package tsconfig.json paths using monorepo glob patterns.
  • .github/workflows/eslint.yaml: Hardens CI permissions and prevents potential shell injections.
  • package.json: Adds stream-json for memory-efficient lint report parsing.

Automation Scripts

  • packages/run-eslint-root.mjs: Chunks monorepo directories and scopes tsconfig dynamically to prevent Out Of Memory (OOM) errors.
  • packages/baseline-from-output.mjs: Handles memory-safe JSON baselining and leverages Regular Expressions to safely merge existing eslint-disable headers.
  • packages/process-batch-root.mjs: Hardened batch processor script using execFileSync instead of execSync to eliminate Shell Injection warnings.

GAPIC Generator (gapic-generator-typescript)

  • core/generator/gapic-generator-typescript/typescript/src/templater.ts: Parallelizes file rendering using Promise.all() to prevent execution bottlenecks.
  • core/generator/gapic-generator-typescript/BUILD.bazel: Includes prettier in the Bazel build container runtime dependencies.
  • core/generator/gapic-generator-typescript/package.json: Declares prettier as a core generator dependency.

@shivanee-p shivanee-p requested a review from a team as a code owner April 16, 2026 16:08
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a baselining mechanism for ESLint violations, including a new script baseline-from-output.mjs to automate the addition of eslint-disable comments and updates to the ESLint configuration. While the goal is to manage existing linting errors across the monorepo, the review identifies several critical issues in the script's implementation. Specifically, the script is susceptible to Out-Of-Memory (OOM) errors when processing large files because it reads entire contents into memory. Furthermore, the regex-based parsing of ESLint output is unreliable, as evidenced by malformed comments in the diff that contain code snippets instead of valid rule IDs. It is highly recommended to refactor the script to use streams for file I/O and ESLint's JSON formatter for robust data extraction.

Comment thread packages/baseline-from-output.mjs Outdated
Comment thread packages/baseline-from-output.mjs Outdated
Comment thread packages/baseline-from-output.mjs Outdated
Comment thread packages/google-cloud-compute/src/v1/network_endpoint_groups_client.ts Outdated
@shivanee-p shivanee-p requested a review from quirogas April 16, 2026 16:13
@shivanee-p
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request centralizes ESLint configuration by removing individual package-level configurations and adding a root-level override in .eslintrc.json. It also introduces a baseline-from-output.mjs script designed to automate the addition of eslint-disable comments to files based on ESLint JSON output, which has been applied across numerous generated client files to suppress prettier/prettier and eol-last warnings. Feedback is provided to ensure the baselining script produces deterministic results by sorting rule IDs and to optimize the TypeScript project configuration for better performance and reliability within a monorepo structure.

Comment thread packages/baseline-from-output.mjs Outdated
Comment thread .eslintrc.json Outdated
@shivanee-p
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates Prettier formatting into the TypeScript GAPIC generator and adds a script to baseline ESLint violations across packages. The baselining script was criticized for using blocking synchronous I/O and for having fragile logic that doesn't account for shebangs or existing headers. Additionally, it was suggested to include the file path in the Prettier formatting call to improve configuration inference.

Comment thread packages/baseline-from-output.mjs Outdated
Comment thread .github/workflows/eslint.yaml Fixed
@shivanee-p shivanee-p removed the request for review from quirogas April 16, 2026 17:44
Comment thread packages/process-batch-root.mjs Fixed
Comment thread packages/process-batch-root.mjs Fixed
@shivanee-p
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces automated Prettier formatting for generated TypeScript files within the GAPIC generator and adds a utility script, baseline-from-output.mjs, to manage ESLint violations by prepending disable comments to affected files. It also refactors the ESLint configuration by moving to a centralized setup and updating tsconfig.json references. Feedback highlights performance concerns regarding sequential file rendering and formatting, suggesting parallelization with Promise.all(). Additionally, the baseline script's logic for detecting existing disable markers should be improved to handle rule updates more robustly.

Comment thread core/generator/gapic-generator-typescript/typescript/src/templater.ts Outdated
Comment thread packages/baseline-from-output.mjs Outdated
@shivanee-p
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request integrates Prettier into the GAPIC generator to automatically format generated TypeScript files and updates the templating logic to support asynchronous processing. It also introduces a utility script, baseline-from-output.mjs, to automate the addition of ESLint disable comments based on linting reports, while centralizing ESLint configurations across the repository. Feedback includes suggestions to dynamically resolve Prettier configurations, improve error logging with stack traces, and remove an unused import in the new utility script.

Comment thread packages/baseline-from-output.mjs
@quirogas quirogas self-requested a review April 22, 2026 18:07
@shivanee-p shivanee-p requested a review from pearigee April 22, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants