Skip to content

docs: fix misleading return-await options and config group #11227

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ function getRuleDefaultOptions(page: RuleDocsPage): string {

return typeof recommended === 'object'
? [
`const defaultOptionsRecommended: Options = ${defaults};`,
'',
'// These options are merged on top of the recommended defaults',
...(recommended.recommended
? [
`const defaultOptionsRecommended: Options = ${defaults};`,
'',
'// These options are merged on top of the recommended defaults',
]
: []),
`const defaultOptionsStrict: Options = ${JSON.stringify(recommended.strict)};`,
].join('\n')
: `const defaultOptions: Options = ${defaults};`;
Expand Down
24 changes: 6 additions & 18 deletions packages/website/src/components/RulesTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useMemo } from 'react';
import type { HistorySelector } from '../../hooks/useHistorySelector';

import { useHistorySelector } from '../../hooks/useHistorySelector';
import { getRecommendationWithEmoji } from '../../theme/MDXComponents/RuleAttributes';
import {
CONFIG_EMOJI,
DEPRECATED_RULE_EMOJI,
Expand All @@ -35,9 +36,9 @@ function interpolateCode(

function getActualRecommended({
docs,
}: RulesMeta[number]): RuleRecommendation | undefined {
}: RulesMeta[number]): ['', ''] | [string, RuleRecommendation] {
const recommended = docs.recommended;
return typeof recommended === 'object' ? 'recommended' : recommended;
return recommended ? getRecommendationWithEmoji(recommended) : ['', ''];
}

function RuleRow({
Expand All @@ -50,7 +51,7 @@ function RuleRow({
}
const { deprecated, fixable, hasSuggestions } = rule;
const { extendsBaseRule, requiresTypeChecking } = rule.docs;
const actualRecommended = getActualRecommended(rule);
const [emoji, actualRecommended] = getActualRecommended(rule);
return (
<tr>
<td>
Expand All @@ -61,20 +62,7 @@ function RuleRow({
{interpolateCode(rule.docs.description)}
</td>
<td className={styles.attrCol} title={actualRecommended}>
{(() => {
switch (actualRecommended) {
case 'recommended':
return RECOMMENDED_CONFIG_EMOJI;
case 'strict':
return STRICT_CONFIG_EMOJI;
case 'stylistic':
return STYLISTIC_CONFIG_EMOJI;
default:
// for some reason the current version of babel loader won't elide
// this correctly recommended satisfies undefined;
return '';
}
})()}
{emoji}
</td>
<td
className={styles.attrCol}
Expand Down Expand Up @@ -172,7 +160,7 @@ export default function RulesTable(): React.JSX.Element {
const relevantRules = useMemo(
() =>
rules.filter(r => {
const actualRecommended = getActualRecommended(r);
const actualRecommended = getActualRecommended(r)[1];
const opinions = [
match(filters.recommended, actualRecommended === 'recommended'),
match(
Expand Down
23 changes: 15 additions & 8 deletions packages/website/src/theme/MDXComponents/RuleAttributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
import { Feature } from './Feature';
import styles from './RuleAttributes.module.css';

const recommendations = {
const recommendations: Record<
RuleRecommendation,
[string, RuleRecommendation]
> = {
recommended: [RECOMMENDED_CONFIG_EMOJI, 'recommended'],
strict: [STRICT_CONFIG_EMOJI, 'strict'],
stylistic: [STYLISTIC_CONFIG_EMOJI, 'stylistic'],
Expand All @@ -45,19 +48,23 @@ const resolveRecommendation = (
};

const getRecommendation = (docs: RecommendedRuleMetaDataDocs): string[] => {
const recommended = docs.recommended;
const recommendation =
recommendations[
typeof recommended === 'object'
? resolveRecommendation(recommended)
: recommended
];
const recommendation = getRecommendationWithEmoji(docs.recommended);

return docs.requiresTypeChecking
? [recommendation[0], `${recommendation[1]}-type-checked`]
: recommendation;
};

export function getRecommendationWithEmoji(
recommended: RecommendedRuleMetaDataDocs['recommended'],
): [string, RuleRecommendation] {
const recommendationKey =
typeof recommended === 'object'
? resolveRecommendation(recommended)
: recommended;
return recommendations[recommendationKey];
}

export function RuleAttributes({ name }: { name: string }): React.ReactNode {
const rules = useRulesMeta();
const rule = rules.find(rule => rule.name === name);
Expand Down
Loading