Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
},
"dependencies": {
"@types/eslint": "^9.6.1",
"flatted": "^3.3.3",
"jest-worker": "^29.7.0",
"micromatch": "^4.0.8",
"normalize-path": "^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/getESLint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { Worker: JestWorker } = require('jest-worker');
const { setup, lintFiles } = require('./worker');
const { getESLintOptions } = require('./options');
const { jsonStringifyReplacerSortKeys } = require('./utils');
const { stringify } = require('flatted');

/** @type {{[key: string]: any}} */
const cache = {};
Expand Down Expand Up @@ -115,7 +116,7 @@ async function getESLint(key, { threads, ...options }) {
* @returns {string}
*/
function getCacheKey(key, options) {
return JSON.stringify({ key, options }, jsonStringifyReplacerSortKeys);
return stringify({ key, options }, jsonStringifyReplacerSortKeys);
}

module.exports = {
Expand Down
10 changes: 7 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ const jsonStringifyReplacerSortKeys = (_, value) => {
return sorted;
};

return value instanceof Object && !(value instanceof Array)
? Object.keys(value).sort().reduce(insert, {})
: value;
if (value instanceof Object && !(value instanceof Array)) {
let sorted = Object.keys(value).sort().reduce(insert, {});
Object.keys(value).forEach((key) => delete value[key]);
Object.assign(value, sorted);
}

return value;
};

module.exports = {
Expand Down
38 changes: 38 additions & 0 deletions test/circular-plugin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pack from './utils/pack';
import { ESLint } from 'eslint';

(ESLint && parseFloat(ESLint.version) < 9 ? describe.skip : describe)(
'circular plugin',
() => {
it('should support plugins with circular configs', async () => {
const plugin = {
configs: {},
rules: {},
processors: {},
};

Object.assign(plugin.configs, {
recommended: {
plugins: {
self: plugin,
},
rules: {},
},
});

const loaderOptions = {
configType: 'flat',
overrideConfig: {
plugins: { plugin: plugin },
},
overrideConfigFile: true,
};

const compiler = pack('good', loaderOptions);

const stats = await compiler.runAsync();
expect(stats.hasWarnings()).toBe(false);
expect(stats.hasErrors()).toBe(false);
});
},
);