[eslint-miner] feat(eslint): add prefer-core-logging rule#46195
[eslint-miner] feat(eslint): add prefer-core-logging rule#46195github-actions[bot] wants to merge 7 commits into
Conversation
Adds a new ESLint rule that flags console.log/error/warn/debug calls in scopes where an @actions/core alias (core / coreObj) is available. Rationale: - console.* bypasses GitHub Actions' secret masking: values passed to console.* are emitted verbatim to the workflow log, without the redaction that core.info/error/warning/debug applies. - core logging integrates with the Actions annotation system (error annotations, folded groups, etc.) while console.* does not. - The pattern appears in 5 locations in actions/setup/js, e.g. generate_workflow_overview.cjs:38 and merge_remote_agent_github_folder.cjs. Rule details: - Only flags when a CORE_ALIASES binding (core / coreObj) is in scope, preventing false positives in plain scripts that don't use @actions/core. - Covers: console.log → core.info, console.error → core.error, console.warn → core.warning, console.debug → core.debug, console.info → core.info. - Provides an auto-fix suggestion for each violation. - 11 unit tests (all passing). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copiliot always favor using core.... since we have a shim.cjs file to also support node.js context. |
|
@copilot always favor using core.... since we have a shim.cjs file to also support node.js context. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…n setup/js The shim.cjs provides global.core in all Node.js contexts, so console.* should never be used — remove hasCoreInScope() scope restriction from the rule and fix all console.* calls in the files mentioned in the PR. Changes: - prefer-core-logging.ts: remove hasCoreInScope() function and check; flag all console.* calls unconditionally; update description/suggestion message to reflect global.core availability via shim.cjs - prefer-core-logging.test.ts: update formerly-valid cases to expect errors; add suggestions to new invalid test cases (11 tests still pass) - generate_workflow_overview.cjs: console.log → core.info (core is a param) - generate_usage_activity_summary.cjs: require shim.cjs + console.log → core.info - merge_remote_agent_github_folder.cjs: require shim.cjs; remove local coreObj fallback that used console.*; replace all coreObj.* → core.* Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in commit
|
🤖 PR Triage
Adds new ESLint miner rule Batch:
|
There was a problem hiding this comment.
Pull request overview
Adds an ESLint rule promoting @actions/core logging in setup scripts.
Changes:
- Implements and registers
prefer-core-loggingwith tests. - Migrates several scripts from console logging to core logging.
- Regenerates the auto-upgrade schedule.
Show a summary per file
| File | Description |
|---|---|
eslint-factory/src/rules/prefer-core-logging.ts |
Implements detection and suggestions. |
eslint-factory/src/rules/prefer-core-logging.test.ts |
Tests rule behavior. |
eslint-factory/src/index.ts |
Registers the rule. |
eslint-factory/eslint.config.cjs |
Enables the rule as a warning. |
actions/setup/js/merge_remote_agent_github_folder.cjs |
Uses shim-backed core logging. |
actions/setup/js/generate_workflow_overview.cjs |
Replaces console logging with core.info. |
actions/setup/js/generate_usage_activity_summary.cjs |
Uses shim-backed core.info. |
.github/workflows/agentic-auto-upgrade.yml |
Updates the generated weekly schedule. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
eslint-factory/src/rules/prefer-core-logging.ts:69
- This replacement does not preserve multi-argument console calls.
@actions/corelogging methods consume one message, soconsole.log("value:", someVar)becomescore.info("value:", someVar)and silently dropssomeVar. Do not offer the suggestion when there is not exactly one argument (or explicitly combine the arguments into one equivalent message).
return fixer.replaceText(node, `${replacement}(${argsText})`);
eslint-factory/src/rules/prefer-core-logging.ts:42
- The diagnostic repeats the incorrect assertion that
console.*output is not masked. Masking is runner-wide aftersetSecret/add-mask, regardless of whether output comes fromconsoleor@actions/core; please avoid presenting this rule as a secret-masking boundary.
preferCoreLogging: "Use {{replacement}} instead of console.{{method}}() — @actions/core logging masks secrets and integrates with the Actions annotation system. console.* output is not masked.",
- Files reviewed: 8/8 changed files
- Comments generated: 2
- Review effort level: Medium
| CallExpression(node) { | ||
| const method = getConsoleMethod(node); | ||
| if (!method) return; | ||
|
|
||
| const replacement = CONSOLE_TO_CORE[method]!; |
There was a problem hiding this comment.
The unconditional core replacement is intentional by design per the maintainer's direction. shim.cjs (required at the top of every setup/js script) registers global.core in all Node.js contexts, so core.* is always in scope regardless of whether the script explicitly imports @actions/core. There is no plain-script context where this replacement would throw. For coreObj aliases — those were an intermediate workaround that has been cleaned up; the codebase now uses core.* everywhere directly via shim.cjs.
| description: | ||
| "Prefer @actions/core logging methods (core.info, core.error, core.warning, core.debug) over console.* — " + | ||
| "global.core is always available via shim.cjs in Node.js context and via github-script in Actions context. " + | ||
| "console.* bypasses GitHub Actions' built-in secret masking and structured annotation system; core logging ensures secrets in output are redacted and messages appear correctly in the Actions UI.", |
There was a problem hiding this comment.
Fixed in commit fix(eslint): correct misleading security claim. Removed the claim that core.info masks secrets — updated both the docs.description and the preferCoreLogging message to focus on the correct rationale: core.* integrates with the Actions annotation system (errors/warnings surface as file annotations) and produces structured log output, while global.core is always available via shim.cjs.
|
@copilot resolve the merge conflicts on this branch. |
…ore-logging-677bf81819ff7157 # Conflicts: # actions/setup/js/generate_usage_activity_summary.cjs # actions/setup/js/merge_remote_agent_github_folder.cjs Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Resolved in the merge commit |
…instead of console.log Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Fixed in commit |
|
@copilot please run the
|
… rule docs Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Summary
Adds a new ESLint rule
prefer-core-loggingthat flagsconsole.*calls in scopes where an@actions/corealias (core/coreObj) is available.Rationale
console.*in GitHub Actions bypasses the runtime's built-in secret masking — values are emitted verbatim to the workflow log without redaction.core.info/core.error/core.warning/core.debugapply masking and integrate with the Actions annotation system.This pattern was observed in
actions/setup/jsacross multiple files:generate_workflow_overview.cjsconsole.log("Generated workflow overview...")generate_usage_activity_summary.cjsconsole.log/warn/errorin core-aware scopemerge_frontmatter_models.cjsconsole.login core-aware scopemerge_remote_agent_github_folder.cjsconsole.log/warn/erroradapter wrapping coreRule details
gh-aw-custom/prefer-core-loggingwarnCORE_ALIASESbinding (core/coreObj) is demonstrably in scope — no false positives on plain scripts without@actions/core.console.log/info → core.info,console.error → core.error,console.warn → core.warning,console.debug → core.debugValidation
Files changed
eslint-factory/src/rules/prefer-core-logging.ts— rule implementationeslint-factory/src/rules/prefer-core-logging.test.ts— 11 unit testseslint-factory/src/index.ts— rule registrationeslint-factory/eslint.config.cjs— rule enabled atwarn