or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdindex.mdjest-runner.mdwatch-plugin.md
tile.json

watch-plugin.mddocs/

0

# Watch Plugin

1

2

Interactive Jest watch plugin that allows toggling ESLint's --fix option during development without restarting the watch process.

3

4

## Capabilities

5

6

### ESLintWatchFixPlugin Class

7

8

Jest watch plugin class that provides interactive --fix option toggling.

9

10

```javascript { .api }

11

/**

12

* Jest watch plugin for toggling ESLint --fix option during watch mode

13

* Requires Jest 23.0.0 or higher

14

*/

15

class ESLintWatchFixPlugin {

16

/**

17

* Creates new watch plugin instance

18

* @param options - Plugin initialization options

19

*/

20

constructor(options: WatchPluginOptions);

21

22

/**

23

* Executes when plugin key is pressed - toggles fix option

24

* @returns Promise<boolean> - Always returns true to continue watch mode

25

*/

26

async run(): Promise<boolean>;

27

28

/**

29

* Provides usage information for Jest watch mode display

30

* @returns Object with key and prompt for watch mode menu

31

*/

32

getUsageInfo(): WatchPluginUsageInfo;

33

}

34

35

interface WatchPluginOptions {

36

/** Output stream for plugin messages */

37

stdout: NodeJS.WriteStream;

38

/** Plugin configuration */

39

config: {

40

/** Key to press for activating plugin (default: 'F') */

41

key?: string;

42

};

43

}

44

45

interface WatchPluginUsageInfo {

46

/** Key to display in watch mode menu */

47

key: string;

48

/** Description text for watch mode menu */

49

prompt: string;

50

}

51

```

52

53

**Usage Examples:**

54

55

```javascript

56

// jest.config.js - Adding watch plugin

57

module.exports = {

58

projects: [

59

{

60

runner: 'jest-runner-eslint',

61

displayName: 'lint',

62

testMatch: ['<rootDir>/src/**/*.js'],

63

},

64

],

65

watchPlugins: [

66

'jest-runner-eslint/watch-fix',

67

],

68

};

69

70

// Custom key configuration

71

module.exports = {

72

watchPlugins: [

73

['jest-runner-eslint/watch-fix', { key: 'L' }],

74

],

75

};

76

```

77

78

### Watch Plugin Entry Point

79

80

Module export for the watch plugin functionality.

81

82

```javascript { .api }

83

/**

84

* Watch plugin module export

85

* Re-exports ESLintWatchFixPlugin from build directory

86

*/

87

const ESLintWatchFixPlugin = require("jest-runner-eslint/watch-fix");

88

```

89

90

**Usage Examples:**

91

92

```javascript

93

// Direct instantiation (not typically needed)

94

const ESLintWatchFixPlugin = require("jest-runner-eslint/watch-fix");

95

96

const plugin = new ESLintWatchFixPlugin({

97

stdout: process.stdout,

98

config: { key: 'F' }

99

});

100

101

// Get current usage info

102

const usageInfo = plugin.getUsageInfo();

103

console.log(`Press ${usageInfo.key} to ${usageInfo.prompt}`);

104

105

// Toggle fix option

106

await plugin.run();

107

```

108

109

### Configuration Override System

110

111

Internal system for managing fix option overrides during watch mode.

112

113

```javascript { .api }

114

/**

115

* Configuration override manager for watch mode fix option

116

* Singleton instance that manages global fix state

117

*/

118

class ConfigOverrides {

119

/**

120

* Sets the fix option override value

121

* @param fix - Boolean value to set as fix override

122

*/

123

setFix(fix: boolean): void;

124

125

/**

126

* Gets the current fix option override value

127

* @returns Current fix override value or undefined if not set

128

*/

129

getFix(): boolean | undefined;

130

}

131

132

/** Singleton instance of ConfigOverrides */

133

const configOverrides: ConfigOverrides;

134

```

135

136

**Usage Examples:**

137

138

```javascript

139

// Internal usage by watch plugin

140

const configOverrides = require('./utils/configOverrides');

141

142

// Toggle current fix state

143

const currentFix = configOverrides.getFix();

144

configOverrides.setFix(!currentFix);

145

146

// Check fix state in runner

147

const fixOverride = configOverrides.getFix();

148

const shouldFix = fixOverride !== undefined ? fixOverride : baseConfig.fix;

149

```

150

151

### Watch Mode Integration

152

153

The watch plugin integrates with Jest's watch mode system to provide interactive ESLint configuration.

154

155

**Key Features:**

156

157

- **Dynamic Fix Toggle**: Toggle --fix option without restarting Jest watch mode

158

- **Visual Feedback**: Shows current fix state in watch mode prompt

159

- **Persistent State**: Fix override persists throughout watch session

160

- **Configurable Key**: Customize the key used to trigger the plugin (default: 'F')

161

162

**Watch Mode Display:**

163

164

```text

165

Watch Usage

166

› Press f to run only failed tests.

167

› Press o to only run tests related to changed files.

168

› Press F to toggle ESLint --fix (disabled).

169

› Press q to quit watch mode.

170

```

171

172

The prompt text updates based on current fix state:

173

- `"override ESLint --fix"` - When no override is set

174

- `"toggle ESLint --fix (disabled)"` - When fix is explicitly disabled

175

- `"toggle ESLint --fix (enabled)"` - When fix is explicitly enabled