Skip to content

Commit

Permalink
Merge pull request #111 from marinaglancy/eslintandcodewarnings
Browse files Browse the repository at this point in the history
Add max-warnings to codechecker and grunt eslint
  • Loading branch information
David Castro authored May 19, 2020
2 parents 0b2090b + 66e088e commit ead2ea4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"type": "package",
"package": {
"name": "moodlehq/moodle-local_codechecker",
"version": "2.9.3",
"version": "2.9.5",
"source": {
"url": "https://github.com/moodlehq/moodle-local_codechecker.git",
"type": "git",
"reference": "v2.9.3"
"reference": "v2.9.5"
},
"autoload": {
"classmap": [
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt
7.2 and 7.3 (per release notes).
- Replaced Selenium in-built functionality with docker image for Selenium
Standalone server. See [#99](https://github.com/blackboard-open-source/moodle-plugin-ci/issues/99).
- Updated version of `moodlehq/moodle-local_codechecker`.

### Added
- New help document: [CLI commands and options](CLI.md)
Expand Down
33 changes: 30 additions & 3 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Run Moodle Code Checker on a plugin

### Usage

* `codechecker [-s|--standard STANDARD] [--] <plugin>`
* `codechecker [-s|--standard STANDARD] [--max-warnings MAX-WARNINGS] [--] <plugin>`

Run Moodle Code Checker on a plugin

Expand All @@ -405,6 +405,15 @@ The name or path of the coding standard to use
* Is multiple: no
* Default: `'moodle'`

#### `--max-warnings`

Number of warnings to trigger nonzero exit code - default: -1

* Accept value: yes
* Is value required: yes
* Is multiple: no
* Default: `-1`

#### `--help|-h`

Display this help message
Expand Down Expand Up @@ -570,7 +579,7 @@ Run Grunt task on a plugin

### Usage

* `grunt [-m|--moodle MOODLE] [-t|--tasks TASKS] [--] <plugin>`
* `grunt [-m|--moodle MOODLE] [-t|--tasks TASKS] [--show-lint-warnings] [--max-lint-warnings MAX-LINT-WARNINGS] [--] <plugin>`

Run Grunt task on a plugin

Expand Down Expand Up @@ -604,6 +613,24 @@ The Grunt tasks to run
* Is multiple: yes
* Default: `array ( 0 => 'amd', 1 => 'yui', 2 => 'gherkinlint', 3 => 'stylelint:css', 4 => 'stylelint:less', 5 => 'stylelint:scss',)`

#### `--show-lint-warnings`

Show eslint warnings

* Accept value: no
* Is value required: no
* Is multiple: no
* Default: `false`

#### `--max-lint-warnings`

Maximum number of eslint warnings

* Accept value: yes
* Is value required: yes
* Is multiple: no
* Default: `''`

#### `--help|-h`

Display this help message
Expand Down Expand Up @@ -1984,4 +2011,4 @@ Do not ask any interactive question
* Accept value: no
* Is value required: no
* Is multiple: no
* Default: `false`
* Default: `false`
2 changes: 2 additions & 0 deletions docs/TravisFileExplained.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ script:
# This step runs the Moodle Code Checker to make sure that your plugin
# conforms to the Moodle coding standards. It is highly recommended
# that you keep this step.
# To fail on warnings use --max-warnings 0
- moodle-plugin-ci codechecker
# This step runs Moodle PHPDoc checker on your plugin.
- moodle-plugin-ci phpdoc
Expand All @@ -115,6 +116,7 @@ script:
# tasks relevant to your plugin and Moodle version, but you can run
# specific tasks by passing them as options,
# EG: moodle-plugin-ci grunt -t task1 -t task2
# To fail on eslint warnings use --max-lint-warnings 0
- moodle-plugin-ci grunt
# This step runs the PHPUnit tests of your plugin. If your plugin has
# PHPUnit tests, then it is highly recommended that you keep this step.
Expand Down
8 changes: 6 additions & 2 deletions src/Command/CodeCheckerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ protected function configure()

$this->setName('codechecker')
->setDescription('Run Moodle Code Checker on a plugin')
->addOption('standard', 's', InputOption::VALUE_REQUIRED, 'The name or path of the coding standard to use', 'moodle');
->addOption('standard', 's', InputOption::VALUE_REQUIRED, 'The name or path of the coding standard to use', 'moodle')
->addOption('max-warnings', null, InputOption::VALUE_REQUIRED,
'Number of warnings to trigger nonzero exit code - default: -1', -1);
}

protected function initialize(InputInterface $input, OutputInterface $output)
Expand Down Expand Up @@ -86,6 +88,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$sniffer->process($files, $this->standard);
$results = $sniffer->reporting->printReport('full', false, $sniffer->cli->getCommandLineValues(), null, 120);

return $results['errors'] > 0 ? 1 : 0;
$maxwarnings = (int) $input->getOption('max-warnings');

return ($results['errors'] > 0 || ($maxwarnings >= 0 && $results['warnings'] > $maxwarnings)) ? 1 : 0;
}
}
6 changes: 4 additions & 2 deletions src/Command/CodeFixerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use MoodlePluginCI\Bridge\CodeSnifferCLI;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -23,10 +24,11 @@ class CodeFixerCommand extends CodeCheckerCommand
{
protected function configure()
{
parent::configure();
AbstractPluginCommand::configure();

$this->setName('phpcbf')
->setDescription('Run Code Beautifier and Fixer on a plugin');
->setDescription('Run Code Beautifier and Fixer on a plugin')
->addOption('standard', 's', InputOption::VALUE_REQUIRED, 'The name or path of the coding standard to use', 'moodle');
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand Down
14 changes: 12 additions & 2 deletions src/Command/GruntCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ protected function configure()

$this->setName('grunt')
->setDescription('Run Grunt task on a plugin')
->addOption('tasks', 't', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The Grunt tasks to run', $tasks);
->addOption('tasks', 't', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The Grunt tasks to run', $tasks)
->addOption('show-lint-warnings', null, InputOption::VALUE_NONE, 'Show eslint warnings')
->addOption('max-lint-warnings', null, InputOption::VALUE_REQUIRED,
'Maximum number of eslint warnings', '');
}

protected function initialize(InputInterface $input, OutputInterface $output)
Expand All @@ -66,7 +69,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$builder = ProcessBuilder::create()
->setPrefix('grunt')
->setPrefix('grunt');
if ($input->getOption('show-lint-warnings')) {
$builder->add('--show-lint-warnings');
}
if (strlen($input->getOption('max-lint-warnings'))) {
$builder->add('--max-lint-warnings='.((int) $input->getOption('max-lint-warnings')));
}
$builder
->add($task->taskName)
->setWorkingDirectory($task->workingDirectory)
->setTimeout(null);
Expand Down

0 comments on commit ead2ea4

Please sign in to comment.