Skip to content

chore(website): fixed most no-unnecessary-condition complaints #7836

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

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
29 changes: 14 additions & 15 deletions packages/website/plugins/generated-rule-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ export const generatedRuleDocs: Plugin = () => {
return;
}

const rule = pluginRules[file.stem];
const meta = rule?.meta;
if (!meta?.docs) {
const rule = file.stem in pluginRules ? pluginRules[file.stem] : undefined;
if (!rule?.meta.docs) {
return;
}

Expand All @@ -72,7 +71,7 @@ export const generatedRuleDocs: Plugin = () => {
{
children: [
{
children: meta.docs.description
children: rule.meta.docs.description
.split(/`(.+?)`/)
.map((value, index, array) => ({
type: index % 2 === 0 ? 'text' : 'inlineCode',
Expand All @@ -90,7 +89,7 @@ export const generatedRuleDocs: Plugin = () => {
);

// 3. Add a notice about formatting rules being 🤢
if (meta.type === 'layout') {
if (rule.meta.type === 'layout') {
const warningNode = {
value: `
<admonition type="warning">
Expand Down Expand Up @@ -150,18 +149,18 @@ export const generatedRuleDocs: Plugin = () => {
}

insertIfMissing('Options');
if (meta.docs.extendsBaseRule) {
if (rule.meta.docs.extendsBaseRule) {
insertIfMissing('How to Use');
}
return [headingIndices[0], headingIndices[1]];
})();

let eslintrc: string;

if (meta.docs.extendsBaseRule) {
if (rule.meta.docs.extendsBaseRule) {
const extendsBaseRuleName =
typeof meta.docs.extendsBaseRule === 'string'
? meta.docs.extendsBaseRule
typeof rule.meta.docs.extendsBaseRule === 'string'
? rule.meta.docs.extendsBaseRule
: file.stem;

children.splice(optionsH2Index + 1, 0, {
Expand Down Expand Up @@ -257,9 +256,9 @@ export const generatedRuleDocs: Plugin = () => {

optionsH2Index += 2;

const hasNoConfig = Array.isArray(meta.schema)
? meta.schema.length === 0
: Object.keys(meta.schema).length === 0;
const hasNoConfig = Array.isArray(rule.meta.schema)
? rule.meta.schema.length === 0
: Object.keys(rule.meta.schema).length === 0;
if (hasNoConfig) {
children.splice(optionsH2Index + 1, 0, {
children: [
Expand Down Expand Up @@ -390,7 +389,7 @@ export const generatedRuleDocs: Plugin = () => {
);

// 6. Also add a notice about coming from ESLint core for extension rules
if (meta.docs.extendsBaseRule) {
if (rule.meta.docs.extendsBaseRule) {
children.push({
children: [
{
Expand All @@ -405,9 +404,9 @@ export const generatedRuleDocs: Plugin = () => {
type: 'link',
title: null,
url: `https://github.com/eslint/eslint/blob/main/docs/src/rules/${
meta.docs.extendsBaseRule === true
rule.meta.docs.extendsBaseRule === true
? file.stem
: meta.docs.extendsBaseRule
: rule.meta.docs.extendsBaseRule
}.md`,
children: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/ErrorsViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function ErrorViewer({
<h4>{title}</h4>
</div>
<pre className={styles.errorPre}>
{type === 'danger' ? value?.stack : value.message}
{type === 'danger' ? value.stack : value.message}
</pre>
</AlertBlock>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/OptionsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function OptionsSelectorContent({
value={state.ts}
disabled={!tsVersions.length}
onChange={(ts): void => setState({ ts })}
options={(tsVersions.length && tsVersions) || [state.ts]}
options={tsVersions.length ? tsVersions : [state.ts]}
/>
</InputLabel>
<InputLabel name="Eslint">{process.env.ESLINT_VERSION}</InputLabel>
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/ast/DataRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function RenderExpandableObject({
<div className={styles.subList}>
{data.map((dataElement, index) => (
<DataRender
key={dataElement[0] ?? index}
key={dataElement[0]}
field={dataElement[0]}
value={dataElement[1]}
lastElement={index === lastIndex}
Expand Down
14 changes: 5 additions & 9 deletions packages/website/src/components/ast/tsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function tsEnumToString(
type: keyof TsParsedEnums,
value: number,
): string | undefined {
return getTsEnum(type)?.[value];
return getTsEnum(type)[value];
}

/**
Expand All @@ -75,12 +75,8 @@ export function tsEnumFlagToString(
type: keyof TsParsedEnums,
value: number,
): string | undefined {
const allFlags = getTsEnum(type);
if (allFlags) {
return Object.entries(allFlags)
.filter(([f]) => (Number(f) & value) !== 0)
.map(([, name]) => `${type}.${name}`)
.join('\n');
}
return '';
return Object.entries(getTsEnum(type))
.filter(([f]) => (Number(f) & value) !== 0)
.map(([, name]) => `${type}.${name}`)
.join('\n');
}
9 changes: 5 additions & 4 deletions packages/website/src/components/config/ConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function ConfigEditorField({
{item.label && <br />}
{item.label && <span> {item.label}</span>}
</span>
{(item.type === 'boolean' && (
{item.type === 'boolean' ? (
<Checkbox
name={`config_${item.key}`}
value={item.key}
Expand All @@ -72,15 +72,16 @@ function ConfigEditorField({
onChange(item.key, checked ? item.defaults?.[0] ?? true : undefined)
}
/>
)) ||
(item.type === 'string' && item.enum && (
) : (
item.enum && (
<Dropdown
name={`config_${item.key}`}
value={String(value)}
options={item.enum}
onChange={(value): void => onChange(item.key, value)}
/>
))}
)
)}
</label>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/editor/LoadedEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
return debounce(() => editor.layout(), 1);
}, [editor]);

const container = editor.getContainerDomNode?.() ?? editor.getDomNode();
const container = editor.getContainerDomNode();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not correct, as this part of code is neccesary for some older versions of playground (older version of ts)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I'm confused, where are those types defined? The editor.api.d.ts I see has getContainerDomNode(): HTMLElement; - and I thought we're settled on just one editor version?


useResizeObserver(container, () => {
resize();
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/lib/jsonSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function getRuleJsonSchemaWithErrorLevel(
};
}
// example: naming-convention rule
if (typeof ruleSchema.items === 'object' && ruleSchema.items) {
if (typeof ruleSchema.items === 'object') {
Copy link
Collaborator

@armano2 armano2 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof null === 'object' // true

Copy link
Member

@bradzacher bradzacher Nov 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the context of the types it's probably defined as items?: T[] - hence the typeof is enough to refine the types correctly?
This was a strictness change we added in v6.

We could probably even change this check to be "cleaner" but it'll do fine like this I think

Copy link
Member Author

@JoshuaKGoldberg JoshuaKGoldberg Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't see any null values for items in any ESLint or typescript-eslint rule. Is there a reason to support it?

return {
...ruleSchema,
type: 'array',
Expand Down
4 changes: 2 additions & 2 deletions packages/website/src/components/lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export function createMarkdownParams(state: ConfigModel): string {
title: `Bug: [${onlyRuleName}] <short description of the issue>`,
'playground-link': document.location.toString(),
'repro-code': state.code,
'eslint-config': `module.exports = ${state.eslintrc ?? '{}'}`,
'typescript-config': state.tsconfig ?? '{}',
'eslint-config': `module.exports = ${state.eslintrc}`,
'typescript-config': state.tsconfig,
versions: generateVersionsTable(state.ts),
};

Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/typeDetails/TypeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function TypeInfo({
onHoverNode,
}: TypeInfoProps): React.JSX.Element {
const computed = useMemo(() => {
if (!typeChecker || !value) {
if (!typeChecker) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not correct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@armano2 according to the types it is - the property value is defined as readonly value: Node and it's never reassigned in the component body

return undefined;
}
const info: InfoModel = {};
Expand Down
7 changes: 6 additions & 1 deletion packages/website/src/theme/CodeBlock/Content/String.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export default function CodeBlockString({

const copiedCode = code
.split('\n')
.filter((c, i) => !lineClassNames[i]?.includes('code-block-removed-line'))
.filter(
(c, i) =>
!(lineClassNames[i] as string[] | undefined)?.includes(
'code-block-removed-line',
),
)
.join('\n');

const eslintrcHash = parseEslintrc(metastring);
Expand Down