-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#84 Add ESLint support and configure it to use Drupal standards.
- Loading branch information
Showing
6 changed files
with
132 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Wunderio\GrumPHP\Task\ESLint; | ||
|
||
use Wunderio\GrumPHP\Task\AbstractExternalExtensionLoader; | ||
|
||
/** | ||
* Class PhpCompatibilityExtensionLoader. | ||
* | ||
* Register Eslint task in the service container of GrumPHP. | ||
* | ||
* @package Wunderio\GrumPHP\Task | ||
*/ | ||
class EslintExtensionLoader extends AbstractExternalExtensionLoader {} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Wunderio\GrumPHP\Task\ESLint; | ||
|
||
use GrumPHP\Collection\ProcessArgumentsCollection; | ||
use Wunderio\GrumPHP\Task\AbstractMultiPathProcessingTask; | ||
|
||
/** | ||
* Class ESLint2Task. | ||
* | ||
* Eslint task. | ||
* | ||
* @package Wunderio\GrumPHP\Task | ||
*/ | ||
class EslintTask extends AbstractMultiPathProcessingTask { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildArguments(iterable $files): ProcessArgumentsCollection { | ||
$config = $this->getConfig()->getOptions(); | ||
$arguments = ProcessArgumentsCollection::forExecutable($config['bin']); | ||
|
||
$arguments->add('--config=' . $config['config']); | ||
$arguments->addOptionalArgument('--debug', $config['debug']); | ||
$arguments->addOptionalCommaSeparatedArgument('--ext=%s', (array) $config['extensions']); | ||
$arguments->addOptionalArgument('--format=%s', $config['format']); | ||
// @todo Not sure if this works. | ||
$arguments->addOptionalIntegerArgument('--max-warnings=%d', $config['max_warnings']); | ||
$arguments->addOptionalBooleanArgument('--no-eslintrc=%s', $config['no_eslintrc'], 'true', 'false'); | ||
$arguments->addOptionalBooleanArgument('--quiet=%s', $config['quiet'], 'true', 'false'); | ||
foreach ($config['ignore_patterns'] as $ignore_pattern) { | ||
$arguments->add('--ignore-pattern=' . $ignore_pattern); | ||
} | ||
|
||
foreach ($files as $file) { | ||
$files_new[] = $file; | ||
$arguments->add($file); | ||
} | ||
|
||
return $arguments; | ||
} | ||
|
||
} |
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,29 @@ | ||
# ESLint | ||
|
||
Check js code against coding standards and security standards. By default Drupal rules are loaded. | ||
|
||
### grumphp.yml (with current defaults): | ||
````yml | ||
parameters: | ||
tasks: | ||
eslint: | ||
ignore_patterns: | ||
- '**/vendor/**' | ||
- '**/node_modules/**' | ||
- '**/core/**' | ||
- '**/libraries/**' | ||
- '**/contrib/**' | ||
extensions: ['js', 'jsx', 'ts', 'tsx', 'vue'] | ||
run_on: [ 'web/modules/custom', 'web/themes/custom' ] | ||
bin: 'node_modules/.bin/eslint' | ||
config: 'web/core/.eslintrc.passing.json' | ||
debug: false | ||
format: ~ | ||
max_warnings: ~ | ||
no_eslintrc: false | ||
quiet: ~ | ||
extensions: | ||
- Wunderio\GrumPHP\Task\PhpCompatibilityTask\PhpCompatibilityExtensionLoader | ||
```` | ||
|
||
|
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