diff --git a/docs/src/extend/plugins.md b/docs/src/extend/plugins.md index f180c034faa..9d7983e67f2 100644 --- a/docs/src/extend/plugins.md +++ b/docs/src/extend/plugins.md @@ -18,6 +18,34 @@ Each plugin is an npm module with a name in the format of `eslint-plugin- { + + const pluginId = getObjectId(plugin); + + if (!pluginId) { + return namespace; + } + + return `${namespace}:${pluginId}`; + }), languageOptions: { ...languageOptions, parser: parserName diff --git a/tests/lib/config/flat-config-array.js b/tests/lib/config/flat-config-array.js index 2b8e8f64ec3..7ca78a388f2 100644 --- a/tests/lib/config/flat-config-array.js +++ b/tests/lib/config/flat-config-array.js @@ -221,6 +221,72 @@ describe("FlatConfigArray", () => { assert.strictEqual(stringify(actual), stringify(expected)); }); + it("should convert config with plugin name/version into normalized JSON object", () => { + + const configs = new FlatConfigArray([{ + plugins: { + a: {}, + b: { + name: "b-plugin", + version: "2.3.1" + } + } + }]); + + configs.normalizeSync(); + + const config = configs.getConfig("foo.js"); + const expected = { + plugins: ["@", "a", "b:b-plugin@2.3.1"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "module", + parser: `espree@${espree.version}`, + parserOptions: {} + }, + processor: void 0 + }; + const actual = config.toJSON(); + + assert.deepStrictEqual(actual, expected); + + assert.strictEqual(stringify(actual), stringify(expected)); + }); + + it("should convert config with plugin meta into normalized JSON object", () => { + + const configs = new FlatConfigArray([{ + plugins: { + a: {}, + b: { + meta: { + name: "b-plugin", + version: "2.3.1" + } + } + } + }]); + + configs.normalizeSync(); + + const config = configs.getConfig("foo.js"); + const expected = { + plugins: ["@", "a", "b:b-plugin@2.3.1"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "module", + parser: `espree@${espree.version}`, + parserOptions: {} + }, + processor: void 0 + }; + const actual = config.toJSON(); + + assert.deepStrictEqual(actual, expected); + + assert.strictEqual(stringify(actual), stringify(expected)); + }); + it("should throw an error when config with unnamed parser object is normalized", () => { const configs = new FlatConfigArray([{