-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert phpcs tests to their own repository
- Loading branch information
1 parent
73cebc6
commit 72bc372
Showing
52 changed files
with
1,475 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# The generic_files_linendings test is checking for crlf line endings and warns about them. | ||
# This must be specified as a .gitattribute to prevent git updating it to be LF on commit. | ||
/phpcs/moodle/tests/fixtures/generic_files_lineendings.php eol=crlf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Moodle Coding Style Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- php: 8.1 | ||
- php: 8.0 | ||
- php: 7.4 | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP ${{ matrix.php }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: ${{ matrix.extensions }} | ||
ini-values: pcov.directory=phpcs/moodle | ||
coverage: pcov | ||
tools: composer, phpcpd | ||
|
||
- name: Install composer dependencies | ||
run: | | ||
composer install | ||
- name: Run phplint | ||
if: ${{ always() }} | ||
run: | | ||
./vendor/bin/phplint | ||
- name: PHP Copy/Paste Detector | ||
continue-on-error: true # This step will show errors but will not fail | ||
if: ${{ always() }} | ||
run: phpcpd --exclude phpcs/moodle/tests phpcs/moodle | ||
|
||
- name: Run phpunit | ||
if: ${{ always() }} | ||
run: | | ||
./vendor/bin/phpunit --coverage-text | ||
- name: Test coverage | ||
run: ./vendor/bin/phpunit-coverage-check -t 80 clover.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
vendor | ||
composer.lock | ||
phpcs.xml | ||
.phpcs.xml | ||
.phpunit.result.cache | ||
phpunit.xml | ||
.phplint-cache | ||
clover.xml | ||
.phpunit.cache | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
path: ./ | ||
exclude: | ||
- vendor | ||
- phpcs/moodle/tests/fixtures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Moodle Coding Style | ||
|
||
<div aria-hidden="true"> | ||
|
||
[![Latest Stable Version](https://poser.pugx.org/moodlehq/moodle-cs/v/stable)](https://packagist.org/packages/moodlehq/moodle-cs) | ||
[![Release Date of the Latest Version](https://img.shields.io/github/release-date/moodlehq/moodle-cs.svg?maxAge=1800)](https://github.com/moodlehq/moodle-cs/releases) | ||
:construction: | ||
|
||
[![Unit Tests](https://github.com/moodlehq/moodle-cs/actions/workflows/phpcs.yml/badge.svg)](https://github.com/moodlehq/moodle-cs/actions/workflows/phpcs.yml) | ||
|
||
[![License](https://poser.pugx.org/moodlehq/moodle-cs/license)](https://github.com/moodlehq/moodle-cs/blob/main/LICENSE) | ||
[![Total Downloads](https://poser.pugx.org/moodlehq/moodle-cs/downloads)](https://packagist.org/packages/moodlehq/moodle-cs/stats) | ||
[![Number of Contributors](https://img.shields.io/github/contributors/moodlehq/moodle-cs.svg?maxAge=3600)](https://github.com/moodlehq/moodle-cs/graphs/contributors) | ||
|
||
</div> | ||
|
||
## Information | ||
|
||
This repository contains the Moodle Coding Style configuration. | ||
|
||
Currently this only includes the configuration for PHP Coding style, but this | ||
may be extended to include custom rules for JavaScript, and any other supported | ||
languages or syntaxes. | ||
|
||
|
||
## Installation | ||
|
||
### Using Composer | ||
|
||
You can include these coding style rules using Composer to make them available | ||
globally across your system. | ||
|
||
This will install the correct version of phpcs, with the Moodle rules, and their | ||
dependencies. | ||
|
||
``` | ||
composer global require moodlehq/moodle-cs | ||
``` | ||
|
||
### As a part of moodle-local_codechecker | ||
|
||
This plugin is included as part of the [moodle-local_codechecker | ||
plugin](https://github.com/moodlehq/moodle-local_codechecker). | ||
|
||
|
||
## Configuration | ||
|
||
You can set the Moodle standard as the system default: | ||
``` | ||
phpcs --config-set default_standard moodle | ||
``` | ||
|
||
This will inform most IDEs automatically. | ||
Alternatively you can configuration your IDE to use phpcs with the Moodle | ||
ruleset as required. | ||
|
||
|
||
### IDE Integration | ||
|
||
#### PhpStorm | ||
|
||
1. Open PhpStorm preferences | ||
2. Go to Inspections > PHP > PHP Code Sniffer Validation | ||
3. In the 'coding standard' dropdown, select 'moodle' | ||
|
||
#### Sublime Text | ||
|
||
Find documentation [here](https://docs.moodle.org/dev/Setting_up_Sublime2#Sublime_PHP_CS). | ||
|
||
1. Go in your Sublime Text to Preferences -> Package Control -> Package Control: Install Package | ||
2. Write 'phpcs' in the search field, if you see Phpcs and SublimeLinter-phpcs, click on them to install them. | ||
3. If not, check if they are already installed Preferences -> Package Control -> Package Control: Remove Package. | ||
4. To set your codecheck to moodle standards go to Preferences -> Package Settings -> PHP Code Sniffer -> Settings-User and write: | ||
|
||
{ "phpcs_additional_args": { | ||
"--standard": "moodle", | ||
"-n": " | ||
}, | ||
} | ||
|
||
5. If you don’t have the auto-save plugin turned on, YOU’RE DONE! | ||
6. If you have the auto-save plugin turned on, because the codecheck gets triggered on save, the quick panel will keep popping making it impossible to type. | ||
To stop quick panel from showing go to Settings-User file and add: | ||
|
||
"phpcs_show_quick_panel": false, | ||
|
||
The line with the error will still get marked and if you’ll click on it you’ll see the error text in the status bar. | ||
|
||
#### VSCode | ||
|
||
Find documentation [here](https://docs.moodle.org/dev/Setting_up_VSCode#PHP_CS). | ||
|
||
1. Install [PHPSniffer](https://marketplace.visualstudio.com/items?itemName=wongjn.php-sniffer). | ||
2. Open VSCode settings.json and add the following setting to define standard PHP CS (if you haven't set it as default in your system): | ||
|
||
"phpSniffer.standard": "moodle", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "moodlehq/moodle-cs", | ||
"type": "phpcodesniffer-standard", | ||
"description": "Moodle Coding Sniffer rules", | ||
"keywords": [ | ||
"phpcs", | ||
"standards", | ||
"WordPress" | ||
], | ||
"license": "GPL-2.0-or-later", | ||
"authors": [ | ||
{ | ||
"name": "Andrew Lyons", | ||
"email": "andrew@nicols.co.uk" | ||
} | ||
], | ||
"require": { | ||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2", | ||
"squizlabs/php_codesniffer": "^3.6", | ||
"phpcompatibility/php-compatibility": "^9.3" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"install-codestandards": [ | ||
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" | ||
] | ||
}, | ||
"support": { | ||
"issues": "https://github.com/moodlehq/moodle-cs/issues", | ||
"wiki": "https://github.com/moodlehq/moodle-cs/wiki", | ||
"source": "https://github.com/moodlehq/moodle-cs" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^9.5", | ||
"mikey179/vfsstream": "^1.6", | ||
"overtrue/phplint": "^3.0", | ||
"phpmd/phpmd": "^2.11", | ||
"thor-juhasz/phpunit-coverage-check": "^0.3.0" | ||
}, | ||
"replace": { | ||
"moodlehq/moodle-local_codechecker": "3.1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"MoodleHQ\\MoodleCS\\moodle\\": "phpcs/moodle/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.