Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ test/fixtures
build/
docs/
protos/
packages/
handwritten/
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"overrides": [
{
"files": ["packages/**/*.ts"],
"extends": "./node_modules/gts",
"parserOptions": {
"project": ["packages/*/tsconfig.json"]
}
}
]
}
49 changes: 49 additions & 0 deletions .github/workflows/eslint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: ESLint Check

on:
pull_request:
paths:
- 'packages/**'

permissions:
contents: read

jobs:
lint-changed:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to get all history for diffs

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install shared linting dependencies
run: |
npm install --save-dev eslint@8 gts@6.0.2 stream-json

- name: Get changed packages
id: changed-packages
run: |
# Get files changed in the PR relative to the base branch
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)

# Extract unique package names from packages/ directory
CHANGED_PACKAGES=$(echo "$CHANGED_FILES" | grep '^packages/' | cut -d/ -f2 | sort -u | tr '\n' ' ')

echo "packages=$CHANGED_PACKAGES" >> $GITHUB_OUTPUT
echo "Changed packages: $CHANGED_PACKAGES"

- name: Run ESLint on changed packages
if: steps.changed-packages.outputs.packages != ''
env:
CHANGED_PACKAGES: ${{ steps.changed-packages.outputs.packages }}
run: |
for pkg in $CHANGED_PACKAGES; do
echo "Processing package: $pkg"
node packages/run-eslint-root.mjs "$pkg" --fail-on-error
done
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/generator/gapic-generator-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"proto3-json-serializer": "^3.0.3",
"protobufjs": "^7.5.4",
"protobufjs-cli": "^1.2.0",
"prettier": "^3.2.5",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion core/generator/gapic-generator-typescript/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as fs from 'fs';
import nunjucks from 'nunjucks';
import * as path from 'path';
import * as util from 'util';
import * as prettier from 'prettier';

import type * as protos from '../../protos/index.js';

Expand Down Expand Up @@ -183,7 +184,7 @@ async function countRegionTagLines(
return {start, end};
}

function renderFile(
async function renderFile(
targetFilename: string,
templateName: string,
renderParameters: {},
Expand All @@ -206,6 +207,28 @@ function renderFile(
}
}
}

// Format generated TypeScript files using Prettier
if (targetFilename.match(/\.ts$/i)) {
try {
processed = await prettier.format(processed, {
parser: 'typescript',
filepath: targetFilename,
singleQuote: true,
trailingComma: 'all',
semi: true,
});
Comment thread
shivanee-p marked this conversation as resolved.
} catch (err) {
if (err instanceof Error) {
console.warn(
`Failed to format TypeScript file ${targetFilename}: ${err.toString()}`,
);
} else {
throw err;
}
}
}

const output =
{} as protos.google.protobuf.compiler.CodeGeneratorResponse.File;
output.name = targetFilename;
Expand Down Expand Up @@ -254,7 +277,7 @@ async function processOneTemplate(
.replace(/\$service/, service.name!.toSnakeCase());

result.push(
renderFile(pushFilename, relativeTemplateName, {
await renderFile(pushFilename, relativeTemplateName, {
method,
api,
commonParameters,
Expand All @@ -274,7 +297,7 @@ async function processOneTemplate(
continue;
}
result.push(
renderFile(
await renderFile(
outputFilename.replace(/\$service/, service.name!.toSnakeCase()),
relativeTemplateName,
{api, commonParameters, service, id},
Expand All @@ -283,7 +306,7 @@ async function processOneTemplate(
}
} else {
result.push(
renderFile(outputFilename, relativeTemplateName, {
await renderFile(outputFilename, relativeTemplateName, {
api,
commonParameters,
id,
Expand Down
Loading
Loading