Skip to content

Fix issues in pylint.yml and JSlint error for no files found#2

Merged
sambhxv merged 4 commits into
developmentfrom
fix/disable-lints/AB-04406
Jun 3, 2025
Merged

Fix issues in pylint.yml and JSlint error for no files found#2
sambhxv merged 4 commits into
developmentfrom
fix/disable-lints/AB-04406

Conversation

@sambhxv

@sambhxv sambhxv commented May 27, 2025

Copy link
Copy Markdown
Contributor

Currently, the script picks up code from all the existing python files in the repository and not just the files changed, which was wrong.

This new patch picks up only select code from the current PR from the diff and tries linting it.

Signed-off-by: Sambhav Saxena <sambhav.saxena@ambibuzz.com>
@github-actions

Copy link
Copy Markdown

Critical Review of the Pull Request Diff

  1. Installation of Dependencies:

    • The addition of diff-cover is a good move if coverage reporting is intended. However, ensure that it is actually used in the workflow later on, or it may be unnecessary bloat.
  2. Flake8 Configuration:

    • The configuration for Flake8 is now being written in a more readable way, which is an improvement. However, consider using a dedicated configuration file (like .flake8 or setup.cfg) instead of generating it dynamically. This approach can help maintain consistency and make it easier to manage configurations.
  3. Fetching Changed Files:

    • The command git fetch origin ${{ github.base_ref }} assumes that the base branch is always available. If the workflow is triggered on a pull request from a fork, this could lead to issues. Consider adding error handling or checks to ensure that the base branch exists.
  4. Linting Only Changed Files:

    • The logic to lint only changed files is a good optimization, as it reduces unnecessary checks. However, ensure that the workflow still runs Flake8 and Black on all files in a separate job or conditionally, to maintain overall code quality.
  5. Conditional Execution:

    • The use of if: steps.get_diff.outputs.changed_files != '' is a good practice to avoid running linting on empty outputs. However, consider logging or notifying if no files were changed, as it might be useful for developers to know that their changes did not affect any Python files.
  6. Error Handling:

    • The || true in the Black check allows the workflow to continue even if formatting issues are found. This could lead to situations where code is merged without proper formatting. It might be better to fail the job if Black finds issues, ensuring that all code adheres to the style guide.

Suggested Improvements

  • Use a Configuration File: Instead of dynamically creating the .flake8 file, consider using a static configuration file. This will make it easier to manage and version control.

  • Error Handling for Git Fetch: Add error handling for the git fetch command to ensure that the workflow does not fail silently if the base branch is not found.

  • Full Linting Job: Consider adding a separate job that runs Flake8 and Black on all files to ensure that the entire codebase remains compliant with the style guide, regardless of whether files were changed.

  • Logging for No Changes: Implement logging to notify when no Python files have been changed, which can help developers understand the workflow's output better.

Test Cases for Business Logic

While this diff primarily deals with CI/CD configuration rather than business logic, if there were any business logic changes in the codebase, consider the following test cases:

  1. Test for Linting on Changed Files:

    • Ensure that when a Python file is changed, the linting process runs successfully and catches any linting errors.
  2. Test for No Changes:

    • Verify that when no Python files are changed, the workflow completes without errors and logs an appropriate message.
  3. Test for Configuration File:

    • If a static configuration file is used, ensure that it is correctly read and applied during the linting process.
  4. Test for Error Handling:

    • Simulate scenarios where the base branch does not exist and ensure that the workflow fails gracefully with a meaningful error message.

By addressing these points, the pull request can be improved for better maintainability and reliability.

…jsx,tsx,vue,css,html,json}"`

The script used to run and throw an error even in cases where no JS or related prettier configured files are found, and eventually lead to a failed workflow. This is not expected behaviour, which has been updated with this patch.

Signed-off-by: Sambhav Saxena <sambhav.saxena@ambibuzz.com>
@github-actions

Copy link
Copy Markdown

