Sign inSign up

crashbar/php-codesniffer

By crashbar

•Updated 10 months ago

Via composer php-codesniffer + Drupal standard

Image
Security
Developer tools
0

621

crashbar/php-codesniffer repository overview

ā šŸ‘ƒ php-codesniffer + Drupa Standard

⁠A simple container for php-codesniffer based on Composer.

Added ESLint and stylelint linters

⁠Features

  • Scans local code.
  • The scan results can be output to a report for detailed analysis.
  • Can be used for tests in a pipeline.

⁠How to run

⁠Buid image
docker build -f ./Dockerfile -t php-codesniffer:1.0.1 .
docker tag php-codesniffer:1.0.1 crashbar/php-codesniffer:1.0.1
docker push crashbar/php-codesniffer:1.0.1
⁠Supported Scanning Standards:
MySource, 
PEAR, 
PSR1, 
PSR2, 
PSR12, 
Squiz, 
Zend, 
Drupal, 
DrupalPractice,
SlevomatCodingStandard
⁠Using docker run:
docker run -v "$(pwd)":/var/www --rm crashbar/php-codesniffer:latest sh -c 'phpcs -d memory_limit=512M --report=summary --standard=DrupalPractice web/*'

-d memory_limit=512M - can be changed to a larger value if you encounter memory errors due to a large volume of files being scanned.

-d memory_limit=-1 - alternatively, you can disable the limit if many files need to be scanned.

⁠Using docker-compose.yml:
services:
  sniffer:
    image: crashbar/php-codesniffer:latest
    command: phpcs --report=summary --standard=DrupalPractice web/*
    container_name: php-sniffer
    volumes:
      - <PATH TO CODE / OR GIT>:/var/www
⁠Using pipeline (e.g. Bitbucket):
pipelines:
  custom:
    tests:
      - step:
          name: php-codesniffer
          image: crashbar/php-codesniffer:latest
          services:
            - docker
          script:
            - apt-get update && apt-get install -y jq
            - phpcs --report=summary --standard=DrupalPractice web/*
⁠Example output php-codesniffer
PHP CODE SNIFFER REPORT SUMMARY
----------------------------------------------------------------------
FILE                                                  ERRORS  WARNINGS
----------------------------------------------------------------------
...rc/EventSubscriber/OrderEntityCloneSubscriber.php  0       3
.../EventSubscriber/ProductEntityCloneSubscriber.php  0       1
...er_print/src/Controller/OrderActionController.php  0       1
..._print/src/Controller/OrderContractController.php  0       1
..._order_print/src/Form/OrderContractConfigForm.php  0       5
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS AND 11 WARNINGS WERE FOUND IN 5 FILES
----------------------------------------------------------------------
Time: 0.91 secs; Memory: 52MB

⁠ESLint (Drupal standard)

⁠Using docker run:
docker run -e USER=$(id -u) -e GROUP=$(id -g) -v "$(pwd)":/var/www --rm php-codesniffer:1.0.2 sh -c 'chown -R $USER:$GROUP /var/linters/. && cp -raf /var/linters/. . && mv .eslintrc.json web/ && mv .stylelintrc.json web/ && npx eslint web/themes/custom/**/webpack.mix.js'
⁠Using pipeline (e.g. Bitbucket):
pipelines:
  custom:
    tests:
      - step: 
          name: ESLint-docker
          image: crashbar/php-codesniffer:latest
          services:
            - docker
          script:
            - cp -raf /var/linters/. . && mv .eslintrc.json web/ && mv .stylelintrc.json web/ 
            - npx eslint web/themes/custom/**/webpack.mix.js

⁠Stylelint (Drupal standard)

⁠Using docker run:
docker run -e USER=$(id -u) -e GROUP=$(id -g) -v ./:/var/www --rm php-codesniffer:1.0.2 sh -c 'chown -R $USER:$GROUP /var/linters/. && cp -raf /var/linters/. . && mv .eslintrc.json web/ && mv .stylelintrc.json web/ && npx stylelint web/themes/custom/**/assets/css/gsore.css'
⁠Using pipeline (e.g. Bitbucket):
pipelines:
  custom:
    tests:
      - step:
          name: stylelint-docker
          image: crashbar/php-codesniffer:latest
          services:
            - docker
          script:
            - cp -raf /var/linters/. . && mv .eslintrc.json web/ && mv .stylelintrc.json web/ 
            - npx stylelint web/themes/custom/**/assets/css/gsore.css
⁠Example output ESLint
/webpack.mix.js
  1:5   error  'mix' is never reassigned. Use 'const' instead                                    prefer-const
  1:19  error  Replace `'laravel-mix')` with `"laravel-mix");`                                   prettier/prettier
  1:19  error  Unable to resolve path to module 'laravel-mix'                                    import/no-unresolved
  2:35  error  Replace `'browser-sync-webpack-plugin'` with `"browser-sync-webpack-plugin"`      prettier/prettier
  27:15  error  Replace `processCssUrls:Ā·false` with `Ā·processCssUrls:Ā·falseĀ·`                   prettier/prettier
  29:2   error  Delete `āŽ`                                                                       prettier/prettier
āœ– 18 problems (18 errors, 0 warnings)
  15 errors and 0 warnings potentially fixable with the `--fix` option.
⁠Example output stylelint
/gsore.css
  109:3    āœ–  Expected color to come before text-decoration

āœ– 3121 problems (3121 errors, 0 warnings)
  1958 errors potentially fixable with the "--fix" option.

Tag summary

Content type

Image

Digest

sha256:a7b3835a2…

Size

399.7 MB

Last updated

10 months ago

docker pull crashbar/php-codesniffer