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

122 lines (121 loc) 5.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extendAngularEslintJson = void 0; exports.createEsLintConfiguration = createEsLintConfiguration; const devkit_1 = require("@nx/devkit"); const string_utils_1 = require("@nx/devkit/src/utils/string-utils"); /** * @deprecated Use tools from `@nx/eslint/src/generators/utils/eslint-file` instead. It will be removed in Nx v22. */ const extendAngularEslintJson = (json, options) => { const overrides = [ { ...json.overrides[0], files: ['*.ts'], extends: [ ...(json.overrides[0].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: {}, }, ]; return { ...json, overrides, }; }; exports.extendAngularEslintJson = extendAngularEslintJson; /** * @deprecated Use {@link extendAngularEslintJson} instead. It will be removed in Nx v22. */ function createEsLintConfiguration(tree, options) { const rootConfig = `${(0, devkit_1.offsetFromRoot)(options.projectRoot)}.eslintrc.json`; // Include all project files to be linted (since they are turned off in the root eslintrc file). const ignorePatterns = ['!**/*']; const configJson = { extends: [rootConfig], ignorePatterns, overrides: [ { files: ['*.ts'], extends: [ 'plugin:@nx/angular', 'plugin:@angular-eslint/template/process-inline-templates', ], /** * NOTE: We no longer set parserOptions.project by default when creating new projects. * * We have observed that users rarely add rules requiring type-checking to their Nx workspaces, and therefore * do not actually need the capabilites which parserOptions.project provides. When specifying parserOptions.project, * typescript-eslint needs to create full TypeScript Programs for you. When omitting it, it can perform a simple * parse (and AST tranformation) of the source files it encounters during a lint run, which is much faster and much * less memory intensive. * * In the rare case that users attempt to add rules requiring type-checking to their setup later on (and haven't set * parserOptions.project), the executor will attempt to look for the particular error typescript-eslint gives you * and provide feedback to the user. */ parserOptions: !options.setParserOptionsProject ? undefined : { project: [`${options.projectRoot}/tsconfig.*?.json`], }, 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, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, '.eslintrc.json'), configJson); }