UNPKG

@beemo/driver-eslint

Version:
87 lines (65 loc) 2.22 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const fs = require('fs'); const core = require('@beemo/core'); const event = require('@boost/event'); const _interopDefault = e => e && e.__esModule ? e : { default: e }; const fs__default = /*#__PURE__*/_interopDefault(fs); // Success: Writes warnings to stdout // Failure: Writes failures to stderr class ESLintDriver extends core.Driver { constructor(...args) { super(...args); this.name = '@beemo/driver-eslint'; this.onCreateIgnoreFile = new event.Event('create-ignore-file'); this.handleCreateIgnoreFile = (context, configPath, config) => { if (!config.ignore) { return; } if (!Array.isArray(config.ignore)) { throw new TypeError(this.tool.msg('errors:eslintIgnoreInvalid')); } const ignorePath = configPath.parent().append('.eslintignore'); const _config$ignore = config.ignore, ignore = _config$ignore === void 0 ? [] : _config$ignore; this.onCreateIgnoreFile.emit([context, ignorePath, { ignore }]); fs__default.default.writeFileSync(ignorePath.path(), ignore.join('\n')); // Add to context so that it can be automatically cleaned up context.addConfigPath('eslint', ignorePath); // Delete the property else ESLint throws an error // eslint-disable-next-line no-param-reassign delete config.ignore; }; } bootstrap() { this.setMetadata({ bin: 'eslint', configName: '.eslintrc.js', description: this.tool.msg('app:eslintDescription'), title: 'ESLint' }); this.onCreateConfigFile.listen(this.handleCreateIgnoreFile); } /** * ESLint writes warnings to stdout, so we need to display * both stdout and stderr on failure. */ processFailure(error) { const stderr = error.stderr, stdout = error.stdout; if (stderr) { this.setOutput('stderr', stderr); } if (stdout) { this.setOutput('stdout', stdout); } } /** * If an "ignore" property exists in the ESLint config, create an ".eslintignore" file. */ } exports.ESLintDriver = ESLintDriver; //# sourceMappingURL=ESLintDriver.js.map