Skip to content

Commit 17b0b9d

Browse files
authored
Merge pull request #124 from hussainweb/custom-check
feat: add custom check
2 parents 51f3b45 + 4d2eb55 commit 17b0b9d

File tree

7 files changed

+83
-1
lines changed

7 files changed

+83
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,19 @@ These are the default options for `phpstan`. All are optional and you can overri
152152
```
153153

154154
This runs `phpstan` on the code base with the specified options. For the defaults to work, you must have a `phpstan.neon` configuration file in your codebase as [mentioned in the documentation](https://phpstan.org/user-guide/command-line-usage#running-without-arguments). Note that the default `phpstan.neon` as generated by [`axelerant/drupal-quality-checker`](https://github.com/axelerant/drupal-quality-checker) is valid for this purpose.
155+
156+
### custom
157+
158+
This allows you to run any arbitrary commands that you may want to run from within the tools that are available within the Docker image. This is useful if you want to run one of the tools available in the drupalqa Docker image but there is no custom check written above, or if you want to use a configuration option not available above. In any case, if you think what you are trying to run here is common enough, consider submitting an issue and/or a pull request to add the check. Look at other pull requests such as #121 and #122 to see how to write a check.
159+
160+
Example usage:
161+
162+
```yaml
163+
checks: |
164+
custom_linters:
165+
command: ['grumphp', 'run', '--testsuite=linters']
166+
custom_stylecheck:
167+
command: ['grumphp', 'run', '--testsuite=style']
168+
```
169+
170+
The above will run two commands as shown. The `custom` check was introduced for situations where we need to run the same command twice with different options. This is otherwise not possible using the typical check format as keys may not be repeated in YAML.

__tests__/custom.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import custom from '../src/checks/custom'
2+
import {expect, test} from '@jest/globals'
3+
4+
test('it returns defaults', () => {
5+
expect(custom({}, 'web')).toEqual([])
6+
})
7+
8+
test('it handles empty commands', () => {
9+
let command
10+
command = custom(
11+
{
12+
command: []
13+
},
14+
'web'
15+
)
16+
expect(command).toEqual([])
17+
})
18+
19+
test('it handles commands', () => {
20+
let command
21+
command = custom(
22+
{
23+
command: ['phpmd']
24+
},
25+
'docroot'
26+
)
27+
expect(command).toEqual(['phpmd'])
28+
})

dist/index.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/checks/custom.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {CustomOptions} from '../types'
2+
3+
export default function custom(
4+
options: CustomOptions,
5+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6+
webRoot: string
7+
): string[] {
8+
return options.command !== undefined ? options.command : []
9+
}

src/main.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as YAML from 'yaml'
44

55
import {CheckCallable} from './types'
66

7+
import custom from './checks/custom'
78
import grumphp from './checks/grumphp'
89
import phplint from './checks/phplint'
910
import phpcs from './checks/phpcs'
@@ -13,6 +14,7 @@ import phpstan from './checks/phpstan'
1314
const availableChecks: {
1415
[key: string]: CheckCallable
1516
} = {
17+
custom,
1618
grumphp,
1719
phplint,
1820
phpcs,
@@ -62,6 +64,8 @@ async function run(): Promise<void> {
6264
}
6365
if (key in availableChecks) {
6466
checksCommands.push(availableChecks[key](value, webRoot))
67+
} else if (key.startsWith('custom_')) {
68+
checksCommands.push(availableChecks['custom'](value, webRoot))
6569
} else {
6670
throw new Error(`invalid check ${key} specified.`)
6771
}

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ export interface PhpStanOptions {
3737
configuration?: string
3838
paths?: string[]
3939
}
40+
41+
export interface CustomOptions {
42+
command?: string[]
43+
}

0 commit comments

Comments
 (0)