X Tutup
Skip to content

Improve ergonomics of setModuleDefaults/Load.scan()#903

Open
jdmarshall wants to merge 1 commit intonode-config:masterfrom
jdmarshall:scanReturn
Open

Improve ergonomics of setModuleDefaults/Load.scan()#903
jdmarshall wants to merge 1 commit intonode-config:masterfrom
jdmarshall:scanReturn

Conversation

@jdmarshall
Copy link
Collaborator

@jdmarshall jdmarshall commented Mar 9, 2026

Fixes #901

This should simplify the setup code for moduleDefaults, which I'll update in the docs.

let load = new Load({...});
config.util.setModuleDefaults("myModule", load.scan());

Summary by CodeRabbit

  • New Features

    • Configuration loading method now returns the resolved configuration object, enabling direct access to configuration data after processing.
  • Tests

    • Added test coverage to verify correct return of resolved configuration data.

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

The Load.scan(additional) method now returns the resolved configuration object (this.config) after performing file loading, environment overrides, and deferred resolution. A test was added to assert that scan() returns the config when skipConfigSources is true.

Changes

Cohort / File(s) Summary
Core Utility Update
lib/util.js
Added return this.config to Load.scan(additional) and updated JSDoc to @returns {object}. No other control-flow changes.
Test Coverage
test/0-util.js
Added test asserting that scan() returns load.config when skipConfigSources is true.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hopped through files and found the trick,
Load.scan now hands back what we pick,
No void, just config, neat and spry,
A rabbit's clap — a happy cry! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: improving ergonomics of Load.scan() by making it return a value, enabling more direct usage with setModuleDefaults.
Linked Issues check ✅ Passed The PR fully addresses issue #901 by implementing Load.scan() to return the config object, enabling ergonomic direct usage with setModuleDefaults as requested.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue: modifying Load.scan() return behavior and adding corresponding test coverage, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@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 (1)
test/0-util.js (1)

1715-1721: Consider using assert.strictEqual for consistency.

The test correctly validates the new return behavior. However, the rest of this file uses assert.strictEqual for comparisons. For consistency, consider using assert.strictEqual here as well.

Suggested fix
     it('returns the resolved data', function() {
       let load = new Load({configDir: import.meta.dirname + '/config', skipConfigSources: true});
       let actual = load.scan();
 
-      assert.equal(actual, load.config);
+      assert.strictEqual(actual, load.config);
     });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/0-util.js` around lines 1715 - 1721, Replace the non-strict assertion in
the test that verifies Load.scan() by changing the call to assert.equal(actual,
load.config) to use assert.strictEqual(actual, load.config) so it matches the
rest of the file’s assertions; locate the test that constructs new
Load({configDir: import.meta.dirname + '/config', skipConfigSources: true}),
calls load.scan(), and assigns to actual, then update the assertion to
strictEqual (no other changes required).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/0-util.js`:
- Around line 1715-1721: Replace the non-strict assertion in the test that
verifies Load.scan() by changing the call to assert.equal(actual, load.config)
to use assert.strictEqual(actual, load.config) so it matches the rest of the
file’s assertions; locate the test that constructs new Load({configDir:
import.meta.dirname + '/config', skipConfigSources: true}), calls load.scan(),
and assigns to actual, then update the assertion to strictEqual (no other
changes required).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 63ae5fba-d468-4e90-b6c2-1c814ea4ede7

📥 Commits

Reviewing files that changed from the base of the PR and between b0c9c9d and 6b3a18f.

📒 Files selected for processing (2)
  • lib/util.js
  • test/0-util.js

Copy link

@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 (1)
lib/util.js (1)

1098-1100: Minor: JSDoc @see reference may be incorrect.

The @see tag references ConfigUtils.setModuleDefaults(), but the utility class in this file is named Util, and the method exists on Load.setModuleDefaults() at line 1243. Consider updating to reference the correct class/method, such as @see Load.setModuleDefaults() or @see config.util.setModuleDefaults().

Suggested fix
   * scan and load config files in the same manner that config.js does
   *
-   * `@see` ConfigUtils.setModuleDefaults()
+   * `@see` Load.setModuleDefaults()
   * `@param` {{name: string, config: any}[]=} additional additional values to populate (usually from NODE_CONFIG)
   * `@returns` {object} - config data
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/util.js` around lines 1098 - 1100, JSDoc `@see` references the wrong
symbol; update the tag in the comment above the function to point to the actual
utility method name—change `@see ConfigUtils.setModuleDefaults()` to the correct
reference `@see Load.setModuleDefaults()` (or `@see
config.util.setModuleDefaults()` if you prefer the external API name) so it
matches the real method defined as Load.setModuleDefaults.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/util.js`:
- Around line 1098-1100: JSDoc `@see` references the wrong symbol; update the tag
in the comment above the function to point to the actual utility method
name—change `@see ConfigUtils.setModuleDefaults()` to the correct reference
`@see Load.setModuleDefaults()` (or `@see config.util.setModuleDefaults()` if
you prefer the external API name) so it matches the real method defined as
Load.setModuleDefaults.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a959445-622e-496f-9007-362eebe5bbc9

📥 Commits

Reviewing files that changed from the base of the PR and between 6b3a18f and 1d22819.

📒 Files selected for processing (2)
  • lib/util.js
  • test/0-util.js

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.

Load.scan() should not be a void method

1 participant

X Tutup