UNPKG

909 BJavaScriptView Raw
1import { constants, promises as fs } from 'fs'
2
3import debug from 'debug'
4
5import { invalidOption } from './messages.js'
6import { InvalidOptionsError } from './symbols.js'
7
8const debugLog = debug('lint-staged:validateOptions')
9
10/**
11 * Validate lint-staged options, either from the Node.js API or the command line flags.
12 * @param {*} options
13 * @param {boolean|string} [options.shell] - Skip parsing of tasks for better shell support
14 *
15 * @throws {InvalidOptionsError}
16 */
17export const validateOptions = async (options = {}, logger) => {
18 debugLog('Validating options...')
19
20 /** Ensure the passed shell option is executable */
21 if (typeof options.shell === 'string') {
22 try {
23 await fs.access(options.shell, constants.X_OK)
24 } catch (error) {
25 logger.error(invalidOption('shell', options.shell, error.message))
26 throw InvalidOptionsError
27 }
28 }
29
30 debugLog('Validated options!')
31}