Skip to content

[jsweep] Clean autofix_code_scanning_alert.cjs#11321

Merged
pelikhan merged 2 commits intomainfrom
jsweep/clean-autofix-code-scanning-alert-20260122150126-62e18b51ddc46c12
Jan 22, 2026
Merged

[jsweep] Clean autofix_code_scanning_alert.cjs#11321
pelikhan merged 2 commits intomainfrom
jsweep/clean-autofix-code-scanning-alert-20260122150126-62e18b51ddc46c12

Conversation

@github-actions
Copy link
Contributor

Summary

Cleaned autofix_code_scanning_alert.cjs to use modern JavaScript patterns and reduce verbosity.

Context

This file runs in github-script context and handles creating autofixes for code scanning alerts via the GitHub REST API.

Changes Made

Code Improvements

  1. Eliminated unnecessary variable - Removed autofixItem intermediate variable, used message directly throughout for consistency
  2. Condensed return objects - Converted multiline return objects to single-line format (e.g., return { success: false, error: "..." })
  3. Used spread operator - Replaced explicit owner: context.repo.owner, repo: context.repo.repo with ...context.repo
  4. Removed unused variable - Removed result variable from github.request call since it wasn't being used
  5. Simplified headers - Converted multiline headers object to single-line format for consistency

Metrics

  • Lines before: 163
  • Lines after: 130
  • Lines saved: 33 (20% reduction)

Test Coverage

The file already had comprehensive test coverage with 15 test cases covering:

  • ✅ Valid autofix creation
  • ✅ String alert_number handling
  • ✅ Missing field validations (alert_number, fix_description, fix_code)
  • ✅ Invalid alert_number validation (invalid, zero, negative)
  • ✅ Max count enforcement
  • ✅ Staged mode collection
  • ✅ API error handling (404, 403, 422, generic errors)
  • ✅ Extensive logging validation

All tests continue to pass with the cleaned code.

Validation

All required checks passed before creating this PR:

Format: npm run format:cjs - All files formatted correctly
Lint: npm run lint:cjs - No linting issues
Type check: npm run typecheck - No type errors
Tests: npm run test:js - 15 test cases passing

Impact

  • No breaking changes - All original functionality preserved
  • Type safety maintained - File already had @ts-check enabled
  • Test coverage maintained - All 15 tests passing
  • Improved readability - More concise and consistent code style

File Context: github-script (uses core, github, context globals)
Handler Type: autofix_code_scanning_alert
Safe Output: Creates autofixes for code scanning alerts via GitHub REST API

AI generated by jsweep - JavaScript Unbloater

- Eliminated unnecessary autofixItem variable - used message directly
- Condensed multiline return objects to single-line format
- Used spread operator {...context.repo} for cleaner code
- Removed unused result variable from github.request call
- Simplified headers object formatting
- Reduced from 163 to 130 lines (33 lines saved)

All validation checks passed:
✓ Format: npm run format:cjs
✓ Lint: npm run lint:cjs
✓ Type check: npm run typecheck
✓ Tests: 15 test cases passing
@pelikhan
Copy link
Contributor

@copilot format, lint js

Copy link
Contributor

Copilot AI commented Jan 22, 2026

@pelikhan I've opened a new pull request, #11330, to work on those changes. Once the pull request is ready, I'll request review from you.

@pelikhan pelikhan merged commit a12f353 into main Jan 22, 2026
49 checks passed
@pelikhan pelikhan deleted the jsweep/clean-autofix-code-scanning-alert-20260122150126-62e18b51ddc46c12 branch January 22, 2026 15:44
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.

2 participants