Skip to content

CI: add Lint Check step to build in Build, Test and Publish Action#354

Open
Carbonautics wants to merge 3 commits intoopenfga:mainfrom
Carbonautics:ci/issue/275
Open

CI: add Lint Check step to build in Build, Test and Publish Action#354
Carbonautics wants to merge 3 commits intoopenfga:mainfrom
Carbonautics:ci/issue/275

Conversation

@Carbonautics
Copy link
Copy Markdown

@Carbonautics Carbonautics commented Mar 17, 2026

Description

What problem is being solved?

  • Adds lint check to the build step in Github Actions and fails the build if lint check fails.
  • Also fix any lint or formatting issues using lint:fix script.

How is it being solved?

  • Use the npm run lint script after installing dependencies using npm ci but before actually creating a build.
  • Use the npm run lint:fix locally and push all fixes to any required files.

What changes are made to solve it?

  • Updated the .github/workflows/main.yaml file to include the lint check command.
  • Few files are updated with mostly formatting changes when running the npm run lint:fix, since there were 400+ errors which would fail everytime, if we added this lint check to the build without fixing those lint/formatting errors first.

References

closes #275

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Chores
    • Updated CI/CD pipeline to include code linting in the build process
    • Reorganized test structure and cleanup procedures for improved consistency

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Mar 17, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 17, 2026

Walkthrough

This PR adds a lint check to the CI/CD pipeline and reorganizes test infrastructure. The build job now executes npm run lint after dependency installation. Test files are restructured with reorganized Mocha hooks without changing test semantics or behavior.

Changes

Cohort / File(s) Summary
CI/CD Workflow
.github/workflows/main.yaml
Added npm run lint step in the build job after npm ci to enforce linting checks in the CI pipeline.
Test Infrastructure
tests/apiExecutor.test.ts, tests/setup.ts
Reorganized test file structure and Mocha hooks; moved afterEach/afterAll cleanup to top-level describe block and re-indented entire test file for consistency. No test logic or assertions were modified.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • chore: improve api executor flow #345: Modifies the same test surface (OpenFgaClient.executeApiRequest tests) for implementing and renaming the executeApiRequest method, creating a direct code-level dependency with this PR's test reorganization.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR contains formatting changes to test files (indentation, hook placement) that are unrelated to the linked issue objective of adding lint checks to CI. Remove test file reformatting changes in tests/apiExecutor.test.ts and tests/setup.ts; focus only on the .github/workflows/main.yaml lint step addition.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a lint check step to the CI/CD build pipeline.
Linked Issues check ✅ Passed The PR successfully implements the primary objective from issue #275: adding npm lint execution to CI that fails the build on lint errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.80%. Comparing base (dbbfcda) to head (dd48253).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #354   +/-   ##
=======================================
  Coverage   85.80%   85.80%           
=======================================
  Files          26       26           
  Lines        1268     1268           
  Branches      225      225           
=======================================
  Hits         1088     1088           
  Misses        110      110           
  Partials       70       70           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Carbonautics Carbonautics marked this pull request as ready for review March 19, 2026 11:49
@Carbonautics Carbonautics requested a review from a team as a code owner March 19, 2026 11:49
Copilot AI review requested due to automatic review settings March 19, 2026 11:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #275 by ensuring linting is executed during CI so builds fail when ESLint reports errors, helping keep the TypeScript SDK codebase consistent and lint-clean.

Changes:

  • Add a npm run lint step to the GitHub Actions build job before npm run build.
  • Reformat Jest test files to comply with the repository’s ESLint formatting rules.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/main.yaml Runs ESLint in CI prior to building so lint errors fail the workflow.
tests/setup.ts Formatting-only change to satisfy lint rules.
tests/apiExecutor.test.ts Formatting-only change (large diff) to satisfy lint rules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +129 to +131
// If we get here without error, the Content-Type header was correctly applied
expect(true).toBe(true);
});
Comment on lines 36 to +41

- name: Install dependencies
run: npm ci

- name: Lint Check
run: npm run lint
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
.github/workflows/main.yaml (1)

19-21: Run lint once instead of once per matrix entry to cut CI time.

This currently runs the same lint pass 4x. Consider gating lint to one Node version while keeping npm run build on the full matrix.

♻️ Suggested adjustment
       - name: Lint Check
+        if: matrix.node-version == env.TARGET_NODE_VERSION
         run: npm run lint

Also applies to: 40-41

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/main.yaml around lines 19 - 21, The workflow currently
runs the same lint step for every entry in strategy.matrix; update the YAML so
lint runs just once by removing the matrix from the lint job (or adding a
conditional like if: github.matrix.node-version == '22.x') and keep the
build/test job under strategy.matrix for full matrix coverage; locate the
strategy.matrix block and the jobs named "lint" and "build" (or equivalent job
IDs) and either move lint out as a standalone job without a matrix or add an
if-gate tied to a single node-version to ensure lint runs only once while builds
still run across all node-version entries.
tests/apiExecutor.test.ts (1)

