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

Add improved codesniffer support. #151

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

codebymikey
Copy link

@codebymikey codebymikey commented May 30, 2024

The Problem/Issue/Bug

Codesniffer integration is currently not the best, so added tooling as well as ensure that the installed_paths set by dealerdirect/phpcodesniffer-composer-installer isn't unintentionally purged after composer has finished installing the site.

How this PR Solves The Problem

Add tooling for php codesniffer's phpcs and phpcbf scripts - which are useful for ensuring code meets certain standards (and will help with gitpod integrations like PHPStorm, which require the scripts to be present on the "host").

Also ensure that ddev phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer is no longer accidentally overwritten with our script. I'd probably opt to remove this part of the code in the first place if possible if we already have the composer plugin.

Manual Testing Instructions

phpcs and phpcbf commands should now work with or without the ddev prefix.

phpcs --config-show
ddev phpcs --config-show
phpcbf --config-show
ddev phpcbf --config-show

Related Issue Link(s)

Release/Deployment notes

Summary by CodeRabbit

  • New Features

    • Introduced scripts for running PHP_CodeSniffer and code beautifier within DDEV.
    • Added scripts for running PHPUnit, PHPCS, and PHPCBF from a DDEV container.
  • Improvements

    • Enhanced configuration setup for PHPCS in Drupal to check existing configurations before setting up.
    • Updated script handling for path compatibility in IDEs.

shaal and others added 5 commits December 22, 2023 00:24
* fix: support drupal 11

* fix: improve code

* fix: default installation

* fix: update mariadb version to 10.6

* fix: update ddev-gitpod image (latest ddev version)

* fix: lazygit binaries

* fix: remove legacy settings from gitpod.yml

* fix: use DP_CORE_VERSION when there's no issue_fork

* fix: reorganize scripts order

* Update .gitpod/drupal/drupalpod-setup/ddev_setup.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Allows fallback setup when DrupalPod is called with no DP_PROJECT_TYPE.
That is the case when DrupalPod is called without using the browser extension.
Copy link

codesandbox bot commented May 30, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@codebymikey codebymikey force-pushed the codesniffer-support branch from 3f906d0 to 8b90f63 Compare May 30, 2024 17:40
Copy link
Contributor

coderabbitai bot commented May 30, 2024

Walkthrough

This update introduces new scripts and modifications to existing ones to improve the handling of PHP_CodeSniffer tools (phpcs and phpcbf) and PHPUnit within a DDEV environment. The changes streamline the setup and execution of these tools, ensuring compatibility with IDEs and enhancing the developer experience in Gitpod and DDEV setups.

Changes

File/Path Change Summary
.ddev/commands/web/phpcbf Added a script to run PHP_CodeSniffer's code beautifier (phpcbf) within DDEV.
.ddev/commands/web/phpcs Introduced a script to run PHP_CodeSniffer's codesniffer tool (phpcs) within DDEV.
.ddev/commands/host/exec_dir Modified argument handling and path references based on environment variables.
.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh Updated phpcs configuration check and setup logic.
.gitpod/utils/env-setup.sh Added commands to run PHPUnit, PHPCS, and PHPCBF inside a DDEV container.
.gitpod/utils/script-templates/ddev-phpcbf.template.sh Added a template script for running phpcbf in a DDEV environment.
.gitpod/utils/script-templates/ddev-phpcs.template.sh Introduced a template script for running phpcs in a DDEV environment.
.gitpod/utils/script-templates/ddev-phpunit.template.sh Added a template script for running PHPUnit in a DDEV environment.

Poem

In the realm of code so neat,
Tools align for a developer's feat.
With phpcs and phpcbf at hand,
DDEV and Gitpod make a stand.
Paths and scripts, all set right,
Bringing joy to coders' sight.
🐰✨ CodeRabbit's delight!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
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: 0

Outside diff range and nitpick comments (1)
.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh (1)

Line range hint 119-119: Correct the syntax for better script robustness.

- if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ]; then
+ if [ ! -f "${GITPOD_REPO_ROOT}"/.drupalpod_initiated ]
+ then

Shellcheck warns about using a semicolon or linefeed before 'then'. It's a good practice to place 'then' on a new line for clarity and to avoid potential script errors.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8ddc8c9 and 8b90f63.

Files selected for processing (7)
  • .ddev/commands/web/phpcbf (1 hunks)
  • .ddev/commands/web/phpcs (1 hunks)
  • .gitpod/drupal/drupalpod-setup/drupalpod-setup.sh (1 hunks)
  • .gitpod/utils/env-setup.sh (1 hunks)
  • .gitpod/utils/script-templates/ddev-phpcbf.template.sh (1 hunks)
  • .gitpod/utils/script-templates/ddev-phpcs.template.sh (1 hunks)
  • .gitpod/utils/script-templates/ddev-phpunit.template.sh (1 hunks)
Files skipped from review due to trivial changes (6)
  • .ddev/commands/web/phpcbf
  • .ddev/commands/web/phpcs
  • .gitpod/utils/env-setup.sh
  • .gitpod/utils/script-templates/ddev-phpcbf.template.sh
  • .gitpod/utils/script-templates/ddev-phpcs.template.sh
  • .gitpod/utils/script-templates/ddev-phpunit.template.sh
Additional context used
Shellcheck
.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh

[info] 51-51: Not following: ./fallback_setup.sh was not specified as input (see shellcheck -x).


[info] 54-54: Not following: ./git_setup.sh was not specified as input (see shellcheck -x).


[info] 63-63: Not following: ./ddev_setup.sh was not specified as input (see shellcheck -x).


[info] 68-68: Not following: ./contrib_modules_setup.sh was not specified as input (see shellcheck -x).


[info] 69-69: Not following: ./cleanup.sh was not specified as input (see shellcheck -x).


[info] 70-70: Not following: ./composer_setup.sh was not specified as input (see shellcheck -x).


[info] 79-79: Not following: ./drupal_setup_core.sh was not specified as input (see shellcheck -x).


[info] 82-82: Not following: ./drupal_setup_contrib.sh was not specified as input (see shellcheck -x).


[warning] 119-119: Use semicolon or linefeed before 'then' (or quote to make it literal).

Additional comments not posted (1)
.gitpod/drupal/drupalpod-setup/drupalpod-setup.sh (1)

89-91: Ensure PHP Codesniffer's installed_paths is correctly set.

The conditional check using ddev phpcs --config-show | grep -q 'installed_paths:' before setting the installed_paths is a good practice. It prevents unnecessary reconfiguration if it's already set, which can be particularly useful in environments where the setup script might be executed multiple times.

This ensures that absolute paths on the host are automatically converted to the absolute path within the container without issue.
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b90f63 and fdad5fa.

Files selected for processing (3)
  • .ddev/commands/host/exec_dir (1 hunks)
  • .gitpod/utils/script-templates/ddev-phpcbf.template.sh (1 hunks)
  • .gitpod/utils/script-templates/ddev-phpcs.template.sh (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • .gitpod/utils/script-templates/ddev-phpcbf.template.sh
  • .gitpod/utils/script-templates/ddev-phpcs.template.sh
Additional comments not posted (1)
.ddev/commands/host/exec_dir (1)

24-24: Validate the final command execution to ensure it correctly uses the modified arguments.

Comment on lines +16 to +19
for arg in "$@"; do
new_arg="${arg//${GITPOD_REPO_ROOT}//var/www/html}"
arguments+=("$new_arg")
done
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The path replacement logic in the loop does not handle edge cases where the substring appears multiple times in the path. This can lead to incorrect replacements, as demonstrated by the script output.

  • The replacement logic should be adjusted to ensure only the intended part of the path is replaced.
Analysis chain

Check the path replacement logic for potential edge cases.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the path replacement logic handles all edge cases.

# Test: Simulate a scenario where the path might not be replaced correctly.
# Example: When the path contains similar substrings or nested paths.
echo "/path/to/repo/path/to/repo/file" | sed "s|/path/to/repo|/new/path|g"

Length of output: 98

@@ -9,4 +9,16 @@ if [ -z "$1" ]; then
exit 1
fi

ddev exec -d /var/www/html/"$(echo "$PWD" | cut -d'/' -f4-)" "$@"
if [ "${GITPOD_NORMALIZE_EXEC_ARGUMENTS:-1}" = 1 ] && [ -n "${GITPOD_REPO_ROOT}" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The environment variable GITPOD_REPO_ROOT is set in the .gitpod.yml file, but there is no evidence of GITPOD_NORMALIZE_EXEC_ARGUMENTS being set anywhere in the codebase or configuration files. This could lead to the condition in the script not being met.

  • Ensure that GITPOD_NORMALIZE_EXEC_ARGUMENTS is set appropriately in the environment or configuration files.
Analysis chain

Ensure GITPOD_NORMALIZE_EXEC_ARGUMENTS is properly set in the environment.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the environment variable `GITPOD_NORMALIZE_EXEC_ARGUMENTS` is set.

# Test: Check the environment variable. Expect: It should be set to 1.
echo $GITPOD_NORMALIZE_EXEC_ARGUMENTS

Length of output: 7



Script:

#!/bin/bash
# Description: Verify the environment variable `GITPOD_REPO_ROOT` is set.

# Test: Check the environment variable. Expect: It should be non-empty.
echo $GITPOD_REPO_ROOT

Length of output: 7



Script:

#!/bin/bash
# Description: Search for the setting of `GITPOD_NORMALIZE_EXEC_ARGUMENTS` and `GITPOD_REPO_ROOT` in the codebase.

# Search for `GITPOD_NORMALIZE_EXEC_ARGUMENTS`
rg 'GITPOD_NORMALIZE_EXEC_ARGUMENTS'

# Search for `GITPOD_REPO_ROOT`
rg 'GITPOD_REPO_ROOT'

Length of output: 58



Script:

#!/bin/bash
# Description: Search for the setting of `GITPOD_NORMALIZE_EXEC_ARGUMENTS` and `GITPOD_REPO_ROOT` in configuration files.

# Search for `GITPOD_NORMALIZE_EXEC_ARGUMENTS` in configuration files
rg 'GITPOD_NORMALIZE_EXEC_ARGUMENTS' --glob '*.env' --glob '*.sh' --glob '*.yaml' --glob '*.yml'

# Search for `GITPOD_REPO_ROOT` in configuration files
rg 'GITPOD_REPO_ROOT' --glob '*.env' --glob '*.sh' --glob '*.yaml' --glob '*.yml'

Length of output: 414

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