Critical Review of the Pull Request Diff

  1. Prettier Linting Changes:

    • The change to use find and xargs for linting JavaScript files is a good improvement as it avoids running Prettier on files that do not exist. However, the command could be simplified by using prettier --check directly on the file patterns without the need for find and xargs. This would make the script cleaner and easier to read.
    • The --write flag is removed from the Prettier command. If the intention is to only check formatting without modifying files, this is appropriate. Ensure that this aligns with the project's linting strategy.
  2. Flake8 Configuration:

    • The method of writing to .flake8 using multiple echo commands is functional but can be simplified to a single command using a heredoc. This would enhance readability.
    • The addition of diff-cover is a positive change, as it can help in assessing test coverage, but ensure that it is utilized in the workflow.
  3. Handling Changed Files:

    • The logic to fetch and check for changed Python files is a good optimization, as it limits linting to only modified files. However, ensure that the base branch is correctly set and that this logic works in all scenarios (e.g., when there are no changes).
    • The use of tr to format the output is effective, but consider using xargs directly in the git diff command to avoid potential issues with file names containing spaces.
  4. Conditional Linting:

    • The conditional checks for running Flake8 and Black only on changed files are well-implemented. This can significantly reduce unnecessary linting on unchanged files, improving CI performance.

Suggestions for Improvement

  • Simplify Prettier Command: Consider reverting to a simpler command for Prettier if it meets the requirements.
  • Use Heredoc for .flake8: Replace multiple echo commands with a heredoc for better readability:
    cat <<EOF > .flake8
    [flake8]
    max-line-length = 256
    indent-size = 4
    EOF
  • Test Coverage Integration: If diff-cover is added, ensure that it is integrated into the workflow to provide meaningful output.
  • Error Handling: Consider adding error handling for the git fetch command to ensure that the workflow fails gracefully if it encounters issues.

Suggested Test Cases for Business Logic

  1. Prettier Linting:

    • Test with a directory containing various file types to ensure that only the specified file types are linted.
    • Test with an empty directory to confirm that the message "No matching files found for linting." is displayed.
  2. Flake8 Linting:

    • Test with a repository that has modified Python files to ensure that only those files are linted.
    • Test with a repository that has no modified Python files to ensure that the workflow does not fail and handles the condition gracefully.
  3. Black Formatting:

    • Test with modified Python files that are formatted correctly to ensure that Black does not report any errors.
    • Test with modified Python files that are incorrectly formatted to ensure that Black reports the expected errors.

By addressing these points, the pull request can be improved for clarity, efficiency, and robustness.

@sambhxv sambhxv changed the title Fix issues in pylint.yml Fix issues in pylint.yml and JSlint error for no files found. May 27, 2025
@sambhxv sambhxv changed the title Fix issues in pylint.yml and JSlint error for no files found. Fix issues in pylint.yml and JSlint error for no files found May 27, 2025
Signed-off-by: Sambhav Saxena <sambhav.saxena@ambibuzz.com>
@github-actions

Copy link
Copy Markdown

Critical Review of the Pull Request Diff

  1. Prettier Linting Changes:

    • The change to use find and xargs for linting JavaScript files is a good improvement as it prevents running Prettier on non-existent files, which could lead to unnecessary errors. However, using xargs can lead to issues if there are too many files (exceeding the command line length limit). Consider using -exec with find instead, which can handle a larger number of files more gracefully.
    • The --write flag in the Prettier command suggests that files will be modified. If the intention is only to check formatting, consider removing this flag to avoid unintended changes.
  2. Flake8 Configuration:

    • The method of creating the .flake8 configuration file is improved for readability. However, consider using a single echo command with a heredoc for better maintainability:
      cat <<EOF > .flake8
      [flake8]
      max-line-length = 256
      indent-size = 4
      EOF
  3. Changed Files Detection:

    • The addition of detecting changed Python files is a significant improvement as it optimizes the linting process. However, ensure that the git fetch command is correctly set up to fetch the base branch. If the base branch is not set correctly, it may lead to incorrect results.
    • The use of tr '\n' ' ' to format the output is a good approach, but consider handling cases where there are no changed files more explicitly to avoid potential issues in subsequent steps.
  4. Conditional Linting:

    • The conditional execution of Flake8 and Black based on the presence of changed files is a good optimization. Ensure that the logic correctly handles edge cases, such as when no Python files are changed or if the output from git diff is malformed.
  5. Error Handling:

    • The current setup does not seem to handle errors from the linting commands effectively. Consider adding error handling to ensure that the workflow fails if linting errors are found, which is crucial for maintaining code quality.

