UNPKG

@procore/core-scripts

Version:

A CLI to enhance your development experience

72 lines 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = require("@oclif/command"); const core_1 = require("@oclif/core"); const eslint_1 = require("eslint"); const BaseCommand_1 = require("../../BaseCommand"); const config_1 = require("../../eslint/config"); class LintEslintCommand extends BaseCommand_1.BaseCommand { async run() { // eslint-disable-next-line no-shadow const { flags, args } = this.parse(LintEslintCommand); const baseEslintConfig = (0, config_1.createEslintConfig)(); const eslintConfig = this.workspace.procoreConfig.eslintOverride ? this.workspace.procoreConfig.eslintOverride(baseEslintConfig) : baseEslintConfig; let inputs; if (args.input) { inputs = [...args.input.split(',')]; } else { inputs = ['src']; } this.workspace.writeFileSync('.eslintrc.json', JSON.stringify(eslintConfig, null, 2)); this.workspace.writeFileSync('prettier.config.js', "module.exports = require('@procore/core-scripts/configs/prettier.config');\n"); const cli = new eslint_1.ESLint({ baseConfig: eslintConfig, cwd: this.workspace.context, extensions: ['.ts', '.tsx', '.js', '.jsx'], fix: flags.fix, fixTypes: flags.fixTypes, useEslintrc: false, }); // TODO: Remove this casting as CLIEngine.Options once @types/eslint includes // "fixTypes" in the definition for CLIEngine.Options core_1.CliUx.ux.action.start('Linting'); const report = await cli.lintFiles(inputs); core_1.CliUx.ux.action.stop(); if (flags.fix) { eslint_1.ESLint.outputFixes(report); } const formatter = await cli.loadFormatter(); this.log(await formatter.format(report)); const errorCount = report.reduce((acc, result) => { return acc + result.errorCount; }, 0); if (errorCount > 0) { this.exit(1); } } } LintEslintCommand.description = 'Runs the ESLint linter.'; LintEslintCommand.args = [ { name: 'input', required: false, description: 'Comma-delimited list of file and/or folder paths that the linter will run against.', }, ]; LintEslintCommand.flags = { fix: command_1.flags.boolean({ default: false, description: 'Automatically fix problems.', }), fixTypes: command_1.flags.string({ default: undefined, description: 'The types of lint errors/warnings to fix.', multiple: true, options: ['layout', 'problem', 'suggestion'], }), }; exports.default = LintEslintCommand; //# sourceMappingURL=eslint.js.map