|
17 | 17 | * under the License. |
18 | 18 | */ |
19 | 19 |
|
20 | | -import { run, combineErrors } from '@kbn/dev-utils'; |
| 20 | +import { run, combineErrors, createFlagError } from '@kbn/dev-utils'; |
21 | 21 | import * as Eslint from './eslint'; |
22 | 22 | import * as Sasslint from './sasslint'; |
23 | 23 | import { getFilesForCommit, checkFileCasing } from './precommit_hook'; |
24 | 24 |
|
25 | 25 | run( |
26 | 26 | async ({ log, flags }) => { |
27 | | - const files = await getFilesForCommit(); |
| 27 | + const files = await getFilesForCommit(flags.ref); |
28 | 28 | const errors = []; |
29 | 29 |
|
| 30 | + const maxFilesCount = flags['max-files'] |
| 31 | + ? Number.parseInt(String(flags['max-files']), 10) |
| 32 | + : undefined; |
| 33 | + if (maxFilesCount !== undefined && (!Number.isFinite(maxFilesCount) || maxFilesCount < 1)) { |
| 34 | + throw createFlagError('expected --max-files to be a number greater than 0'); |
| 35 | + } |
| 36 | + |
| 37 | + if (maxFilesCount && files.length > maxFilesCount) { |
| 38 | + log.warning( |
| 39 | + `--max-files is set to ${maxFilesCount} and ${files.length} were discovered. The current script execution will be skipped.` |
| 40 | + ); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
30 | 44 | try { |
31 | 45 | await checkFileCasing(log, files); |
32 | 46 | } catch (error) { |
|
52 | 66 | }, |
53 | 67 | { |
54 | 68 | description: ` |
55 | | - Run checks on files that are staged for commit |
| 69 | + Run checks on files that are staged for commit by default |
56 | 70 | `, |
57 | 71 | flags: { |
58 | 72 | boolean: ['fix'], |
| 73 | + string: ['max-files', 'ref'], |
59 | 74 | default: { |
60 | 75 | fix: false, |
61 | 76 | }, |
62 | 77 | help: ` |
63 | 78 | --fix Execute eslint in --fix mode |
| 79 | + --max-files Max files number to check against. If exceeded the script will skip the execution |
| 80 | + --ref Run checks against any git ref files (example HEAD or <commit_sha>) instead of running against staged ones |
64 | 81 | `, |
65 | 82 | }, |
66 | 83 | } |
|
0 commit comments