Repository navigation
feat: add PowerShell license header support - #285
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new PowerShell workflow lacks regression coverage across style lookup, generation, insertion, and normalization.
1 open finding
What changed in this PR
Adds PowerShell license-header checking and fixing support.
Changes:
- Defines PowerShell
<# ... #>header formatting. - Maps PowerShell files to the new style.
- Normalizes PowerShell block-comment delimiters.
| File | Description |
|---|---|
pkg/license/norm.go |
Recognizes PowerShell comment delimiters. |
assets/styles.yaml |
Defines the PowerShell header style. |
assets/languages.yaml |
Enables the style for PowerShell files. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
[P2] Preserve PowerShell file encoding when enabling header fixes The new mapping at assets/languages.yaml:4310 enables This affects I verified the following reproduction against go build -o /tmp/skywalking-eyes-pr285-license-eye ./cmd/license-eye
python3 - <<'PY'
from pathlib import Path
from tempfile import TemporaryDirectory
import subprocess
with TemporaryDirectory() as tmp:
root = Path(tmp)
script = root / "test.ps1"
script.write_bytes(b"\xff\xfe" + "Write-Host 'Hello'\n".encode("utf-16le"))
(root / ".licenserc.yaml").write_text(
"header:\n"
" license:\n"
" content: Apache License 2.0\n"
" paths:\n"
" - test.ps1\n",
encoding="utf-8",
)
binary = "/tmp/skywalking-eyes-pr285-license-eye"
print("BOM offset before fix:", script.read_bytes().find(b"\xff\xfe"), flush=True)
subprocess.run([binary, "header", "fix"], cwd=root, check=True)
data = script.read_bytes()
print("BOM offset after fix:", data.find(b"\xff\xfe"), flush=True)
print("First 29 bytes after fix:", repr(data[:29]), flush=True)
subprocess.run([binary, "-v", "debug", "header", "check"], cwd=root, check=True)
PYRelevant output: Expected: preserve the file's encoding and keep its BOM at byte 0, or reject the unsupported encoding before writing. Please add a UTF-16LE/BOM regression case alongside the UTF-8 tests. The existing suites pass: |
- add a PowerShellStyle using <# ... #> block comments - preserve BOM encodings (UTF-8, UTF-16LE/BE) in header check, diff and fix
linghengqian
left a comment
There was a problem hiding this comment.
- It looks like the ASF runner queue is full again, just like before. We'll likely have to wait until tomorrow to see the CI results.
|
The original UTF-16 reproduction now passes on [P2] Detect UTF-32LE before matching the UTF-16LE BOM There is still an encoding corruption case in pkg/header/encoding.go:50-52. A UTF-32LE BOM is Verified reproduction against go build -o /tmp/skywalking-eyes-pr285-04a53f1-license-eye ./cmd/license-eye
python3 - <<'PY'
from pathlib import Path
from tempfile import TemporaryDirectory
import subprocess
with TemporaryDirectory() as tmp:
root = Path(tmp)
script = root / "test.ps1"
script.write_bytes(b"\xff\xfe\x00\x00" + "Write-Host 'Hello'\n".encode("utf-32le"))
(root / ".licenserc.yaml").write_text(
"header:\n"
" license:\n"
" content: Apache License 2.0\n"
" comment: never\n"
" paths:\n"
" - test.ps1\n",
encoding="utf-8",
)
binary = "/tmp/skywalking-eyes-pr285-04a53f1-license-eye"
print("Original prefix:", script.read_bytes()[:4].hex(" "), flush=True)
print("Original text:", repr(script.read_bytes().decode("utf-32")), flush=True)
subprocess.run([binary, "header", "fix"], cwd=root, check=True)
data = script.read_bytes()
print("After-fix prefix:", data[:4].hex(" "), flush=True)
try:
print("Decoded as UTF-32:", repr(data.decode("utf-32")), flush=True)
except UnicodeDecodeError as error:
print("UTF-32 decoding failed:", error, flush=True)
print("Decoded as UTF-16:", repr(data.decode("utf-16")), flush=True)
subprocess.run([binary, "header", "check"], cwd=root, check=True)
PYRelevant output: Please detect the four-byte UTF-32 BOM before the UTF-16 prefixes and either preserve its encoding or reject/skip it without modifying the file. Full UTF-32 support is not required to avoid this corruption. A regression fixture should verify that an unsupported encoding is left untouched. Validation otherwise passed: |
linghengqian
left a comment
There was a problem hiding this comment.
- It seems there's nothing left for me to do?
CheckFile now logs a warning and marks a file it cannot decode (e.g. UTF-32) as invalid, so the rest of the check, fix and diff still run. Fixing such a file is still rejected by InsertComment without touching it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qcqgfw4N7r3bzX86dXrWxD
Yes. I did update for the nits. Will merge after CI passed. |
|
Final behavior as of 40de3cd. On top of the UTF-32 fix, I pushed two more commits: an undecodable file is now reported per file instead of stopping the whole run, and PowerShell
Encoding handling in
The UTF-32 BOM is matched before the UTF-16 BOMs, so Behavior changes compared with
Verification on 40de3cd
|
The UTF-16 decoder replaces an odd trailing byte or an unpaired surrogate with U+FFFD instead of failing, so fixing such a file silently changed bytes outside the license header. InsertComment now requires the decoded content to round-trip back to the original bytes, and otherwise returns a per-file error without writing. Check and diff keep the lenient decoding, so a malformed file that already has a header still passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qcqgfw4N7r3bzX86dXrWxD
linghengqian
left a comment
There was a problem hiding this comment.
- It looks like the GitHub milestone for
0.9.0is incorrect? After all, the0.9.0version has already been released.

apache/skywalking-eyesversion-fox/vfox-flutter#41 thatapache/skywalking-eyesdoes not support checks for PowerShell 7. Adding support for it would obviously be a good thing.