or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

directory-config.mdindex.mdmonorepo-config.mdtransformation.md

transformation.mddocs/

0

# Configuration Transformation

1

2

Core functionality for converting object-based ESLint rules to flat config format, providing a more intuitive way to write ESLint configurations.

3

4

## Capabilities

5

6

### matchToFlat Function

7

8

Converts object-based rule configurations to ESLint flat config arrays. This allows writing ESLint configs using objects instead of verbose arrays.

9

10

```javascript { .api }

11

/**

12

* Converts object-based rule configurations to flat config arrays

13

* @param {Object} config - Object with file patterns as keys and rules as values

14

* @returns {Array<Object>} Array of ESLint flat config objects

15

*/

16

function matchToFlat(config);

17

```

18

19

**Parameters:**

20

- `config` (Object): Configuration object where keys are file patterns and values are rule objects

21

22

**Returns:**

23

Array of objects with `files` and `rules` properties matching ESLint flat config format.

24

25

**Usage Examples:**

26

27

```javascript

28

const { matchToFlat } = require('@putout/eslint-flat');

29

30

// Basic transformation

31

const match = {

32

'bin/putout.mjs': {

33

'n/hashbang': 'off',

34

},

35

'**/register.mjs': {

36

'n/no-unsupported-features/node-builtins': 'off',

37

},

38

};

39

40

const result = matchToFlat(match);

41

console.log(result);

42

// Output:

43

// [

44

// {

45

// files: ['bin/putout.mjs'],

46

// rules: { 'n/hashbang': 'off' }

47

// },

48

// {

49

// files: ['**/register.mjs'],

50

// rules: { 'n/no-unsupported-features/node-builtins': 'off' }

51

// }

52

// ]

53

54

// Multiple rules per pattern

55

const complexMatch = {

56

'*.test.js': {

57

'jest/expect-expect': 'off',

58

'jest/no-disabled-tests': 'warn',

59

'complexity': ['error', 15],

60

},

61

};

62

63

const complexResult = matchToFlat(complexMatch);

64

// Result: [{ files: ['*.test.js'], rules: { 'jest/expect-expect': 'off', ... } }]

65

```

66

67

**Use in ESLint Configuration:**

68

69

```javascript

70

const { matchToFlat } = require('@putout/eslint-flat');

71

const { safeAlign } = require('eslint-plugin-putout/config');

72

73

const match = {

74

'src/**/*.js': {

75

'no-console': 'warn',

76

},

77

'test/**/*.js': {

78

'no-console': 'off',

79

},

80

};

81

82

module.exports = [

83

...safeAlign,

84

...matchToFlat(match),

85

];

86

87

// Export the match object for reuse

88

module.exports.match = match;

89

```

90

91

This approach provides several benefits:

92

- More readable configuration structure

93

- Easier to maintain and modify rules

94

- Better organization of file-specific rules

95

- Ability to export the match object for reuse in monorepos