This capability handles adding ESLint configuration to existing Angular projects that don't already have it configured.
Adds ESLint configuration to an existing Angular CLI project within a workspace.
/**
* Add ESLint to an Angular CLI project
* @param schema - Configuration options for adding ESLint
* @returns Schematic rule that adds ESLint to the project
*/
function addESLintToProject(schema: AddESLintToProjectSchema): Rule;
interface AddESLintToProjectSchema {
/** Name of the project to add ESLint to. If not specified, attempts to determine automatically */
project?: string;
/** Whether to set parserOptions.project in the ESLint config */
setParserOptionsProject?: boolean;
}Usage Examples:
# Add ESLint to a specific project
ng generate @angular-eslint/schematics:add-eslint-to-project --project=my-app
# Add ESLint with automatic project detection
ng generate @angular-eslint/schematics:add-eslint-to-project
# Add ESLint with parserOptions.project enabled
ng generate @angular-eslint/schematics:add-eslint-to-project --project=my-app --setParserOptionsProjectWhen the project option is not specified, the schematic uses intelligent project detection:
angular.json/**
* Determine target project name when not explicitly specified
* @param tree - The file tree
* @param maybeProject - Optional project name hint
* @returns Project name or null if not determinable
*/
function determineTargetProjectName(tree: Tree, maybeProject?: string): string | null;The add-eslint-to-project schematic performs the following operations:
Creates a project-specific ESLint configuration file that:
Adds a lint target to the project configuration:
/**
* Add ESLint lint target to Angular project configuration
* @param projectName - Name of the project
* @param targetName - Name for the lint target ('eslint' or 'lint')
* @returns Schematic rule that adds the target
*/
function addESLintTargetToProject(projectName: string, targetName: 'eslint' | 'lint'): Rule;The schematic automatically detects and matches the configuration format used by the workspace:
/**
* Determine whether to use ESLint flat config or legacy eslintrc
* @param tree - The file tree
* @param existingJson - Optional existing configuration to check
* @returns true if flat config should be used
*/
function shouldUseFlatConfig(tree: Tree, existingJson?: Record<string, unknown>): boolean;
/**
* Find existing root ESLint config file path
* @param tree - The file tree
* @returns Config file path or null if not found
*/
function resolveRootESLintConfigPath(tree: Tree): string | null;When setParserOptionsProject is enabled, the generated configuration includes TypeScript project references:
parserOptions: {
project: ['tsconfig.json', 'tsconfig.app.json', 'tsconfig.spec.json']
}This enables type-aware ESLint rules but may impact linting performance.
The schematic automatically detects project types and applies appropriate configurations:
type ProjectType = 'application' | 'library';
/**
* Extract targets/architect config from project configuration
* @param projectConfig - Project configuration object
* @returns TargetsConfig or null if not found
*/
function getTargetsConfigFromProject(projectConfig: any): TargetsConfig | null;
type TargetsConfig = Record<string, { builder: string; options: unknown }>;The schematic supports both legacy and modern ESLint configuration formats:
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"rules": {}
},
{
"files": ["*.html"],
"rules": {}
}
]
}import baseConfig from '../../eslint.config.js';
export default [
...baseConfig,
{
files: ['**/*.ts'],
rules: {}
},
{
files: ['**/*.html'],
rules: {}
}
];The schematic includes robust error handling for common scenarios:
interface AddESLintToProjectSchema {
project?: string;
setParserOptionsProject?: boolean;
}
type TargetsConfig = Record<string, { builder: string; options: unknown }>;
type ProjectType = 'application' | 'library';