├── .editorconfig ├── .github ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── FUNDING.yml ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── config ├── drupal7 │ ├── grumphp.yml │ ├── php_cs_fixer.config.php │ ├── phpcs.xml │ └── tasks.phpcsfixer2.config.yml └── drupal8 │ ├── grumphp.yml │ ├── php_cs_fixer.config.php │ ├── phpcs.xml │ └── tasks.phpcsfixer.config.yml └── src └── GrumphpTasksExtension.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration normalization 2 | # @see http://editorconfig.org/ 3 | 4 | # This is the top-most .editorconfig file; do not search in parent directories. 5 | root = true 6 | 7 | # All files. 8 | [*] 9 | end_of_line = LF 10 | indent_style = space 11 | indent_size = 4 12 | charset = utf-8 13 | trim_trailing_whitespace = true 14 | insert_final_newline = true 15 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @drupol 2 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at am@localheinz.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # CONTRIBUTING 2 | 3 | We're using [Travis CI](https://travis-ci.com) as a continuous integration system. 4 | 5 | For details, see [`.travis.yml`](../.travis.yml). 6 | 7 | ## Tests 8 | 9 | We're using [`grumphp/grumphp`](https://github.com/phpro/grumphp) to drive the development. 10 | 11 | Run 12 | 13 | ```bash 14 | ./vendor/bin/grumphp run 15 | ``` 16 | 17 | to run all the tests. 18 | 19 | ## Coding Standards 20 | 21 | We are using [`drupol/php-conventions`](https://github.com/drupol/php-conventions) to enforce coding standards. 22 | 23 | Run 24 | 25 | ```bash 26 | ./vendor/bin/grumphp run 27 | ``` 28 | 29 | to automatically detect/fix coding standard violations. 30 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: drupol 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Steps required to reproduce the problem 2 | 3 | 1. 4 | 2. 5 | 3. 6 | 7 | ## Expected Result 8 | 9 | * 10 | 11 | ## Actual Result 12 | 13 | * 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | This PR 2 | 3 | * [x] 4 | * [ ] 5 | * [ ] 6 | 7 | Follows #. 8 | Related to #. 9 | Fixes #. 10 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | daysUntilStale: 60 2 | 3 | daysUntilClose: 7 4 | 5 | staleLabel: stale 6 | 7 | markComment: > 8 | This issue has been automatically marked as stale because it has not had 9 | recent activity. It will be closed if no further activity occurs. Thank you 10 | for your contributions. 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | node_modules 3 | build 4 | npm-debug.log 5 | composer.lock 6 | yarn.lock 7 | behat.yml 8 | runner.yml 9 | .idea 10 | package-lock.json 11 | phpunit.xml 12 | .stylelintrc.json 13 | docker-compose.*.yml 14 | 15 | # Ignore artifacts generated by "npm run build". 16 | /css/ 17 | /fonts/ 18 | /js/base.js 19 | /templates/components/ 20 | /oe_theme/ 21 | *.tar.gz 22 | 23 | # Ignore all files in the images folder other than the required icon. 24 | 25 | /images/* 26 | !/images/required.svg 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Drupal conventions 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Latest Stable Version](https://img.shields.io/packagist/v/drupol/drupal-conventions.svg?style=flat-square)](https://packagist.org/packages/drupol/drupal-conventions) 2 | [![Stars](https://img.shields.io/github/stars/drupol/drupal-conventions.svg?style=flat-square)](https://github.com/drupol/drupal-conventions) 3 | [![Total Downloads](https://img.shields.io/packagist/dt/drupol/drupal-conventions.svg?style=flat-square)](https://packagist.org/packages/drupol/drupal-conventions) 4 | [![Build Status](https://img.shields.io/travis/drupol/drupal-conventions/master.svg?style=flat-square)](https://travis-ci.org/drupol/drupal-conventions) 5 | [![License](https://img.shields.io/github/license/drupol/drupal-conventions.svg?style=flat-square)](https://packagist.org/packages/drupol/drupal-conventions) 6 | [![Say Thanks!](https://img.shields.io/badge/Say-thanks-brightgreen.svg?style=flat-square)](https://saythanks.io/to/drupol) 7 | [![Donate!](https://img.shields.io/badge/Donate-Paypal-brightgreen.svg?style=flat-square)](https://paypal.me/drupol) 8 | 9 | # Drupal conventions 10 | 11 | This tool will check your code against Drupal's coding standard. 12 | 13 | It's based on [GrumPHP](https://github.com/phpro/grumphp) and comes with a default configuration tailored for Drupal development. 14 | 15 | The following checks are triggered: 16 | * [Drupal coder](https://www.drupal.org/project/coder) code sniffer's checks 17 | * Custom [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer) configuration 18 | * PHPLint 19 | * YAMLlint 20 | * JSONlint 21 | 22 | Drupal 7 and 8 are supported. 23 | 24 | ## Installation 25 | 26 | ```shell 27 | composer require --dev drupol/drupal-conventions 28 | ``` 29 | 30 | ### If you're not using GrumPHP 31 | 32 | Manually add to your `composer.json` file: 33 | 34 | #### Drupal 8 35 | ```yaml 36 | "extra": { 37 | "grumphp": { 38 | "config-default-path": "vendor/drupol/drupal-conventions/config/drupal8/grumphp.yml" 39 | } 40 | } 41 | ``` 42 | #### Drupal 7 43 | ```yaml 44 | "extra": { 45 | "grumphp": { 46 | "config-default-path": "vendor/drupol/drupal-conventions/config/drupal7/grumphp.yml" 47 | } 48 | } 49 | ``` 50 | 51 | ### If you're using GrumPHP already 52 | 53 | Edit the file `grumphp.yml.dist` or `grumphp.yml` and add on the top it: 54 | 55 | #### Drupal 8 56 | ```yaml 57 | imports: 58 | - { resource: vendor/drupol/drupal-conventions/config/drupal8/grumphp.yml } 59 | ``` 60 | #### Drupal 7 61 | ```yaml 62 | imports: 63 | - { resource: vendor/drupol/drupal-conventions/config/drupal7/grumphp.yml } 64 | ``` 65 | 66 | To add an extra Grumphp task: 67 | 68 | ```yaml 69 | imports: 70 | - { resource: vendor/drupol/drupal-conventions/config/drupal7/grumphp.yml } 71 | 72 | parameters: 73 | extra_tasks: 74 | phpunit: 75 | always_execute: false 76 | ``` 77 | 78 | In conjunction with `extra_tasks`, use `skip_tasks` to skip tasks if needed. 79 | 80 | ## Contributing 81 | 82 | Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-) 83 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "drupol/drupal-conventions", 3 | "type": "library", 4 | "description": "Drupal conventions for coding.", 5 | "keywords": [ 6 | "drupal", 7 | "coding style", 8 | "phpcs", 9 | "coding standard", 10 | "php-cs-fixer" 11 | ], 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Pol Dellaiera", 16 | "homepage": "https://www.drupal.org/u/pol", 17 | "role": "Author" 18 | } 19 | ], 20 | "require": { 21 | "php": ">= 7.4", 22 | "drupal/coder": "^8.3.13", 23 | "drupol/php-conventions": "^5", 24 | "drupol/phpcsfixer-configs-drupal": "^2" 25 | }, 26 | "suggest": { 27 | "symplify/coding-standard": "The LineLength fixer needs this library. Only PHP >= 7." 28 | }, 29 | "config": { 30 | "sort-packages": true 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "drupol\\DrupalConventions\\": "./src/" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /config/drupal7/grumphp.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: tasks.phpcsfixer.config.yml } 3 | 4 | parameters: 5 | # PHP Code Sniffer parameters. 6 | tasks.phpcs.exclude: [] 7 | tasks.phpcs.ignore_patterns: 8 | - vendor/ 9 | - node_modules/ 10 | - tests/fixtures/ 11 | - spec 12 | tasks.phpcs.triggered_by: 13 | - inc 14 | - install 15 | - module 16 | - php 17 | - profile 18 | tasks.phpcs.whitelist_patterns: [] 19 | tasks.phpcs.standard: ./vendor/drupol/drupal-conventions/config/drupal7/phpcs.xml 20 | tasks.phpcs.warning_severity: ~ 21 | 22 | # PHP CS Fixer parameters 23 | tasks.phpcsfixer.triggered_by: 24 | - inc 25 | - install 26 | - module 27 | - php 28 | - profile 29 | 30 | grumphp: 31 | process_timeout: 900 32 | parallel: 33 | enabled: false 34 | max_workers: 32 35 | fixer: 36 | enabled: true 37 | fix_by_default: true 38 | 39 | extensions: 40 | - drupol\PhpConventions\GrumphpTasksExtension 41 | 42 | # Tasks. 43 | tasks: 44 | # Composer checks 45 | composer: ~ 46 | 47 | # Composer Normalize 48 | composer_normalize: ~ 49 | 50 | # YAML Lint 51 | yamllint: 52 | whitelist_patterns: [] 53 | ignore_patterns: [] 54 | object_support: true 55 | exception_on_invalid_type: true 56 | parse_constant: true 57 | parse_custom_tags: true 58 | 59 | # JSON Lint 60 | jsonlint: 61 | ignore_patterns: [] 62 | detect_key_conflicts: true 63 | 64 | # PHP Lint 65 | phplint: 66 | triggered_by: ['php', 'module', 'install', 'profile', 'inc'] 67 | 68 | # Twig CS 69 | twigcs: 70 | path: '%tasks.twigcs.path%' 71 | ruleset: '%tasks.twigcs.ruleset%' 72 | severity: '%tasks.twigcs.severity%' 73 | triggered_by: '%tasks.twigcs.triggered_by%' 74 | 75 | # PHP CS Fixer 76 | phpcsfixer2: 77 | allow_risky: true 78 | config: '%tasks.phpcsfixer2.config%' 79 | config_contains_finder: true 80 | triggered_by: '%tasks.phpcsfixer2.triggered_by%' 81 | using_cache: false 82 | verbose: true 83 | 84 | # PHP Code Sniffer. 85 | phpcs: 86 | exclude: '%tasks.phpcs.exclude%' 87 | ignore_patterns: '%tasks.phpcs.ignore_patterns%' 88 | standard: '%tasks.phpcs.standard%' 89 | triggered_by: '%tasks.phpcs.triggered_by%' 90 | whitelist_patterns: '%tasks.phpcs.whitelist_patterns%' 91 | warning_severity: '%tasks.phpcs.warning_severity%' 92 | metadata: 93 | priority: 3000 94 | -------------------------------------------------------------------------------- /config/drupal7/php_cs_fixer.config.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | Drupal 7 coding standard 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /config/drupal7/tasks.phpcsfixer2.config.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | tasks.phpcsfixer.config: ./vendor/drupol/drupal-conventions/config/drupal7/php_cs_fixer.config.php 3 | -------------------------------------------------------------------------------- /config/drupal8/grumphp.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: ../../../../drupol/php-conventions/config/php73/grumphp.yml } 3 | - { resource: tasks.phpcsfixer.config.yml } 4 | 5 | parameters: 6 | # Grumphp license task 7 | tasks.license.name: LGPL-2.0 8 | 9 | # PHP Code Sniffer parameters. 10 | tasks.phpcs.exclude: [] 11 | tasks.phpcs.ignore_patterns: 12 | - vendor/ 13 | - node_modules/ 14 | - tests/fixtures/ 15 | - spec 16 | tasks.phpcs.triggered_by: 17 | - inc 18 | - install 19 | - module 20 | - php 21 | - profile 22 | - theme 23 | tasks.phpcs.whitelist_patterns: [] 24 | tasks.phpcs.standard: ./vendor/drupol/drupal-conventions/config/drupal8/phpcs.xml 25 | tasks.phpcs.warning_severity: ~ 26 | 27 | # PHP CS Fixer parameters 28 | tasks.phpcsfixer.triggered_by: 29 | - inc 30 | - install 31 | - module 32 | - php 33 | - profile 34 | - theme 35 | -------------------------------------------------------------------------------- /config/drupal8/php_cs_fixer.config.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | Drupal 8 coding standard 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /config/drupal8/tasks.phpcsfixer.config.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | tasks.phpcsfixer.config: ./vendor/drupol/drupal-conventions/config/drupal8/php_cs_fixer.config.php 3 | -------------------------------------------------------------------------------- /src/GrumphpTasksExtension.php: -------------------------------------------------------------------------------- 1 | hasParameter('extra_tasks')) { 26 | $tasks = $container->getParameter('tasks'); 27 | 28 | foreach ($container->getParameter('extra_tasks') as $name => $value) { 29 | if (isset($tasks[$name])) { 30 | throw new RuntimeException( 31 | sprintf("Cannot override already defined task '%s' in 'extra_tasks'", $name) 32 | ); 33 | } 34 | 35 | $tasks[$name] = $value; 36 | } 37 | 38 | $container->setParameter('tasks', $tasks); 39 | } 40 | 41 | if ($container->hasParameter('skip_tasks')) { 42 | $tasks = $container->getParameter('tasks'); 43 | 44 | foreach ($container->getParameter('skip_tasks') as $name) { 45 | unset($tasks[$name]); 46 | } 47 | 48 | $container->setParameter('tasks', $tasks); 49 | } 50 | 51 | } 52 | } 53 | --------------------------------------------------------------------------------