Skip to content

Commit

Permalink
refactor: prepare the plugin for eslint's new 'flat-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Oct 27, 2023
1 parent 27ec31b commit 8c9e1ce
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
* @author sverweij
*/

module.exports = {
// eslint-disable-next-line budapestian/global-constant-pattern
const { name, version } = require("../package.json");

const plugin = {
meta: {
name,
version,
},
rules: {
"parameter-pattern": require("./rules/parameter-pattern-rule"),
"global-constant-pattern": require("./rules/global-constant-pattern-rule"),
"global-variable-pattern": require("./rules/global-variable-pattern-rule"),
"local-variable-pattern": require("./rules/local-variable-pattern-rule"),
},
configs: {
recommended: {
plugins: ["budapestian"],
rules: {
"budapestian/parameter-pattern": "error",
"budapestian/global-variable-pattern": "error",
"budapestian/local-variable-pattern": [
"error",
{ exceptions: ["i", "j", "k", "x", "y", "z"] },
],
"budapestian/global-constant-pattern": "error",
},
configs: {},
};

// see https://eslint.org/docs/latest/extend/plugin-migration-flat-config why
// configs is not defined directly in the plugin object
Object.assign(plugin.configs, {
recommended: {
plugins: ["budapestian"],
// the above documentation recommends to use plugins: { budapestian: plugin }
// however, eslint 8 does not like that:
// ESLint: 8.52.0
//
// TypeError: Converting circular structure to JSON
rules: {
"budapestian/parameter-pattern": "error",
"budapestian/global-variable-pattern": "error",
"budapestian/local-variable-pattern": [
"error",
{ exceptions: ["i", "j", "k", "x", "y", "z"] },
],
"budapestian/global-constant-pattern": "error",
},
},
};
});

module.exports = plugin;

0 comments on commit 8c9e1ce

Please sign in to comment.