or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

executor.mdgenerators.mdindex.mdplugin.mdutilities.md

generators.mddocs/

0

# Project Generators

1

2

Generators for setting up and configuring ESLint in Nx projects and workspaces, providing automated configuration management for both individual projects and workspace-wide setups.

3

4

## Core Imports

5

6

```typescript

7

import { lintProjectGenerator, lintInitGenerator, Linter, LinterType } from '@nx/eslint';

8

import type { Tree, GeneratorCallback } from '@nx/devkit';

9

```

10

11

## Capabilities

12

13

### Lint Project Generator

14

15

Main generator for adding ESLint configuration to a specific project within an Nx workspace.

16

17

```typescript { .api }

18

/**

19

* Generates lint configuration for a specific project

20

* @param tree - Nx DevKit tree for file system operations

21

* @param options - Configuration options for the generator

22

* @returns Generator callback for async operations

23

*/

24

function lintProjectGenerator(tree: Tree, options: LintProjectOptions): GeneratorCallback;

25

26

interface LintProjectOptions {

27

/** Name of the project to configure */

28

project: string;

29

/** Linter type to use */

30

linter?: Linter | LinterType;

31

/** File patterns to include in linting */

32

eslintFilePatterns?: string[];

33

/** Paths to TypeScript configuration files */

34

tsConfigPaths?: string[];

35

/** Skip formatting files after generation */

36

skipFormat: boolean;

37

/** Enable parser options project for type-aware rules */

38

setParserOptionsProject?: boolean;

39

/** Skip updating package.json */

40

skipPackageJson?: boolean;

41

/** Unit test runner being used */

42

unitTestRunner?: string;

43

/** Whether this is the root project */

44

rootProject?: boolean;

45

/** Keep existing dependency versions */

46

keepExistingVersions?: boolean;

47

/** Add Nx plugin for project inference */

48

addPlugin?: boolean;

49

/** ESLint configuration format to use */

50

eslintConfigFormat?: 'mjs' | 'cjs';

51

}

52

```

53

54

**Usage Examples:**

55

56

```typescript

57

import { Tree } from '@nx/devkit';

58

import { lintProjectGenerator } from '@nx/eslint';

59

60

// Basic project setup

61

await lintProjectGenerator(tree, {

62

project: 'my-lib',

63

skipFormat: false

64

});

65

66

// Advanced configuration

67

await lintProjectGenerator(tree, {

68

project: 'my-app',

69

linter: 'eslint',

70

eslintFilePatterns: ['src/**/*.ts', 'src/**/*.tsx'],

71

setParserOptionsProject: true,

72

eslintConfigFormat: 'mjs',

73

addPlugin: true,

74

keepExistingVersions: false

75

});

76

77

// Root project setup

78

await lintProjectGenerator(tree, {

79

project: 'workspace-root',

80

rootProject: true,

81

eslintFilePatterns: ['./src'],

82

skipFormat: false

83

});

84

```

85

86

### Lint Init Generator

87

88

Generator for initializing ESLint in the workspace, setting up global configuration and dependencies.

89

90

```typescript { .api }

91

/**

92

* Initializes ESLint plugin in the workspace

93

* @param tree - Nx DevKit tree for file system operations

94

* @param options - Initialization options

95

* @returns Promise resolving to generator callback

96

*/

97

function lintInitGenerator(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;

98

99

interface LinterInitOptions {

100

/** Skip updating package.json dependencies */

101

skipPackageJson?: boolean;

102

/** Keep existing dependency versions */

103

keepExistingVersions?: boolean;

104

/** Update package.json scripts */

105

updatePackageScripts?: boolean;

106

/** Add Nx plugin for automatic inference */

107

addPlugin?: boolean;

108

/** ESLint configuration format */

109

eslintConfigFormat?: 'mjs' | 'cjs';

110

}

111

```

112

113

**Usage Examples:**

114

115

```typescript

116

import { lintInitGenerator } from '@nx/eslint';

117

118

// Basic workspace initialization

119

await lintInitGenerator(tree, {

120

addPlugin: true

121

});

122

123

// Skip package.json updates

124

await lintInitGenerator(tree, {

125

skipPackageJson: true,

126

addPlugin: false,

127

eslintConfigFormat: 'mjs'

128

});

129

130

// Keep existing versions

131

await lintInitGenerator(tree, {

132

keepExistingVersions: true,

133

updatePackageScripts: true

134

});

135

```

136

137

### Internal Generator Function

138

139

Internal implementation providing additional configuration options.

140

141

```typescript { .api }

142

/**

143

* Internal lint project generator with extended options

144

* @param tree - Nx DevKit tree

145

* @param options - Extended configuration options

146

* @returns Promise resolving to generator callback

147

*/

148

function lintProjectGeneratorInternal(

149

tree: Tree,

150

options: LintProjectOptions & {

151

addExplicitTargets?: boolean;

152

addPackageJsonDependencyChecks?: boolean;

153

}

154

): Promise<GeneratorCallback>;

155

```

156

157

### ESLint Initialization Function

158

159

Core initialization logic for ESLint setup.

160

161

```typescript { .api }

162

/**

163

* Core ESLint initialization function

164

* @param tree - Nx DevKit tree

165

* @param options - Initialization options

166

* @returns Promise resolving to generator callback

167

*/

168

function initEsLint(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;

169

```

170

171

## Generator Configuration

172

173

### Available Generators

174

175

The package provides the following configured generators via `generators.json`:

176

177

- **`init`**: Set up the ESLint plugin (hidden)

178

- **`workspace-rules-project`**: Create workspace lint rules project (hidden)

179

- **`workspace-rule`**: Create new workspace ESLint rule

180

- **`convert-to-flat-config`**: Convert workspace to ESLint flat config

181

- **`convert-to-inferred`**: Convert to use plugin inference

182

183

### Generator Schemas

184

185

Each generator includes JSON schema validation for options:

186

187

```typescript { .api }

188

interface GeneratorSchema {

189

factory: string;

190

schema: string;

191

description: string;

192

hidden?: boolean;

193

}

194

```

195

196

**Usage in nx.json or project.json:**

197

198

```json

199

{

200

"generators": {

201

"@nx/eslint:lint-project": {

202

"linter": "eslint",

203

"eslintConfigFormat": "mjs"

204

}

205

}

206

}

207

```