-
Notifications
You must be signed in to change notification settings - Fork 303
Introduce leftism in overhauling copyright :) #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Refactor to not use regexes for simple search Refactor use a fast comprehension (see https://stackoverflow.com/questions/44802682/python-any-unexpected-performance) Search for "copyleft" at the same time Update relevant tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes issue #64 by updating the copyright checker to accept "copyleft" in addition to "copyright" as valid license indicators in source files. The change allows more flexibility in recognizing open-source license headers.
Key changes:
- Modified copyright detection logic to recognize both "copyright" and "copyleft" keywords (case-insensitive)
- Added test case to verify copyleft detection works correctly
- Updated sample test files to reflect the reduced error count after adding a copyleft header
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cpplint.py | Updated CheckForCopyright function to accept "copyleft" as valid in addition to "copyright" |
| cpplint_unittest.py | Added test case for copyleft detection and simplified list comprehensions in existing tests |
| samples/silly-sample/src/sillycode.w | Added copyleft header comment to demonstrate the fix |
| samples/silly-sample/simple.def | Updated expected error count and removed copyright error for sillycode.w |
| samples/silly-sample/cfg.def | Updated expected error count and removed copyright error for sillycode.w |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Walkthroughcpplint.py simplifies copyright header detection by replacing the for/else loop with an any()-based check that scans lines 1–10 for either "copyright" or "copyleft" (case-insensitive). Tests and sample files updated to reflect the detection change. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (2)
samples/silly-sample/src/sillycode.w (1)
1-6: Fix Copyleft sample comment to avoid extra whitespace warning and match real headersThe
//#copyleft4prez2025…line both:
- Triggers an extra
whitespace/commentswarning (no space after//), which is whycpplint_clitest silly-simpleis now seeing an extra error; and- Uses a very non‑standard Copyleft format.
To keep this file as the Copyleft acceptance sample but avoid changing the whitespace counts, I’d suggest something like:
-//#copyleft4prez2025 super copy paste go +// Copyleft 2025 Example Corp. All rights reserved.This still exercises the new Copyleft support, removes the unexpected whitespace warning on line 1 (so only line 3 is flagged), and brings cfg.def/simple.def totals back in sync with actual output.
cpplint.py (1)
2440-2442: Semantics look correct, but theany(True for ...)pattern is non‑idiomatic and redundantFunctionally this change does what the issue asks: it now treats both “copyright” and “copyleft” (case‑insensitive) as satisfying the header requirement within the first 10 real lines, so the behavior matches the PR objective.
A couple of nits you might (optionally) address:
- The generator
any(True for line in lines[1:11] if ...)is harder to read than the usualany(predicate(line) for line in ...), and it still has to evaluate the predicate for each line that’s checked. This is essentially the same concern raised in the earlier review you already discussed, so treat this as a duplicate style note, not a blocker.- You’re calling
line.lower()twice per line; if you care about micro‑perf here, you could factor it once per iteration.A clearer, still short‑circuiting version could be:
- if not any( - True for line in lines[1:11] if "copyright" in line.lower() or "copyleft" in line.lower() - ): + if not any( + (lower := line.lower()) and ("copyright" in lower or "copyleft" in lower) + for line in lines[1:11] + ):or, if you prefer to avoid the walrus operator for compatibility/readability:
- if not any( - True for line in lines[1:11] if "copyright" in line.lower() or "copyleft" in line.lower() - ): + def _has_copyright_or_copyleft(line): + lower = line.lower() + return "copyright" in lower or "copyleft" in lower + + if not any(_has_copyright_or_copyleft(line) for line in lines[1:11]):Given the test failure mention (
cpplint_clitest“silly-simple”), it would also be worth double‑checking that the updated samples/expected outputs in that test still line up with this behavior (e.g., that a “Copyleft …” line truly appears within the first 10 lines after the sentinel).
🧹 Nitpick comments (1)
cpplint_unittest.py (1)
86-95: Minor docstring nit: use clearer notation for set differenceThe phrase
_ERROR_CATEGORIES~_SEEN_ERROR_CATEGORIESlooks like it was meant to be a set difference (probably_ERROR_CATEGORIES - _SEEN_ERROR_CATEGORIES). Consider restoring the minus or spelling it out for clarity; it’s only a comment but currently reads a bit cryptically.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
cpplint.py(1 hunks)cpplint_unittest.py(2 hunks)samples/silly-sample/cfg.def(1 hunks)samples/silly-sample/simple.def(1 hunks)samples/silly-sample/src/sillycode.w(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cpplint_unittest.py (1)
cpplint.py (1)
ProcessFileData(7354-7423)
🪛 GitHub Actions: Test
samples/silly-sample/src/sillycode.w
[error] 3: cpplint: No #ifndef header guard found (suggested macro); cpplint: Should have a space between // and comment on lines 1 and 3 [build/header_guard, whitespace/comments]
cpplint.py
pytest tests for cpplint failed with exit code 1 during cpplint_clitest suite (silly-simple).
cpplint_unittest.py
pytest tests for cpplint failed with exit code 1 during cpplint_clitest suite (silly-simple).
🔇 Additional comments (3)
samples/silly-sample/cfg.def (1)
6-27: Totals and diagnostics look consistent with new Copyleft handlingWith only
build/header_guardplus a singlewhitespace/commentswarning expected forsrc/sillycode.w,Total errors found: 20and the listed diagnostics are correct; once the extra whitespace warning fromsillycode.wline 1 is removed (see that file), this definition should match cpplint_clitest output again.cpplint_unittest.py (1)
5857-5894: New copyright/Copyleft tests correctly cover intended behaviourThe additions in
testLegalCopyrightlook good:
[""] * 10 + [copyright_line]still asserts that a copyright at logical line 11 triggers the warning.- A single
// Copyleft …line is now accepted withoutlegal/copyright.[""] * 9 + [copyright_line]verifies that a header on the 10th logical line is treated as valid.These align with the updated CheckForCopyright semantics and should guard regressions around both Copyleft acceptance and the “first ten lines” rule.
samples/silly-sample/simple.def (1)
6-7: I'll help you verify and rewrite this review comment. Let me start by exploring the repository structure and examining the relevant files.
<function_calls>
find . -type f -name "simple.def" | head -20
</function_calls>
<function_calls>
find . -type f -name "sillycode.w" | head -20
</function_calls>
<function_calls>
git ls-files | grep -E "(simple.def|sillycode.w)" | head -20
</function_calls>These scripts will help me locate the files mentioned in the review comment and understand the repository structure.
jayvdb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on #64 (comment)
|
Ditto. |
sorry not sorry. you've been getting a less-than-average amount of april fools recently, have you?
(this is a serious PR with serious commits that fix #64 and an unserious title and description)
Summary by CodeRabbit
Refactor
Tests
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.