From b71b9c8b2b00f1db6925c44b9acd8316c51a2bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Sat, 29 Jun 2019 23:08:09 +0300 Subject: [PATCH] refactor: warn about long arguments string only once --- src/generateTasks.js | 3 ++- src/resolveTaskFn.js | 21 --------------------- src/runAll.js | 30 +++++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/generateTasks.js b/src/generateTasks.js index a17300f94..885a651bb 100644 --- a/src/generateTasks.js +++ b/src/generateTasks.js @@ -1,8 +1,9 @@ 'use strict' -const path = require('path') const micromatch = require('micromatch') const pathIsInside = require('path-is-inside') +const path = require('path') + const { getConfig } = require('./getConfig') const debug = require('debug')('lint-staged:gen-tasks') diff --git a/src/resolveTaskFn.js b/src/resolveTaskFn.js index c8e32fb0a..bd93bd31e 100644 --- a/src/resolveTaskFn.js +++ b/src/resolveTaskFn.js @@ -26,14 +26,6 @@ function execLinter(bin, args, execaOptions) { return execa(bin, args, { ...execaOptions }) } -/** - * https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x - * https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation - * https://unix.stackexchange.com/a/120652 - */ -const MAX_ARG_LENGTH = - (process.platform === 'darwin' && 262144) || (process.platform === 'win32' && 8191) || 131072 - const successMsg = linter => `${symbols.success} ${linter} passed!` /** @@ -104,19 +96,6 @@ module.exports = function resolveTaskFn(options) { const tasks = linters.map(command => { const { bin, args } = findBin(command) - const argLength = args.join(' ').length - if (argLength > MAX_ARG_LENGTH) { - console.warn(dedent`${symbols.warning} ${chalk.yellow( - `${chalk.bold( - command - )} received an argument string of ${argLength} characters, and might not run correctly on your platform. -It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please read: -https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands - ` - )} - `) - } - // If `linter` is a function, args already include `pathsToLint`. const argsWithPaths = fnLinter ? args : args.concat(pathsToLint) diff --git a/src/runAll.js b/src/runAll.js index 26de7923b..3c66abcf1 100644 --- a/src/runAll.js +++ b/src/runAll.js @@ -1,15 +1,27 @@ 'use strict' -const generateTasks = require('./generateTasks') -const git = require('./gitWorkflow') -const getStagedFiles = require('./getStagedFiles') +const chalk = require('chalk') +const dedent = require('dedent') const Listr = require('listr') const has = require('lodash/has') +const symbols = require('log-symbols') + +const generateTasks = require('./generateTasks') +const getStagedFiles = require('./getStagedFiles') +const git = require('./gitWorkflow') const makeCmdTasks = require('./makeCmdTasks') const resolveGitDir = require('./resolveGitDir') const debug = require('debug')('lint-staged:run') +/** + * https://serverfault.com/questions/69430/what-is-the-maximum-length-of-a-command-line-in-mac-os-x + * https://support.microsoft.com/en-us/help/830473/command-prompt-cmd-exe-command-line-string-limitation + * https://unix.stackexchange.com/a/120652 + */ +const MAX_ARG_LENGTH = + (process.platform === 'darwin' && 262144) || (process.platform === 'win32' && 8191) || 131072 + /** * Executes all tasks and either resolves or rejects the promise * @param config {Object} @@ -39,6 +51,18 @@ module.exports = async function runAll(config) { debug('Loaded list of staged files in git:\n%O', files) + const argLength = files.join(' ').length + if (argLength > MAX_ARG_LENGTH) { + console.warn( + dedent`${symbols.warning} ${chalk.yellow( + `lint-staged generated an argument string of ${argLength} characters, and commands might not run correctly on your platform. +It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please read: +https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands + ` + )}` + ) + } + const tasks = (await generateTasks(config, gitDir, files)).map(task => ({ title: `Running tasks for ${task.pattern}`, task: async () =>