Skip to content

Commit 12d770c

Browse files
committed
[fix] Match plugin export and plugin object on flat configs
1 parent 01c9eb0 commit 12d770c

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
66

77
## [Unreleased]
88

9+
### Fixed
10+
- ensure plugin exports are equal to the `plugin` object on flat configs ([#3213], thanks [@soren121])
11+
912
## [2.32.0] - 2025-06-20
1013

1114
### Added
@@ -1181,6 +1184,7 @@ for info on changes for earlier releases.
11811184

11821185
[`memo-parser`]: ./memo-parser/README.md
11831186

1187+
[#3213]: https://github.com/import-js/eslint-plugin-import/pull/3213
11841188
[#3191]: https://github.com/import-js/eslint-plugin-import/pull/3191
11851189
[#3173]: https://github.com/import-js/eslint-plugin-import/pull/3173
11861190
[#3172]: https://github.com/import-js/eslint-plugin-import/pull/3172
@@ -2042,6 +2046,7 @@ for info on changes for earlier releases.
20422046
[@skyrpex]: https://github.com/skyrpex
20432047
[@snewcomer]: https://github.com/snewcomer
20442048
[@sompylasar]: https://github.com/sompylasar
2049+
[@soren121]: https://github.com/soren121
20452050
[@soryy708]: https://github.com/soryy708
20462051
[@sosukesuzuki]: https://github.com/sosukesuzuki
20472052
[@spalger]: https://github.com/spalger

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,13 @@ export const configs = {
7373
typescript: require('../config/typescript'),
7474
};
7575

76+
export const meta = { name, version };
77+
7678
// Base Plugin Object
7779
const importPlugin = {
78-
meta: { name, version },
80+
meta,
81+
configs,
82+
flatConfigs: {},
7983
rules,
8084
};
8185

@@ -86,7 +90,7 @@ const createFlatConfig = (baseConfig, configName) => ({
8690
plugins: { import: importPlugin },
8791
});
8892

89-
export const flatConfigs = {
93+
export const flatConfigs = importPlugin.flatConfigs = {
9094
recommended: createFlatConfig(
9195
require('../config/flat/recommended'),
9296
'recommended',
@@ -101,3 +105,5 @@ export const flatConfigs = {
101105
electron: createFlatConfig(configs.electron, 'electron'),
102106
typescript: createFlatConfig(configs.typescript, 'typescript'),
103107
};
108+
109+
module.exports = importPlugin;

tests/src/package.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ describe('package', function () {
2020
});
2121

2222
it('has every rule', function (done) {
23-
2423
fs.readdir(
2524
path.join(pkg, 'rules')
2625
, function (err, files) {
@@ -34,7 +33,7 @@ describe('package', function () {
3433
});
3534
});
3635

37-
it('exports all configs', function (done) {
36+
it('exports all legacy configs', function (done) {
3837
fs.readdir(path.join(process.cwd(), 'config'), function (err, files) {
3938
if (err) { done(err); return; }
4039
files.filter(isJSFile).forEach((file) => {
@@ -45,6 +44,34 @@ describe('package', function () {
4544
});
4645
});
4746

47+
it('exports all flat configs', function (done) {
48+
fs.readdir(path.join(process.cwd(), 'config'), function (err, files) {
49+
if (err) { done(err); return; }
50+
files.filter(isJSFile).forEach((file) => {
51+
if (file[0] === '.') { return; }
52+
53+
const basename = path.basename(file, '.js');
54+
// stage-0 is not included in flat configs
55+
if (basename === 'stage-0') { return; }
56+
57+
expect(module.flatConfigs).to.have.property(basename);
58+
});
59+
done();
60+
});
61+
});
62+
63+
it('exports plugin meta object', function () {
64+
expect(module.meta).to.be.an('object').that.has.all.keys('name', 'version');
65+
expect(module.meta.name).to.equal('eslint-plugin-import');
66+
expect(module.meta.version).to.be.a('string');
67+
});
68+
69+
it('ensures the plugin object in the flat configs is identical to the module', function () {
70+
for (const configFile in module.flatConfigs) {
71+
expect(module.flatConfigs[configFile].plugins.import).to.equal(module);
72+
}
73+
});
74+
4875
function getRulePath(ruleName) {
4976
// 'require' does not work with dynamic paths because of the compilation step by babel
5077
// (which resolves paths according to the root folder configuration)

0 commit comments

Comments
 (0)