Skip to content

Commit

Permalink
Merge pull request #153 from bmish/duplicate-config-emoji-legend
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Oct 21, 2022
2 parents ccce381 + 0ccec07 commit a0e9684
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/legend.ts
Expand Up @@ -52,10 +52,12 @@ const LEGENDS: {

const legends = [];
if (
configNamesWithoutIgnored.length > 1 ||
!configEmojis.find((configEmoji) =>
configNamesWithoutIgnored?.includes(configEmoji.config)
)?.emoji
(configNamesWithoutIgnored.length > 1 ||
!configEmojis.find((configEmoji) =>
configNamesWithoutIgnored?.includes(configEmoji.config)
)?.emoji) &&
// If any configs are using the generic config emoji, then don't display the generic config legend.
!configEmojis.some((configEmoji) => configEmoji.emoji === EMOJI_CONFIG)
) {
// Generic config emoji will be used if the plugin has multiple configs or the sole config has no emoji.
legends.push(`${EMOJI_CONFIG} ${configsLinkOrWord} enabled in.`);
Expand Down
23 changes: 23 additions & 0 deletions test/lib/__snapshots__/generator-test.ts.snap
Expand Up @@ -845,6 +845,29 @@ exports[`generator #generate with --config-emoji and removing default emoji for
"
`;

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`] = `
"## Rules
<!-- begin rules list -->
💼 Enabled in the \`recommended\` configuration.
| Name | Description | 💼 |
| :----------------------------- | :---------------------- | :-- |
| [no-foo](docs/rules/no-foo.md) | Description for no-foo. | 💼 |
<!-- end rules list -->
"
`;

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`] = `
"# Description for no-foo (\`test/no-foo\`)
💼 This rule is enabled in the \`recommended\` config.
<!-- end rule header -->
"
`;

exports[`generator #generate with --config-emoji shows the correct emojis 1`] = `
"## Rules
<!-- begin rules list -->
Expand Down
44 changes: 44 additions & 0 deletions test/lib/generator-test.ts
Expand Up @@ -2719,6 +2719,50 @@ describe('generator', function () {
});
});

describe('with --config-emoji and using the default config emoji for a config', function () {
beforeEach(function () {
mockFs({
'package.json': JSON.stringify({
name: 'eslint-plugin-test',
main: 'index.js',
type: 'module',
}),

'index.js': `
export default {
rules: {
'no-foo': { meta: { docs: { description: 'Description for no-foo.'} }, create(context) {} },
},
configs: {
recommended: { rules: { 'test/no-foo': 'error' } },
}
};`,

'README.md': '## Rules\n',

'docs/rules/no-foo.md': '',

// Needed for some of the test infrastructure to work.
node_modules: mockFs.load(
resolve(__dirname, '..', '..', 'node_modules')
),
});
});

afterEach(function () {
mockFs.restore();
jest.resetModules();
});

it('hides the generic config emoji legend to avoid two legends for the same emoji', async function () {
await generate('.', {
configEmoji: ['recommended,💼'],
});
expect(readFileSync('README.md', 'utf8')).toMatchSnapshot();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});

describe('with one config that does not have emoji', function () {
beforeEach(function () {
mockFs({
Expand Down

0 comments on commit a0e9684

Please sign in to comment.