Skip to content

fix: add node: protocol prefix to built-in module imports#64

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260515-050326-ff55671b
Open

fix: add node: protocol prefix to built-in module imports#64
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260515-050326-ff55671b

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Add the node: protocol prefix to built-in Node.js module imports across the codebase to comply with SonarQube best practices. This clarifies that imports refer to core Node.js modules rather than third-party packages, enhances security against package name confusion attacks, and aligns with modern Node.js ESM standards.

View Project in SonarCloud


Fixed Issues

typescript:S7772 - Prefer `node:os` over `os`. • MINORView issue

Location: src/credential-guard-post.ts:3

Why is this an issue?

When importing Node.js built-in modules, using the node: protocol makes it explicitly clear that you’re importing a core Node.js module rather than a third-party package from npm.

What changed

This hunk adds the node: protocol prefix to three Node.js built-in module imports in src/credential-guard-post.ts. It changes 'fs/promises' to 'node:fs/promises', 'os' to 'node:os', and 'path' to 'node:path'. This directly fixes all three static analysis warnings about preferring the node: protocol for built-in module imports, which improves clarity about whether imports refer to core Node.js modules versus third-party npm packages, enhances security against potential package name confusion attacks, and aligns with Node.js best practices.

--- a/src/credential-guard-post.ts
+++ b/src/credential-guard-post.ts
@@ -2,3 +2,3 @@ import * as core from '@actions/core';
-import * as fs from 'fs/promises';
-import * as os from 'os';
-import * as path from 'path';
+import * as fs from 'node:fs/promises';
+import * as os from 'node:os';
+import * as path from 'node:path';
typescript:S7772 - Prefer `node:path` over `path`. • MINORView issue

Location: src/credential-guard-post.ts:4

Why is this an issue?

When importing Node.js built-in modules, using the node: protocol makes it explicitly clear that you’re importing a core Node.js module rather than a third-party package from npm.

What changed

This hunk adds the node: protocol prefix to three Node.js built-in module imports in src/credential-guard-post.ts. It changes 'fs/promises' to 'node:fs/promises', 'os' to 'node:os', and 'path' to 'node:path'. This directly fixes all three static analysis warnings about preferring the node: protocol for built-in module imports, which improves clarity about whether imports refer to core Node.js modules versus third-party npm packages, enhances security against potential package name confusion attacks, and aligns with Node.js best practices.

--- a/src/credential-guard-post.ts
+++ b/src/credential-guard-post.ts
@@ -2,3 +2,3 @@ import * as core from '@actions/core';
-import * as fs from 'fs/promises';
-import * as os from 'os';
-import * as path from 'path';
+import * as fs from 'node:fs/promises';
+import * as os from 'node:os';
+import * as path from 'node:path';
typescript:S7772 - Prefer `node:fs/promises` over `fs/promises`. • MINORView issue

Location: __tests__/credential-guard.test.ts:2

Why is this an issue?

When importing Node.js built-in modules, using the node: protocol makes it explicitly clear that you’re importing a core Node.js module rather than a third-party package from npm.

What changed

This hunk changes the import of 'fs/promises' to 'node:fs/promises', adding the 'node:' protocol prefix to the Node.js built-in module import. This makes it explicitly clear that the import refers to a core Node.js module rather than a third-party package, following Node.js best practices for ESM imports and eliminating ambiguity about the module's origin.

--- a/__tests__/credential-guard.test.ts
+++ b/__tests__/credential-guard.test.ts
@@ -2,1 +2,1 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
-import * as fs from 'fs/promises';
+import * as fs from 'node:fs/promises';
typescript:S7772 - Prefer `node:fs/promises` over `fs/promises`. • MINORView issue

Location: src/credential-guard-post.ts:2

Why is this an issue?

When importing Node.js built-in modules, using the node: protocol makes it explicitly clear that you’re importing a core Node.js module rather than a third-party package from npm.

What changed

This hunk adds the node: protocol prefix to three Node.js built-in module imports in src/credential-guard-post.ts. It changes 'fs/promises' to 'node:fs/promises', 'os' to 'node:os', and 'path' to 'node:path'. This directly fixes all three static analysis warnings about preferring the node: protocol for built-in module imports, which improves clarity about whether imports refer to core Node.js modules versus third-party npm packages, enhances security against potential package name confusion attacks, and aligns with Node.js best practices.

--- a/src/credential-guard-post.ts
+++ b/src/credential-guard-post.ts
@@ -2,3 +2,3 @@ import * as core from '@actions/core';
-import * as fs from 'fs/promises';
-import * as os from 'os';
-import * as path from 'path';
+import * as fs from 'node:fs/promises';
+import * as os from 'node:os';
+import * as path from 'node:path';

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZzYE2GUPf0LcAuwqQVK for typescript:S7772 rule
- AZzYE2GsPf0LcAuwqQVX for typescript:S7772 rule
- AZzYE2GsPf0LcAuwqQVY for typescript:S7772 rule
- AZzYE2GsPf0LcAuwqQVZ for typescript:S7772 rule

Generated by SonarQube Agent (task: 9cca4bbd-d888-4489-8626-d559469d0184)
@sonar-review-alpha
Copy link
Copy Markdown

sonar-review-alpha Bot commented May 15, 2026

Summary

⚠️ The PR description exceeded the analysis limit and was truncated. The review may not reflect all context.

This PR adds the node: protocol prefix to 4 built-in Node.js module imports that were flagged by SonarQube's S7772 rule:

  • 3 imports in src/credential-guard-post.ts (fs/promises, os, path)
  • 1 import in __tests__/credential-guard.test.ts (fs/promises)

The changes are purely mechanical — prefixing imports with node: to explicitly identify core Node.js modules. This improves code clarity and security against package name confusion attacks. No functional changes or behavior modifications.

What reviewers should know

What to check:

  • All flagged imports received the prefix (compare the diff against the 4 SonarQube issues listed in the description)
  • No other imports were modified
  • The path and os imports in the test file remain unprefixed — confirm these weren't flagged by SonarQube (they appear to be outside the analysis scope)

No surprises here — this is a straightforward linting fix with zero risk of introducing bugs or behavior changes.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

@sonarqube-cloud-us
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha Bot left a comment

Choose a reason for hiding this comment

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

Clean, low-risk linting fix. No logic changes, no test-mocking issues (fs is used directly in tests for real file I/O, not mocked), and node: prefix carries identical runtime semantics in any Node.js version the GitHub Actions runner supplies.

Two observations worth knowing:

  • src/credential-setup.ts has the same three bare built-in imports (fs/promises, os, path) and was not updated. That file is not part of this PR's scope, but it will continue to generate S7772 findings unless addressed separately.
  • The bundled dist files in credential-guard/dist/post/ are committed to the repo but were not rebuilt as part of this PR. Since node:fs/promises and fs/promises resolve identically at runtime, this has zero functional impact — but the source and dist are now technically out of sync until the next build.

🗣️ Give feedback

Comment on lines 3 to 4
import * as path from 'path';
import * as os from 'os';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lines 2 and 3–4 are now inconsistent within the same file: fs/promises was updated to node:fs/promises by this PR, but path and os still use the bare form. SonarQube only flagged line 2 here, but leaving the file half-migrated makes the intent unclear to future readers.

Suggested change
import * as path from 'path';
import * as os from 'os';
import * as path from 'node:path';
import * as os from 'node:os';
  • Mark as noise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant