#!/usr/bin/env bash

#ddev-generated
## Command provided by https://github.com/ddev/ddev-drupal-contrib
## Description: Run eslint inside the web container
## Usage: eslint [flags] [args]
## Example: "ddev eslint"
## ExecRaw: true

if "$DDEV_DOCROOT/core/node_modules/.bin/eslint" --version >/dev/null ; then
  # Configure prettier
  test -e .prettierrc.json || ln -s $DDEV_DOCROOT/core/.prettierrc.json .
  test -e .prettierignore || echo '*.yml' > .prettierignore
  # Change directory to the project root folder
  cd "$DDEV_DOCROOT/modules/custom/${DDEV_SITENAME//-/_}" || exit
  "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core/node_modules/.bin/eslint" --config="../../../core/.eslintrc.passing.json" --no-error-on-unmatched-pattern --ignore-pattern="*.es6.js" --resolve-plugins-relative-to=$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/core --ext=.js,.yml . "$@"
else
  echo "eslint is not available. You may need to 'ddev exec \"cd $DDEV_DOCROOT/core && yarn install\"'"
  exit 1
fi
