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 support for phpcs #111

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ env:
# This needs to match your .coveralls.yml file.
- DRUPAL_TI_COVERAGE_FILE="build/logs/clover.xml"

# === PHPCS specific variables.
# These arguments are passed to the phpcs command.
- DRUPAL_TI_PHPCS_ARGS=""
# The version of drupal/coder that should be used.
- DRUPAL_TI_DRUPAL_CODER_VERSION="drupal/coder:^8.2"

# Debug options
#- DRUPAL_TI_DEBUG="-x -v"
# Set to "all" to output all files, set to e.g. "xvfb selenium" or "selenium",
Expand Down
32 changes: 32 additions & 0 deletions functions/phpcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# @file
# Common functionality for installing phpcs and friends.

#
# Ensures that phpcs is installed.
#
function drupal_ti_ensure_phpcs() {
# This function is re-entrant.
if [ -r "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" ]
then
return
fi

# Check if drupal/coder is already available.
DRUPAL_CODER=$(composer info --no-interaction drupal/coder || echo "")

if [ -z "$DRUPAL_CODER" ]
then
# Install drupal/coder globally.
echo "Installing drupal/coder: $DRUPAL_TI_DRUPAL_CODER_VERSION"
composer global require --no-interaction "$DRUPAL_TI_DRUPAL_CODER_VERSION"
else
echo "phpcs $DRUPAL_TI_DRUPAL_CODER_VERSION is already installed."
composer global install --no-interaction
fi

# Install Drupal and DrupalPractice coding standards.
phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer

touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed"
}
7 changes: 7 additions & 0 deletions runners/phpcs/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Simple script to install dependencies for travis-ci running.

set -e $DRUPAL_TI_DEBUG

# Ensure that phpcs is installed.
drupal_ti_ensure_phpcs
19 changes: 19 additions & 0 deletions runners/phpcs/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# @file
# phpcs integration - Script step.

set -e $DRUPAL_TI_DEBUG

if [[ -n $DRUPAL_TI_PHPCS_ARGS ]]; then
ARGS=( $DRUPAL_TI_PHPCS_ARGS )
else
ARGS=(
"--colors"
"--standard=Drupal,DrupalPractice"
"--extensions=php,module,inc,install,test,profile,theme,css,info,txt,md"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure you should lint css files :D

"--ignore=node_modules,bower_components,vendor"
"${TRAVIS_BUILD_DIR}"
)
fi

$HOME/.composer/vendor/bin/phpcs "${ARGS[@]}"
2 changes: 1 addition & 1 deletion tests/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ln -sf "$SCRIPT_DIR/drupal-ti" /tmp/drupal_ti/bin/

# Setup runners.
export DRUPAL_TI_RUNNERS="success"
/tmp/drupal_ti/bin/drupal-ti script && echo "- Test succeeed as expected." || exit 1
/tmp/drupal_ti/bin/drupal-ti script && echo "- Test succeeded as expected." || exit 1

export DRUPAL_TI_RUNNERS="failure"
/tmp/drupal_ti/bin/drupal-ti script && exit 1 || echo "- Test failed as expected."
Expand Down