UNPKG

@nx/angular

Version:

The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: - Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, Playwright and Cypre

141 lines (140 loc) 6.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addLintingGenerator = addLintingGenerator; const devkit_1 = require("@nx/devkit"); const string_utils_1 = require("@nx/devkit/src/utils/string-utils"); const eslint_1 = require("@nx/eslint"); const global_eslint_config_1 = require("@nx/eslint/src/generators/init/global-eslint-config"); const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file"); const add_angular_eslint_dependencies_1 = require("./lib/add-angular-eslint-dependencies"); const buildable_project_1 = require("./lib/buildable-project"); const flat_config_1 = require("@nx/eslint/src/utils/flat-config"); async function addLintingGenerator(tree, options) { const tasks = []; const rootProject = options.projectRoot === '.' || options.projectRoot === ''; const lintTask = await (0, eslint_1.lintProjectGenerator)(tree, { linter: 'eslint', project: options.projectName, tsConfigPaths: [ (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.app.json'), ], unitTestRunner: options.unitTestRunner, setParserOptionsProject: options.setParserOptionsProject, skipFormat: true, rootProject: rootProject, addPlugin: options.addPlugin ?? false, addExplicitTargets: true, skipPackageJson: options.skipPackageJson, }); tasks.push(lintTask); if ((0, eslint_file_1.isEslintConfigSupported)(tree)) { const eslintFile = (0, eslint_file_1.findEslintFile)(tree, options.projectRoot); // keep parser options if they exist const hasParserOptions = tree .read((0, devkit_1.joinPathFragments)(options.projectRoot, eslintFile), 'utf8') .includes(`${options.projectRoot}/tsconfig.*?.json`); if ((0, flat_config_1.useFlatConfig)(tree)) { (0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(tree, options.projectRoot, 'flat/angular'); (0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(tree, options.projectRoot, 'flat/angular-template'); (0, eslint_file_1.addOverrideToLintConfig)(tree, options.projectRoot, { files: ['*.ts'], rules: { '@angular-eslint/directive-selector': [ 'error', { type: 'attribute', prefix: (0, string_utils_1.camelize)(options.prefix), style: 'camelCase', }, ], '@angular-eslint/component-selector': [ 'error', { type: 'element', prefix: (0, string_utils_1.dasherize)(options.prefix), style: 'kebab-case', }, ], }, }); (0, eslint_file_1.addOverrideToLintConfig)(tree, options.projectRoot, { files: ['*.html'], rules: {}, }); } else { (0, eslint_file_1.replaceOverridesInLintConfig)(tree, options.projectRoot, [ ...(rootProject ? [global_eslint_config_1.typeScriptOverride, global_eslint_config_1.javaScriptOverride] : []), { files: ['*.ts'], ...(hasParserOptions ? { parserOptions: { project: [`${options.projectRoot}/tsconfig.*?.json`], }, } : {}), extends: [ 'plugin:@nx/angular', 'plugin:@angular-eslint/template/process-inline-templates', ], rules: { '@angular-eslint/directive-selector': [ 'error', { type: 'attribute', prefix: (0, string_utils_1.camelize)(options.prefix), style: 'camelCase', }, ], '@angular-eslint/component-selector': [ 'error', { type: 'element', prefix: (0, string_utils_1.dasherize)(options.prefix), style: 'kebab-case', }, ], }, }, { files: ['*.html'], extends: ['plugin:@nx/angular-template'], /** * Having an empty rules object present makes it more obvious to the user where they would * extend things from if they needed to */ rules: {}, }, ...((0, buildable_project_1.isBuildableLibraryProject)(tree, options.projectName) ? [ { files: ['*.json'], parser: 'jsonc-eslint-parser', rules: { '@nx/dependency-checks': [ 'error', { // With flat configs, we don't want to include imports in the eslint js/cjs/mjs files to be checked ignoredFiles: [ '{projectRoot}/eslint.config.{js,cjs,mjs}', ], }, ], }, }, ] : []), ]); } } if (!options.skipPackageJson) { const installTask = (0, add_angular_eslint_dependencies_1.addAngularEsLintDependencies)(tree, options.projectName); tasks.push(installTask); } if (!options.skipFormat) { await (0, devkit_1.formatFiles)(tree); } return (0, devkit_1.runTasksInSerial)(...tasks); } exports.default = addLintingGenerator;