Skip to content
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

feat: added Check for embedded CSS and the correct stylesheet in Typescript files #3261

Open
wants to merge 2 commits into
base: develop-postgres
Choose a base branch
from

Conversation

IITI-tushar
Copy link
Contributor

@IITI-tushar IITI-tushar commented Jan 12, 2025

What kind of change does this PR introduce?

feature

Issue Number:#2907

Fixes #2907

Snapshots/Videos:

If relevant, did you update the documentation?

Summary

Other information

Have you read the contributing guide?
yes

Summary by CodeRabbit

  • New Features

    • Added a new GitHub Actions workflow step to validate CSS imports in TypeScript files.
    • Introduced a Python script to check for CSS violations during pull requests.
  • Chores

    • Enhanced code quality checks in the repository's CI/CD pipeline.

Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

Walkthrough

A new Python script css_check.py has been introduced in the .github/workflows directory to validate CSS usage in TypeScript files. The script checks for embedded CSS color codes and ensures that only the specified src/style/app.module.css stylesheet is referenced. It is designed to run as part of GitHub Actions, with command-line options to specify directories and exclusions. The workflow in pull-request.yml has been updated to incorporate this CSS checking mechanism.

Changes

File Change Summary
.github/workflows/css_check.py New Python script added with functions to check embedded CSS, validate CSS imports, and process TypeScript files.
.github/workflows/pull-request.yml Added steps to identify changed TypeScript files and run CSS violation checks.

Assessment against linked issues

Objective Addressed Explanation
Eliminate embedded CSS
Check only src/style/app.module.css
CLI option with --directory flag
Exclude unit test files Needs verification of exclusion logic.
Add to develop and develop-postgres workflows Requires confirmation of workflow updates.

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes
  • noman2002
  • AVtheking

Poem

🐰 In the realm of code, where styles reside,
A rabbit hops to check what's inside.
No embedded CSS shall escape my sight,
With regex sharp and checks held tight.
Cleanliness reigns, our stylesheet's pride! 🎨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a16908f and dd77fc9.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/pull-request.yml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)

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
Contributor

@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: 3

🧹 Nitpick comments (1)
.github/workflows/pull-request.yml (1)

43-50: Consider adding exclusions for generated TypeScript files.

The current file pattern might include generated TypeScript files that shouldn't be checked for CSS violations.

       - name: Get changed TypeScript files
         id: changed-ts-files
         uses: tj-actions/changed-files@v45
         with:
           files: |
             **/*.ts
             **/*.tsx
+          files_ignore: |
+            **/*.generated.ts
+            **/*.gen.ts
+            **/dist/**
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 018155d and a16908f.

📒 Files selected for processing (2)
  • .github/workflows/css_check.py (1 hunks)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: IITI-tushar
PR: PalisadoesFoundation/talawa-admin#3041
File: .github/workflows/css_check.py:11-22
Timestamp: 2025-01-07T09:50:29.019Z
Learning: In the talawa-admin project, CSS validation in TypeScript files should only check for hex color codes using the pattern `#([0-9a-fA-F]{3}){1,2}` and ensure that files only reference the `src/style/app.module.css` stylesheet.
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/css_check.py

[warning] 1-1:
File ignored by default.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (2)
.github/workflows/css_check.py (2)

9-21: LGTM! Function correctly implements CSS color code detection.

The implementation aligns with the project requirements for detecting hex color codes.


59-59: Reconsider excluding test files from CSS validation.

The current implementation skips files in test directories, but CSS violations in test files could still impact the application.

.github/workflows/css_check.py Show resolved Hide resolved
.github/workflows/css_check.py Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
@IITI-tushar
Copy link
Contributor Author

@palisadoes i have updated the code to run for files changed in the PR...
like here in this workflow the css_check.py didn't ran since there's not changed file...
image

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.21%. Comparing base (eceaad9) to head (dd77fc9).
Report is 10 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3261       +/-   ##
=====================================================
+ Coverage             10.74%   90.21%   +79.47%     
=====================================================
  Files                   309      330       +21     
  Lines                  7802     8491      +689     
  Branches               1729     1934      +205     
=====================================================
+ Hits                    838     7660     +6822     
+ Misses                 6900      601     -6299     
- Partials                 64      230      +166     

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

@Cioppolo14 Cioppolo14 requested review from noman2002 and beingnoble03 and removed request for palisadoes January 12, 2025 13:27
Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

f"Embedded CSS found in {file_path}: {', '.join(embedded_css)}"
)

return violations, correct_css_imports, embedded_css_violations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return a namedtuple. There is less risk of mistakes later by other contributors

print("\n".join(violations))

if embedded_css_violations:
print("\nEmbedded CSS Violations:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use a single string and at the end give an explanation of what the contributor must do. Use the python """ string representation to achieve this.
    1. We need contributors to understand the next steps and fix things without having to ask why
    2. It reduces the workload of the reviewers
  2. Give the color code and line number in the message. Make it easier for the end user to rectify the situation

)

if violations:
print("\nCSS Import Violations:")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use a single string and at the end give an explanation of what the contributor must do. Use the python """ string representation to achieve this.
    1. We need contributors to understand the next steps and fix things without having to ask why
    2. It reduces the workload of the reviewers


if correct_css_imports:
print("\nCorrect CSS Imports:")
print("\n".join(correct_css_imports))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make printing successes an optional message based on a argparse CLI flag.

print("\nCorrect CSS Imports:")
print("\n".join(correct_css_imports))
else:
print("\nNo correct CSS imports found.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary. Please remove

embedded_css = check_embedded_css(content)
if embedded_css:
embedded_css_violations.append(
f"Embedded CSS found in {file_path}: {', '.join(embedded_css)}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a named tuple with only the variable names. Add the text at the time of printing.

)
else:
violations.append(
f"Invalid CSS import ({css_file}) in {file_path}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a named tuple with only the variable names. Add the text at the time of printing.

# Check if the CSS import matches the allowed patterns
if any(css_file.endswith(pattern) for pattern in allowed_css_patterns):
correct_css_imports.append(
f"Correct CSS import ({css_file}) in {file_path}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a named tuple with only the variable names. Add the text at the time of printing.


# Check for CSS imports with an improved regex pattern
css_imports = re.findall(
r'import\s+.*?["\'](.*?\.css)["\'];', content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no test to see whether the CSS file actually exists. Please fix.

continue

# Check for CSS imports with an improved regex pattern
css_imports = re.findall(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you handle the use of single or double quotes? What does prettier apply, if relevant?

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