Skip to content

Commit 7c9292f

Browse files
authored
Merge pull request #1223 from rodrigoaguilera/eslint-cache
Add cache CLI options for eslint
2 parents 47362f1 + ed5cac9 commit 7c9292f

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

doc/tasks/eslint.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ grumphp:
3434
- /^resources\/js\/(.*)/
3535
config: .eslintrc.json
3636
ignore_path: .eslintignore
37+
cache: ~
38+
cache_location: ~
3739
debug: false
3840
format: ~
3941
max_warnings: ~
@@ -79,6 +81,18 @@ The path to your eslint's configuration file. Not necessary if using a standard
7981

8082
The path to your eslint's ignore file ([eslint.org](https://eslint.org/docs/user-guide/configuring/ignoring-code#using-an-alternate-file)). Not necessary if using standard .eslintignore name.
8183

84+
**cache**
85+
86+
*Default: null*
87+
88+
Store the results of processed files so that eslint only operates on the changed ones. By default, the cache is stored in `./.eslintcache ` in `process.cwd()`. ([eslint.org](https://eslint.org/docs/latest/use/command-line-interface#caching)).
89+
90+
**cache_location**
91+
92+
*Default: null*
93+
94+
Path to a file or directory for the cache location. ([eslint.org](https://eslint.org/docs/latest/use/command-line-interface#--cache-location)).
95+
8296
**debug**
8397

8498
*Default: false*

src/Task/ESLint.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3434
// ESLint native config options
3535
'config' => null,
3636
'ignore_path' => null,
37+
'cache' => null,
38+
'cache_location' => null,
3739
'debug' => false,
3840
'format' => null,
3941
'max_warnings' => null,
@@ -49,6 +51,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4951
// ESLint native config options
5052
$resolver->addAllowedTypes('config', ['null', 'string']);
5153
$resolver->addAllowedTypes('ignore_path', ['null', 'string']);
54+
$resolver->addAllowedTypes('cache', ['null', 'bool']);
55+
$resolver->addAllowedTypes('cache_location', ['null', 'string']);
5256
$resolver->addAllowedTypes('debug', ['bool']);
5357
$resolver->addAllowedTypes('format', ['null', 'string']);
5458
$resolver->addAllowedTypes('max_warnings', ['null', 'integer']);
@@ -82,6 +86,8 @@ public function run(ContextInterface $context): TaskResultInterface
8286

8387
$arguments->addOptionalArgument('--config=%s', $config['config']);
8488
$arguments->addOptionalArgument('--ignore-path=%s', $config['ignore_path']);
89+
$arguments->addOptionalArgument('--cache', $config['cache']);
90+
$arguments->addOptionalArgument('--cache-location=%s', $config['cache_location']);
8591
$arguments->addOptionalArgument('--debug', $config['debug']);
8692
$arguments->addOptionalArgument('--format=%s', $config['format']);
8793
$arguments->addOptionalArgument('--no-eslintrc', $config['no_eslintrc']);

test/Unit/Task/ESLintTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public static function provideConfigurableOptions(): iterable
3434
// ESLint native config options
3535
'config' => null,
3636
'ignore_path' => null,
37+
'cache' => null,
38+
'cache_location' => null,
3739
'debug' => false,
3840
'format' => null,
3941
'max_warnings' => null,
@@ -146,6 +148,30 @@ public static function provideExternalTaskRuns(): iterable
146148
'hello2.js',
147149
]
148150
];
151+
yield 'cache' => [
152+
[
153+
'cache' => true,
154+
],
155+
self::mockContext(RunContext::class, ['hello.js', 'hello2.js']),
156+
'eslint',
157+
[
158+
'--cache',
159+
'hello.js',
160+
'hello2.js',
161+
]
162+
];
163+
yield 'cache_location' => [
164+
[
165+
'cache_location' => 'path/to/cache',
166+
],
167+
self::mockContext(RunContext::class, ['hello.js', 'hello2.js']),
168+
'eslint',
169+
[
170+
'--cache-location=path/to/cache',
171+
'hello.js',
172+
'hello2.js',
173+
]
174+
];
149175
yield 'debug' => [
150176
[
151177
'debug' => true,

0 commit comments

Comments
 (0)