Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions .github/workflows/jsweep.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 47 additions & 3 deletions .github/workflows/jsweep.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Daily JavaScript unbloater that cleans one .cjs file per day using modern JavaScript patterns
description: Daily JavaScript unbloater that cleans one .cjs file per day, prioritizing files with @ts-nocheck to enable type checking
on:
schedule: daily
workflow_dispatch:
Expand Down Expand Up @@ -57,14 +57,16 @@ Use cache-memory to track which files you've already cleaned. Look for:
- Files in `/home/runner/work/gh-aw/gh-aw/actions/setup/js/*.cjs`
- Exclude test files (`*.test.cjs`)
- Exclude files you've already cleaned (stored in cache-memory as `cleaned_files` array)
- Pick the **one file** with the earliest modification timestamp that hasn't been cleaned
- **Priority 1**: Pick files with `@ts-nocheck` or `// @ts-nocheck` comments (these need type checking enabled)
- **Priority 2**: If no uncleaned files with `@ts-nocheck` remain, pick the **one file** with the earliest modification timestamp that hasn't been cleaned

If no uncleaned files remain, start over with the oldest cleaned file.

### 2. Analyze the File

Before making changes to the file:
- Determine the execution context (github-script vs Node.js)
- **Check if the file has `@ts-nocheck` comment** - if so, your goal is to remove it and fix type errors
- Identify code smells: unnecessary try/catch, verbose patterns, missing modern syntax
- Check if the file has a corresponding test file
- Read the test file to understand expected behavior
Expand All @@ -73,6 +75,44 @@ Before making changes to the file:

Apply these principles to the file:

**Remove `@ts-nocheck` and Fix Type Errors (High Priority):**
```javascript
// ❌ BEFORE: Type checking disabled
// @ts-nocheck - Type checking disabled due to complex type errors requiring refactoring
/// <reference types="@actions/github-script" />

async function processData(data) {
return data.items.map(item => item.value); // Type errors ignored
}

// ✅ AFTER: Type checking enabled with proper types
// @ts-check
/// <reference types="@actions/github-script" />

/**
* Process data items
* @param {{ items: Array<{ value: string }> }} data - Input data
* @returns {Array<string>} Processed values
*/
async function processData(data) {
return data.items.map(item => item.value);
}
```

**Steps to remove `@ts-nocheck`:**
1. Remove the `@ts-nocheck` comment from the file
2. Replace it with `@ts-check` to enable type checking
3. Run `npm run typecheck` to see type errors
4. Fix type errors by:
- Adding JSDoc type annotations for functions and parameters
- Adding proper type declarations for variables
- Fixing incorrect type usage
- Adding proper null checks where needed
5. Re-run `npm run typecheck` until all errors are resolved
6. The file must pass type checking before creating the PR

Apply these principles to the file:

**Remove Unnecessary Try/Catch:**
```javascript
// ❌ BEFORE: Exception not handled with control flow
Expand Down Expand Up @@ -187,14 +227,18 @@ After cleaning the file, adding/improving tests, and verifying all tests, TypeSc

## Important Constraints

- **PRIORITIZE files with `@ts-nocheck`** - These files need type checking enabled. Remove `@ts-nocheck`, add proper type annotations, and fix all type errors.
- **DO NOT change logic** - only make the code cleaner and more maintainable
- **Always add or improve tests** - the file must have comprehensive test coverage with at least 5-10 test cases
- **Always run tests** after changes to verify they pass: `npm run test:js`
- **Always run TypeScript typecheck** before creating the PR to ensure type safety: `npm run typecheck`
- If the file had `@ts-nocheck`, it MUST pass typecheck after removing it
- **Always run prettier** to format the code consistently: `npm run format:cjs`
- **Preserve all functionality** - ensure the file works exactly as before
- **One file per run** - focus on quality over quantity
- **Document your changes** in the PR description, including test improvements
- **Document your changes** in the PR description, including:
- Whether `@ts-nocheck` was removed and type errors fixed
- Test improvements (number of tests added, coverage improvements)

## Current Repository Context

Expand Down
41 changes: 39 additions & 2 deletions pkg/workflow/jsweep_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestJSweepWorkflowConfiguration(t *testing.T) {
if strings.Contains(mdContent, "three .cjs files per day") {
t.Error("jsweep workflow should not process three files")
}
if !strings.Contains(mdContent, "Pick the **one file**") {
// Check for "one file" in either Priority 1 or Priority 2
if !strings.Contains(mdContent, "one file") {
t.Error("jsweep workflow should pick one file")
}
if strings.Contains(mdContent, "Pick the **three files**") {
Expand Down Expand Up @@ -104,7 +105,33 @@ func TestJSweepWorkflowConfiguration(t *testing.T) {
}
})

// Test 8: Verify the workflow has a valid lock file
// Test 8: Verify the workflow prioritizes files with @ts-nocheck
t.Run("PrioritizesTsNocheck", func(t *testing.T) {
if !strings.Contains(mdContent, "Priority 1") {
t.Error("jsweep workflow should have Priority 1 for file selection")
}
if !strings.Contains(mdContent, "@ts-nocheck") {
t.Error("jsweep workflow should mention @ts-nocheck")
}
if !strings.Contains(mdContent, "these need type checking enabled") {
t.Error("jsweep workflow should explain why @ts-nocheck files are prioritized")
}
})

// Test 9: Verify the workflow has instructions to remove @ts-nocheck
t.Run("RemovesTsNocheck", func(t *testing.T) {
if !strings.Contains(mdContent, "Remove `@ts-nocheck`") {
t.Error("jsweep workflow should have instructions to remove @ts-nocheck")
}
if !strings.Contains(mdContent, "Replace it with `@ts-check`") {
t.Error("jsweep workflow should instruct replacing @ts-nocheck with @ts-check")
}
if !strings.Contains(mdContent, "Fix type errors") {
t.Error("jsweep workflow should mention fixing type errors")
}
})

// Test 10: Verify the workflow has a valid lock file
t.Run("HasValidLockFile", func(t *testing.T) {
lockPath := filepath.Join("..", "..", ".github", "workflows", "jsweep.lock.yml")
_, err := os.Stat(lockPath)
Expand Down Expand Up @@ -149,4 +176,14 @@ func TestJSweepWorkflowLockFile(t *testing.T) {
t.Error("Compiled jsweep workflow should include prettier formatting")
}
})

// Test 4: Verify @ts-nocheck prioritization is in the compiled workflow
t.Run("CompiledTsNocheckPrioritization", func(t *testing.T) {
if !strings.Contains(lockContent, "Priority 1") {
t.Error("Compiled jsweep workflow should prioritize files with @ts-nocheck")
}
if !strings.Contains(lockContent, "@ts-nocheck") {
t.Error("Compiled jsweep workflow should mention @ts-nocheck")
}
})
}