Skip to content

Enhance Linting and Code Coverage Checks with New Scripts and Job Separation #2810

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

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

im-vedant
Copy link

@im-vedant im-vedant commented Dec 30, 2024

What kind of change does this PR introduce?

Feature

Issue Number:

Fixes #2806

Summary

  1. Added code coverage script for checking code coverage disable statements.
  2. Improved eslint disable check script.
  3. Added separate jobs for eslint disable check and code coverage disable check.

Summary by CodeRabbit

  • New Features

    • Added Python scripts to check for ESLint and code coverage disable comments in TypeScript files
    • Implemented GitHub Actions workflow jobs to validate code quality during pull requests
  • Chores

    • Enhanced error handling and input validation for code checking scripts
    • Updated workflow dependencies to include new code quality checks

Copy link

coderabbitai bot commented Dec 30, 2024

Walkthrough

The pull request introduces two new Python scripts and updates the GitHub Actions workflow to enhance code quality checks. The code_coverage_disable_check.py script detects code coverage disable statements in TypeScript files, while the eslint_disable_check.py script identifies ESLint disable comments. The pull-request.yml workflow is modified to include new jobs that run these scripts on changed files during pull request reviews, ensuring that code coverage and linting bypass statements are flagged and reviewed.

Changes

File Change Summary
.github/workflows/code_coverage_disable_check.py New script to recursively check TypeScript files for code coverage disable statements using regex
.github/workflows/eslint_disable_check.py Enhanced script with improved file/directory handling and expanded regex for detecting ESLint disable comments
.github/workflows/pull-request.yml Added two new jobs: Check-Eslint-Disable and Check-Code-Coverage-Disable; updated job dependencies

Assessment against linked issues

Objective Addressed Explanation
Detect Code Coverage Bypass Comments [#2806]
Detect ESLint Disable Comments [#2806]
Fail Workflow if Bypass Comments Detected [#2806]

Possibly related PRs

Suggested reviewers

  • palisadoes
  • varshith257

Poem

🐰 Code quality's our quest, oh so bright!
Catching sneaky comments out of sight
No bypasses shall slip through today
Our rabbit-powered checks are here to stay
Linting and coverage, standing tall and proud! 🕵️‍♀️🔍

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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

🧹 Nitpick comments (4)
.github/workflows/eslint_disable_check.py (1)

76-77: Combine nested if statements for cleaner logic.

You can simplify this by merging the condition that checks if a file ends with ".ts" and the call to has_eslint_disable.

Here’s a possible diff:

- if item.endswith(".ts"):
-     if has_eslint_disable(item):
-         print(f"File {item} contains eslint-disable statement. Please remove them and ensure the code adheres to the specified ESLint rules.")
-         eslint_found = True
+ if item.endswith(".ts") and has_eslint_disable(item):
+     print(f"File {item} contains eslint-disable statement. Please remove them and ensure the code adheres to the specified ESLint rules.")
+     eslint_found = True
🧰 Tools
🪛 Ruff (0.8.2)

76-77: Use a single if statement instead of nested if statements

(SIM102)

.github/workflows/code_coverage_disable_check.py (1)

91-103: Combine nested if statements to reduce complexity.

Similar to the ESLint checker script, merging both conditions into a single statement can make the code more concise and maintainable.

Here’s a suggested diff:

- if (
-     item.endswith(".ts")
-     and not item.endswith(".test.ts")
-     and not item.endswith(".spec.ts")
- ):
-     if has_code_coverage_disable(item):
-         print(...)
-         code_coverage_found = True
+ if (
+     item.endswith(".ts")
+     and not item.endswith(".test.ts")
+     and not item.endswith(".spec.ts")
+     and has_code_coverage_disable(item)
+ ):
+     print(...)
+     code_coverage_found = True
🧰 Tools
🪛 Ruff (0.8.2)

91-98: Use a single if statement instead of nested if statements

(SIM102)


93-98: Use a single if statement instead of nested if statements

(SIM102)

.github/workflows/pull-request.yml (2)

77-77: Quote variables to avoid shell expansion issues.

Shellcheck suggests quoting $CHANGED_FILES to prevent unwanted word splitting. For instance:

- run: npx eslint ${CHANGED_FILES} --max-warnings=1500
+ run: npx eslint "${CHANGED_FILES}" --max-warnings=1500
🧰 Tools
🪛 actionlint (1.7.4)

77-77: shellcheck reported issue in this script: SC2086:info:1:12: Double quote to prevent globbing and word splitting

(shellcheck)


218-218: Remove trailing spaces.

YAML linting flags trailing spaces on this line. Consider removing them to keep the file neatly formatted.

-          python .github/workflows/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} 
+          python .github/workflows/code_coverage_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }}
🧰 Tools
🪛 yamllint (1.35.1)

[error] 218-218: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 938812c and cdb026f.

📒 Files selected for processing (3)
  • .github/workflows/code_coverage_disable_check.py (1 hunks)
  • .github/workflows/eslint_disable_check.py (3 hunks)
  • .github/workflows/pull-request.yml (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
.github/workflows/eslint_disable_check.py

76-77: Use a single if statement instead of nested if statements

(SIM102)

.github/workflows/code_coverage_disable_check.py

91-98: Use a single if statement instead of nested if statements

(SIM102)


93-98: Use a single if statement instead of nested if statements

(SIM102)

🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

77-77: shellcheck reported issue in this script: SC2086:info:1:12: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 218-218: trailing spaces

(trailing-spaces)

🔇 Additional comments (7)
.github/workflows/eslint_disable_check.py (3)

7-9: Good clarity in docstring.

These lines effectively communicate that both directories and individual files can now be analyzed. Clear documentation helps maintainers and contributors understand the script usage.


142-145: Validate fallback to directory arguments.

Here, if --files is not provided, you default to --directory. This logic appears sound. Confirm that there are no edge cases where both arguments are empty.

Do you want a script to check for invocations of this file without either argument specified?


147-152: Exit code ensures robust CI checks.

Exiting with error code 1 when an ESLint-disable is found provides a clear CI signal. This matches best practices for fail-fast pipelines.

.github/workflows/code_coverage_disable_check.py (2)

1-10: New file addition is well-documented.

The script's high-level docstring clearly states its purpose and methodology. Good adherence to Python docstring conventions.


133-158: Solid design for script entry point.

Your main() function clearly lays out the usage flow. Handling file vs. directory arguments and performing checks aligns well with the project's coding style.

.github/workflows/pull-request.yml (2)

180-219: Separate jobs for ESLint and coverage checks are well-structured.

Defining dedicated jobs Check-ESlint-Disable and Check-Code-Coverage-Disable isolates responsibilities and enhances maintainability. This is a beneficial addition to the workflow.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 218-218: trailing spaces

(trailing-spaces)


223-223: Good practice to gate final tests on new checks.

Requiring [Code-Quality-Checks, Check-Eslint-Disable, Check-Code-Coverage-Disable] ensures no test runs if essential checks fail, enforcing robust CI gating.

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.72%. Comparing base (938812c) to head (cdb026f).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2810   +/-   ##
========================================
  Coverage    97.72%   97.72%           
========================================
  Files          364      364           
  Lines        18545    18545           
  Branches      2676     2676           
========================================
  Hits         18123    18123           
  Misses         417      417           
  Partials         5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@palisadoes palisadoes merged commit f998e32 into PalisadoesFoundation:develop Dec 30, 2024
13 of 14 checks passed
@palisadoes
Copy link
Contributor

Add to the develop-postgres branch too

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.

2 participants