just-scripts
Version:
Just Stack Scripts
40 lines • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.eslintTask = void 0;
const just_task_1 = require("just-task");
const just_scripts_utils_1 = require("just-scripts-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, } = options;
const eslintCmd = 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 || just_task_1.resolveCwd('.eslintrc', { extensions: ['.js', '.cjs', '.yaml', '.yml', '.json'] });
if (eslintCmd && eslintConfigPath && fs.existsSync(eslintConfigPath)) {
const eslintIgnorePath = ignorePath || 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] : []),
'--color',
];
just_task_1.logger.info(just_scripts_utils_1.encodeArgs(eslintArgs).join(' '));
return just_scripts_utils_1.spawn(process.execPath, eslintArgs, { stdio: 'inherit', ...(timing && { env: { TIMING: '1' } }) });
}
else {
return Promise.resolve();
}
};
}
exports.eslintTask = eslintTask;
//# sourceMappingURL=eslintTask.js.map