From eb6088bca6e2e69f5b8a8951a7ca0ccce336a4c5 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 11 May 2024 15:05:14 +0700 Subject: [PATCH] Fix flat config Closes #358 --- index.js | 59 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index c88288b..054a5bd 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,9 @@ const path = require('node:path'); const importModules = require('import-modules'); +const {name, version} = require('./package.json'); -const rules = { +const recommendedRules = { 'ava/assertion-arguments': 'error', 'ava/hooks-order': 'error', 'ava/max-asserts': [ @@ -36,31 +37,39 @@ const rules = { 'ava/use-true-false': 'error', }; -module.exports = { +const plugin = { + meta: { + name, + version, + }, rules: importModules(path.resolve(__dirname, 'rules'), {camelize: false}), - configs: { - recommended: { - env: { - es6: true, - }, - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - }, - plugins: [ - 'ava', - ], - rules: { - ...rules, - }, + configs: {}, +}; + +Object.assign(plugin.configs, { + recommended: { + env: { + es6: true, }, - 'flat/recommended': { - plugins: { - ava: 'ava', - }, - rules: { - ...rules, - }, + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + plugins: [ + 'ava', + ], + rules: { + ...recommendedRules, }, }, -}; + 'flat/recommended': { + plugins: { + ava: plugin, + }, + rules: { + ...recommendedRules, + }, + }, +}); + +module.exports = plugin;