Skip to content

Conversation

@aaronliu0130
Copy link
Member

@aaronliu0130 aaronliu0130 commented Apr 24, 2025

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

    • Streamlined copyright/copyleft detection for faster, clearer checks.
  • Tests

    • Expanded unit tests to cover additional copyright detection scenarios.
  • Bug Fixes

    • Adjusted lint diagnostics in sample inputs so reported warnings better match actual content.

✏️ Tip: You can customize this high-level summary in your review settings.

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
Copy link

Copilot AI left a 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.

@coderabbitai
Copy link

coderabbitai bot commented Nov 28, 2025

Note

Other AI code review bot(s) detected

CodeRabbit 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.

Walkthrough

cpplint.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

Cohort / File(s) Summary
Core Logic Enhancement
cpplint.py
Replaced the explicit for/else copyright search with a concise any() check over lines[1:11], matching "copyright" (case-insensitive) or "copyleft"; behavior, error messages, and public APIs unchanged.
Test Updates
cpplint_unittest.py
Added test cases covering copyleft detection; replaced list-comprehension constructors with [""] * N in ProcessFileData calls; reorganized one ProcessFileData invocation layout without semantic change.
Sample Test Data
samples/silly-sample/src/sillycode.w, samples/silly-sample/cfg.def, samples/silly-sample/simple.def
Modified comment in src/sillycode.w to include a copyleft marker; .def files adjusted expected lint counts and messages to reflect the new copyleft recognition (net reductions in reported warnings where applicable).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the any() slice bounds (lines[1:11]) and the case-normalization to ensure it matches prior semantics.
  • Verify new/updated tests in cpplint_unittest.py correctly exercise both "copyright" and "copyleft" cases and maintain previous coverage.
  • Check .def sample expectations and updated lint counts for consistency with detection change.

Poem

🐇
I hopped through headers, swift and deft,
Found "copyleft" where copyright left.
A tiny change, a lighter load—
The linting path a friendlier road.
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Introduce leftism in overhauling copyright :)' is a playful reference to 'copyleft' but accurately describes the main change: extending copyright/copyleft handling in cpplint.
Linked Issues check ✅ Passed The PR fully addresses issue #64 by modifying cpplint to recognize 'copyleft' (case-insensitive) alongside 'copyright' in file headers, eliminating the lint error for copyleft-licensed projects.
Out of Scope Changes check ✅ Passed All changes are within scope: cpplint.py implements copyleft support, cpplint_unittest.py adds corresponding tests, and sample files reflect expected lint output changes.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch anarchism

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ff0afe and b0f02d6.

📒 Files selected for processing (1)
  • samples/silly-sample/simple.def (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • samples/silly-sample/simple.def
⏰ 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)
  • GitHub Check: build-test (3.x, windows-latest)
  • GitHub Check: build-test (3.10, windows-latest)

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 headers

The //#copyleft4prez2025… line both:

  • Triggers an extra whitespace/comments warning (no space after //), which is why cpplint_clitest silly-simple is 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 the any(True for ...) pattern is non‑idiomatic and redundant

Functionally 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 usual any(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 difference

The phrase _ERROR_CATEGORIES~_SEEN_ERROR_CATEGORIES looks 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

📥 Commits

Reviewing files that changed from the base of the PR and between b32e1f3 and 8ff0afe.

📒 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 handling

With only build/header_guard plus a single whitespace/comments warning expected for src/sillycode.w, Total errors found: 20 and the listed diagnostics are correct; once the extra whitespace warning from sillycode.w line 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 behaviour

The additions in testLegalCopyright look good:

  • [""] * 10 + [copyright_line] still asserts that a copyright at logical line 11 triggers the warning.
  • A single // Copyleft … line is now accepted without legal/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.

Copy link
Member

@jayvdb jayvdb left a 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)

@aaronliu0130
Copy link
Member Author

Ditto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow use of "Copyleft" instead of "Copyright"

3 participants