Suggested Test Cases for Business Logic

  1. Prettier Linting:

    • Test with a directory containing various file types (JS, TS, etc.) to ensure that only the specified file types are linted.
    • Test with an empty directory to confirm that the message "No matching files found for linting." is displayed.
  2. Flake8 Linting:

    • Test with a repository that has modified Python files to ensure that only those files are linted.
    • Test with a repository that has no modified Python files to ensure that the workflow does not attempt to lint and handles the case gracefully.
  3. Configuration File Creation:

    • Test the creation of the .flake8 file to ensure it contains the correct configuration settings.
  4. Error Handling:

    • Test scenarios where linting fails (e.g., code style violations) to ensure that the workflow fails as expected and provides appropriate feedback.

By addressing these points and implementing the suggested test cases, the overall quality and reliability of the CI/CD workflow can be significantly improved.

Signed-off-by: Sambhav Saxena <sambhav.saxena@ambibuzz.com>
@github-actions

Copy link
Copy Markdown

Critical Review of the Pull Request Diff

General Observations:

  1. Improved Efficiency: The changes made to both the JavaScript and Python workflows aim to improve efficiency by only linting files that have changed, which is a good practice to reduce unnecessary processing.
  2. Error Handling: The addition of checks for the existence of files before running linting commands is a positive change, as it prevents unnecessary errors when no files match the criteria.

Specific Issues and Suggestions:

  1. JavaScript Workflow (jslint.yml):

    • Use of xargs: The use of xargs to pass files to Prettier is generally fine, but it may fail if the list of files exceeds the command line length limit. Consider using a loop to handle files in smaller batches if you expect a large number of files.
    • Prettier Command: The --write flag modifies files in place. If the intention is only to check formatting, consider using --check instead. If the intention is to format files, ensure that this is clearly documented.
  2. Python Workflow (pylint.yml):

    • Fetching Base Reference: The command git fetch origin ${{ github.base_ref }} assumes that the base branch is always available. If the workflow is triggered by a pull request from a fork, this could lead to issues. Consider adding error handling or checks to ensure that the base branch exists.
    • Output Variable Naming: The output variable changed_files could be more descriptive, such as changed_python_files, to avoid confusion with other potential outputs.
    • Conditional Execution: The conditional checks for running Flake8 and Black are good, but ensure that the logic is clear and that the workflows do not silently skip linting if no files are found. Consider adding a log message to indicate that no files were found for linting.
  3. Documentation:

    • Ensure that comments are added to explain the purpose of each step in the workflows. This will help future maintainers understand the rationale behind the changes.

Suggested Test Cases for Business Logic:

  1. JavaScript Workflow:

    • Test with a repository containing no JavaScript files to ensure that the workflow correctly outputs "No matching files found for linting."
    • Test with a repository containing a mix of file types to ensure only the specified file types are linted.
  2. Python Workflow:

    • Test with a repository where no Python files have changed to verify that the workflow does not attempt to run Flake8 or Black and outputs a message indicating no files were found.
    • Test with a repository containing modified Python files to ensure that both Flake8 and Black run correctly on the changed files.

By addressing these points, the pull request can be improved for better reliability and maintainability.

@sambhxv sambhxv merged commit a5390ab into development Jun 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants