UNPKG

just-scripts

Version:
49 lines 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.eslintTask = void 0; const just_task_1 = require("just-task"); const utils_1 = require("../utils"); const fs = require("fs"); function eslintTask(options = {}) { return function eslint() { const { files, configPath, ignorePath, fix, extensions, noEslintRc, maxWarnings, resolvePluginsPath, cache, cacheLocation, timing, outputFile, format, quiet, useFlatConfig, } = options; const eslintCmd = (0, just_task_1.resolve)('eslint/bin/eslint.js'); // Try all possible extensions in the order listed here: https://eslint.org/docs/user-guide/configuring#configuration-file-formats const eslintConfigPath = configPath || (0, just_task_1.resolveCwd)('.eslintrc', { extensions: ['.js', '.cjs', '.yaml', '.yml', '.json'] }); if (eslintCmd && eslintConfigPath && fs.existsSync(eslintConfigPath)) { const eslintIgnorePath = ignorePath || (0, just_task_1.resolveCwd)('.eslintignore'); const eslintArgs = [ eslintCmd, ...(files ? files : ['.']), ...['--ext', extensions ? extensions : '.js,.jsx,.ts,.tsx'], ...(noEslintRc ? '--no-eslintrc' : []), ...(eslintConfigPath ? ['--config', eslintConfigPath] : []), ...(eslintIgnorePath ? ['--ignore-path', eslintIgnorePath] : []), ...(resolvePluginsPath ? ['--resolve-plugins-relative-to', resolvePluginsPath] : []), ...(fix ? ['--fix'] : []), ...(maxWarnings !== undefined ? ['--max-warnings', `${maxWarnings}`] : []), ...(cache ? ['--cache'] : []), ...(cacheLocation ? ['--cache-location', cacheLocation] : []), ...(outputFile ? ['--output-file', outputFile] : []), ...(format ? ['--format', format] : []), ...(quiet ? ['--quiet'] : []), ...(options.reportUnusedDisableDirectives ? ['--report-unused-disable-directives'] : []), '--color', ]; const env = { ...process.env }; if (timing) { env.TIMING = '1'; } if (useFlatConfig !== undefined) { env.ESLINT_USE_FLAT_CONFIG = JSON.stringify(useFlatConfig); } just_task_1.logger.info((0, utils_1.encodeArgs)(eslintArgs).join(' ')); return (0, utils_1.spawn)(process.execPath, eslintArgs, { stdio: 'inherit', env }); } else { return Promise.resolve(); } }; } exports.eslintTask = eslintTask; //# sourceMappingURL=eslintTask.js.map