Skip to content

Commit

Permalink
feat: add pkg.meta, config.name for better DX (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add authored Sep 2, 2024
1 parent 4f9edc2 commit 2557d60
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
14 changes: 8 additions & 6 deletions packages/autofix/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ const all = require("./configs/all");
const recommended = require("./configs/recommended");
const unsafe = require("./configs/unsafe");
const rules = require("./rules");
const pkg = require("../package.json");

const pkg = {
const plugin = {
meta: { name: pkg.name, version: pkg.version },
configs: {
all,
recommended,
Expand All @@ -18,10 +20,10 @@ const pkg = {
rules
};

Object.assign(pkg.configs, {
"flat/all": { ...pkg.configs.all, plugins: { autofix: pkg }, rules: pkg.configs.all.rules },
"flat/recommended": { ...pkg.configs.recommended, plugins: { autofix: pkg }, rules: pkg.configs.recommended.rules },
"flat/unsafe": { ...pkg.configs.unsafe, plugins: { autofix: pkg }, rules: pkg.configs.unsafe.rules }
Object.assign(plugin.configs, {
"flat/all": { name: "eslint-plugin-autofix/all", ...plugin.configs.all, plugins: { autofix: plugin }, rules: plugin.configs.all.rules },
"flat/recommended": { name: "eslint-plugin-autofix/recommended", ...plugin.configs.recommended, plugins: { autofix: plugin }, rules: plugin.configs.recommended.rules },
"flat/unsafe": { name: "eslint-plugin-autofix/unsafe", ...plugin.configs.unsafe, plugins: { autofix: plugin }, rules: plugin.configs.unsafe.rules }
});

module.exports = pkg;
module.exports = plugin;
10 changes: 6 additions & 4 deletions packages/no-autofix/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

const all = require("./configs/all");
const rules = require("./rules");
const pkg = require("../package.json");

const pkg = {
const plugin = {
meta: { name: pkg.name, version: pkg.version },
configs: {
all
},
rules
};

Object.assign(pkg.configs, {
"flat/all": { plugins: { "no-autofix": pkg }, rules: pkg.configs.all.rules }
Object.assign(plugin.configs, {
"flat/all": { name: "eslint-plugin-no-autofix/all", plugins: { "no-autofix": plugin }, rules: plugin.configs.all.rules }
});

module.exports = pkg;
module.exports = plugin;
51 changes: 26 additions & 25 deletions packages/web/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
/**
* @fileoverview eslint-plugin-web
* @author 唯然<[email protected]>
*/
"use strict";

const ruleIds = ["no-alert", "no-script-url"];
const all = {};
const rules = {};

for (const ruleId of ruleIds) {
all[ruleId] = 2;
rules[ruleId] = require(`../lib/rules/${ruleId}.js`);
}

module.exports = {
configs: {
all: {
plugins: ["web"],
rules: all
}

},
rules
};
/**
* @fileoverview eslint-plugin-web
* @author 唯然<[email protected]>
*/
"use strict";
const pkg = require("../package.json");
const ruleIds = ["no-alert", "no-script-url"];
const all = {};
const rules = {};

for (const ruleId of ruleIds) {
all[ruleId] = 2;
rules[ruleId] = require(`../lib/rules/${ruleId}.js`);
}

module.exports = {
meta: { name: pkg.name, version: pkg.version },
configs: {
all: {
plugins: ["web"],
rules: all
}

},
rules
};

0 comments on commit 2557d60

Please sign in to comment.