19-32: Consider extracting duplicated Nock hook setup into a helper.

Both suites define the same lifecycle hooks; a small helper would reduce drift and keep this easier to maintain.

♻️ Possible refactor
+const registerNockLifecycleHooks = () => {
+  beforeAll(() => {
+    nock.restore();
+    nock.cleanAll();
+    nock.activate();
+    nock.disableNetConnect();
+  });
+
+  afterEach(() => {
+    nock.cleanAll();
+  });
+
+  afterAll(() => {
+    nock.restore();
+  });
+};
+
 describe("OpenFgaClient.executeApiRequest", () => {
+  registerNockLifecycleHooks();
   const basePath = defaultConfiguration.getBasePath();
   ...
-  beforeAll(() => { ... });
-  afterEach(() => { ... });
-  afterAll(() => { ... });
 });
 
 describe("OpenFgaClient.executeApiRequest - path parameters", () => {
+  registerNockLifecycleHooks();
   const basePath = defaultConfiguration.getBasePath();
   ...
-  beforeAll(() => { ... });
-  afterEach(() => { ... });
-  afterAll(() => { ... });
 });

Also applies to: 340-353

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/apiExecutor.test.ts` around lines 19 - 32, Duplicate Nock lifecycle
hook setup in tests/apiExecutor.test.ts (the beforeAll/afterEach/afterAll blocks
that call nock.restore(), nock.cleanAll(), nock.activate(),
nock.disableNetConnect()) should be extracted into a shared helper; create a
function (e.g., setupNockLifecycle or useNockHooks) that registers the same
beforeAll, afterEach, and afterAll behavior and call that helper from each test
suite instead of repeating the hooks—update references in the suites to invoke
the helper and remove the duplicated hook blocks so both suites use the single
shared setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/main.yaml:
- Around line 19-21: The workflow currently runs the same lint step for every
entry in strategy.matrix; update the YAML so lint runs just once by removing the
matrix from the lint job (or adding a conditional like if:
github.matrix.node-version == '22.x') and keep the build/test job under
strategy.matrix for full matrix coverage; locate the strategy.matrix block and
the jobs named "lint" and "build" (or equivalent job IDs) and either move lint
out as a standalone job without a matrix or add an if-gate tied to a single
node-version to ensure lint runs only once while builds still run across all
node-version entries.

In `@tests/apiExecutor.test.ts`:
- Around line 19-32: Duplicate Nock lifecycle hook setup in
tests/apiExecutor.test.ts (the beforeAll/afterEach/afterAll blocks that call
nock.restore(), nock.cleanAll(), nock.activate(), nock.disableNetConnect())
should be extracted into a shared helper; create a function (e.g.,
setupNockLifecycle or useNockHooks) that registers the same beforeAll,
afterEach, and afterAll behavior and call that helper from each test suite
instead of repeating the hooks—update references in the suites to invoke the
helper and remove the duplicated hook blocks so both suites use the single
shared setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5630d977-c4e8-4413-8ec5-018bc69234ea

📥 Commits

Reviewing files that changed from the base of the PR and between dbbfcda and 725a1d8.

📒 Files selected for processing (3)
  • .github/workflows/main.yaml
  • tests/apiExecutor.test.ts
  • tests/setup.ts

@Carbonautics Carbonautics requested a review from Copilot March 19, 2026 11:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an ESLint linting gate to the CI build workflow so builds fail on lint errors, and applies lint/format fixes across the codebase (as reflected in updated test files).

Changes:

  • Add a npm run lint step to the GitHub Actions build job before npm run build.
  • Apply lint-driven formatting updates in tests (indentation/style consistency).

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.

File Description
.github/workflows/main.yaml Runs npm run lint in CI prior to building to fail fast on lint errors.
tests/setup.ts Formatting-only change aligning with lint rules.
tests/apiExecutor.test.ts Formatting-only changes aligning with lint rules (no functional test logic changes intended).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- name: Install dependencies
run: npm ci

- name: Lint Check
Comment on lines +129 to +130
// If we get here without error, the Content-Type header was correctly applied
expect(true).toBe(true);
Comment on lines +150 to +151
// If we get here without error, the Accept header was correctly applied
expect(true).toBe(true);
Comment on lines +232 to +233
// If we get here without error, the custom header was correctly applied
expect(true).toBe(true);
Comment on lines +258 to +259
// If we get here without error, the custom header was correctly applied
expect(true).toBe(true);
}
);

expect(true).toBe(true);
@SoulPancake SoulPancake self-assigned this Mar 25, 2026
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.

Add lint checks to CI/CD pipeline

4 participants