Utilities for working with ESLint Flat Config format, providing object-based syntax and monorepo configuration management.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core functionality for converting object-based ESLint rules to flat config format, providing a more intuitive way to write ESLint configurations.
Converts object-based rule configurations to ESLint flat config arrays. This allows writing ESLint configs using objects instead of verbose arrays.
/**
* Converts object-based rule configurations to flat config arrays
* @param {Object} config - Object with file patterns as keys and rules as values
* @returns {Array<Object>} Array of ESLint flat config objects
*/
function matchToFlat(config);Parameters:
config (Object): Configuration object where keys are file patterns and values are rule objectsReturns:
Array of objects with files and rules properties matching ESLint flat config format.
Usage Examples:
const { matchToFlat } = require('@putout/eslint-flat');
// Basic transformation
const match = {
'bin/putout.mjs': {
'n/hashbang': 'off',
},
'**/register.mjs': {
'n/no-unsupported-features/node-builtins': 'off',
},
};
const result = matchToFlat(match);
console.log(result);
// Output:
// [
// {
// files: ['bin/putout.mjs'],
// rules: { 'n/hashbang': 'off' }
// },
// {
// files: ['**/register.mjs'],
// rules: { 'n/no-unsupported-features/node-builtins': 'off' }
// }
// ]
// Multiple rules per pattern
const complexMatch = {
'*.test.js': {
'jest/expect-expect': 'off',
'jest/no-disabled-tests': 'warn',
'complexity': ['error', 15],
},
};
const complexResult = matchToFlat(complexMatch);
// Result: [{ files: ['*.test.js'], rules: { 'jest/expect-expect': 'off', ... } }]Use in ESLint Configuration:
const { matchToFlat } = require('@putout/eslint-flat');
const { safeAlign } = require('eslint-plugin-putout/config');
const match = {
'src/**/*.js': {
'no-console': 'warn',
},
'test/**/*.js': {
'no-console': 'off',
},
};
module.exports = [
...safeAlign,
...matchToFlat(match),
];
// Export the match object for reuse
module.exports.match = match;This approach provides several benefits:
Install with Tessl CLI
npx tessl i tessl/npm-putout--eslint-flat