Skip to content

Commit 0ccec07

Browse files
committed
fix: avoid two config legends for the same emoji
1 parent ccce381 commit 0ccec07

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

lib/legend.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ const LEGENDS: {
5252

5353
const legends = [];
5454
if (
55-
configNamesWithoutIgnored.length > 1 ||
56-
!configEmojis.find((configEmoji) =>
57-
configNamesWithoutIgnored?.includes(configEmoji.config)
58-
)?.emoji
55+
(configNamesWithoutIgnored.length > 1 ||
56+
!configEmojis.find((configEmoji) =>
57+
configNamesWithoutIgnored?.includes(configEmoji.config)
58+
)?.emoji) &&
59+
// If any configs are using the generic config emoji, then don't display the generic config legend.
60+
!configEmojis.some((configEmoji) => configEmoji.emoji === EMOJI_CONFIG)
5961
) {
6062
// Generic config emoji will be used if the plugin has multiple configs or the sole config has no emoji.
6163
legends.push(`${EMOJI_CONFIG} ${configsLinkOrWord} enabled in.`);

test/lib/__snapshots__/generator-test.ts.snap

+23
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,29 @@ exports[`generator #generate with --config-emoji and removing default emoji for
845845
"
846846
`;
847847

848+
exports[`generator #generate with --config-emoji and using the default config emoji for a config hides the generic config emoji legend to avoid two legends for the same emoji 1`] = `
849+
"## Rules
850+
<!-- begin rules list -->
851+
852+
💼 Enabled in the \`recommended\` configuration.
853+
854+
| Name | Description | 💼 |
855+
| :----------------------------- | :---------------------- | :-- |
856+
| [no-foo](docs/rules/no-foo.md) | Description for no-foo. | 💼 |
857+
858+
<!-- end rules list -->
859+
"
860+
`;
861+
862+
exports[`generator #generate with --config-emoji and using the default config emoji for a config hides the generic config emoji legend to avoid two legends for the same emoji 2`] = `
863+
"# Description for no-foo (\`test/no-foo\`)
864+
865+
💼 This rule is enabled in the \`recommended\` config.
866+
867+
<!-- end rule header -->
868+
"
869+
`;
870+
848871
exports[`generator #generate with --config-emoji shows the correct emojis 1`] = `
849872
"## Rules
850873
<!-- begin rules list -->

test/lib/generator-test.ts

+44
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,50 @@ describe('generator', function () {
27192719
});
27202720
});
27212721

2722+
describe('with --config-emoji and using the default config emoji for a config', function () {
2723+
beforeEach(function () {
2724+
mockFs({
2725+
'package.json': JSON.stringify({
2726+
name: 'eslint-plugin-test',
2727+
main: 'index.js',
2728+
type: 'module',
2729+
}),
2730+
2731+
'index.js': `
2732+
export default {
2733+
rules: {
2734+
'no-foo': { meta: { docs: { description: 'Description for no-foo.'} }, create(context) {} },
2735+
},
2736+
configs: {
2737+
recommended: { rules: { 'test/no-foo': 'error' } },
2738+
}
2739+
};`,
2740+
2741+
'README.md': '## Rules\n',
2742+
2743+
'docs/rules/no-foo.md': '',
2744+
2745+
// Needed for some of the test infrastructure to work.
2746+
node_modules: mockFs.load(
2747+
resolve(__dirname, '..', '..', 'node_modules')
2748+
),
2749+
});
2750+
});
2751+
2752+
afterEach(function () {
2753+
mockFs.restore();
2754+
jest.resetModules();
2755+
});
2756+
2757+
it('hides the generic config emoji legend to avoid two legends for the same emoji', async function () {
2758+
await generate('.', {
2759+
configEmoji: ['recommended,💼'],
2760+
});
2761+
expect(readFileSync('README.md', 'utf8')).toMatchSnapshot();
2762+
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
2763+
});
2764+
});
2765+
27222766
describe('with one config that does not have emoji', function () {
27232767
beforeEach(function () {
27242768
mockFs({

0 commit comments

Comments
 (0)