Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid potentially having two legends for the same config emoji #153

Merged
merged 1 commit into from Oct 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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