UNPKG

@nx-plugins/linter

Version:

The Nx Plugin for Linter that contains executors, generators, and utilities to use powerful Eslint capabilities.

51 lines 2.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addLinter = void 0; const tslib_1 = require("tslib"); const devkit_1 = require("@nrwl/devkit"); const create_eslint_1 = require("./create-eslint"); const linter_1 = require("@nrwl/linter"); const run_tasks_in_serial_1 = require("@nrwl/workspace/src/utilities/run-tasks-in-serial"); function addLinter(host, options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const lintTask = yield (0, linter_1.lintProjectGenerator)(host, { linter: linter_1.Linter.EsLint, project: options.project, tsConfigPaths: [ (0, devkit_1.joinPathFragments)(options.projectRoot, `tsconfig.${options.projectType}.json`), ], eslintFilePatterns: [`${options.projectRoot}/**/*.{ts,tsx,js,jsx}`], skipFormat: true, skipPackageJson: options.skipPackageJson }); const reactEslintJson = (0, create_eslint_1.createReactEslintJson)(options.projectRoot, options.setParserOptionsProject); (0, devkit_1.updateJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, '.eslintrc.json'), () => { var _a, _b, _c; // Find the override that handles both TS and JS files. const commonOverride = (_a = reactEslintJson.overrides) === null || _a === void 0 ? void 0 : _a.find((o) => ['*.ts', '*.tsx', '*.js', '*.jsx'].every((ext) => o.files.includes(ext))); if (commonOverride) { // Only set parserOptions.project if it already exists (defined by options.setParserOptionsProject) if ((_b = commonOverride.parserOptions) === null || _b === void 0 ? void 0 : _b.project) { commonOverride.parserOptions.project = [ `${options.projectRoot}/tsconfig(.*)?.json`, ]; } } (_c = reactEslintJson.extends) !== null && _c !== void 0 ? _c : (reactEslintJson.extends = []); if (typeof reactEslintJson.extends === 'string') { reactEslintJson.extends = [reactEslintJson.extends]; } if (!reactEslintJson.env) { reactEslintJson.env = {}; } if (options.unitTestRunner === 'jest') { reactEslintJson.env.jest = true; } return reactEslintJson; }); const installTask = (0, devkit_1.addDependenciesToPackageJson)(host, create_eslint_1.extraEslintDependencies.dependencies, create_eslint_1.extraEslintDependencies.devDependencies); return (0, run_tasks_in_serial_1.runTasksInSerial)(lintTask, installTask); }); } exports.addLinter = addLinter; //# sourceMappingURL=add-linter.js.map