Skip to content

Commit ea5e33c

Browse files
committed
refactor(devtools): clean up imports and improve text handling in SEO tab components
This commit refactors the SEO tab components by cleaning up imports related to severity handling and ensuring consistent text handling by removing unnecessary nullish coalescing and optional chaining. These changes enhance code readability and maintainability across the heading structure, JSON-LD, and links preview components.
1 parent d898203 commit ea5e33c

4 files changed

Lines changed: 14 additions & 19 deletions

File tree

packages/devtools/src/tabs/seo-tab/heading-structure-preview.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { For, Show } from 'solid-js'
22
import { Section, SectionDescription } from '@tanstack/devtools-ui'
33
import { useStyles } from '../../styles/use-styles'
4-
import { pickSeverityClass, type SeoSeverity } from './seo-severity'
4+
import { pickSeverityClass } from './seo-severity'
5+
import type { SeoSeverity } from './seo-severity'
56
import type { SeoSectionSummary } from './seo-section-summary'
67

78
type HeadingItem = {
@@ -29,7 +30,7 @@ function extractHeadings(): Array<HeadingItem> {
2930
id: node.id || `heading-${index}`,
3031
level,
3132
tag,
32-
text: node.textContent?.trim() || '',
33+
text: node.textContent.trim() || '',
3334
}
3435
})
3536
}

packages/devtools/src/tabs/seo-tab/json-ld-preview.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { For, Show } from 'solid-js'
22
import { Section, SectionDescription } from '@tanstack/devtools-ui'
33
import { useStyles } from '../../styles/use-styles'
4-
import {
5-
pickSeverityClass,
6-
seoHealthTier,
7-
type SeoSeverity,
8-
} from './seo-severity'
4+
import { pickSeverityClass, seoHealthTier } from './seo-severity'
5+
import type { SeoSeverity } from './seo-severity'
96
import type { SeoSectionSummary } from './seo-section-summary'
107

118
type JsonLdValue = Record<string, unknown>
@@ -269,7 +266,7 @@ function stringifyPreviewValue(value: unknown, maxLen = 200): string {
269266
return value.join(', ')
270267
}
271268
if (value.length === 1 && isRecord(value[0])) {
272-
const o = value[0] as JsonLdValue
269+
const o = value[0]
273270
const t = typeof o['@type'] === 'string' ? String(o['@type']) : 'Item'
274271
const label =
275272
typeof o.name === 'string'
@@ -330,7 +327,7 @@ function analyzeJsonLdScripts(): Array<JsonLdEntry> {
330327
)
331328

332329
return scripts.map((script, index) => {
333-
const raw = script.textContent?.trim() ?? ''
330+
const raw = script.textContent.trim()
334331
if (!raw) {
335332
return {
336333
id: `jsonld-${index}`,
@@ -462,7 +459,7 @@ function getJsonLdScore(entries: Array<JsonLdEntry>): number {
462459
for (const issue of entry.issues) {
463460
if (issue.severity === 'error') errors += 1
464461
else if (issue.severity === 'warning') warnings += 1
465-
else if (issue.severity === 'info') infos += 1
462+
else infos += 1
466463
}
467464
}
468465

packages/devtools/src/tabs/seo-tab/links-preview.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { For, Show, createSignal } from 'solid-js'
22
import { Section, SectionDescription } from '@tanstack/devtools-ui'
33
import { useStyles } from '../../styles/use-styles'
4-
import { pickSeverityClass, type SeoSeverity } from './seo-severity'
4+
import { pickSeverityClass } from './seo-severity'
5+
import type { SeoSeverity } from './seo-severity'
56
import type { SeoSectionSummary } from './seo-section-summary'
67

78
type LinkKind = 'internal' | 'external' | 'non-web' | 'invalid'
@@ -22,7 +23,7 @@ type LinkRow = {
2223
function classifyLink(anchor: HTMLAnchorElement): LinkRow {
2324
const href = anchor.getAttribute('href')?.trim() || ''
2425
const text =
25-
anchor.textContent?.trim() ||
26+
anchor.textContent.trim() ||
2627
anchor.getAttribute('aria-label')?.trim() ||
2728
anchor.getAttribute('title')?.trim() ||
2829
''

packages/devtools/src/tabs/seo-tab/seo-overview.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@ import { getSerpPreviewSummary } from './serp-preview'
88
import { getJsonLdPreviewSummary } from './json-ld-preview'
99
import { getHeadingStructureSummary } from './heading-structure-preview'
1010
import { getLinksPreviewSummary } from './links-preview'
11+
import { pickSeverityClass, seoHealthTier } from './seo-severity'
1112
import {
1213
aggregateSeoHealth,
1314
countBySeverity,
1415
sectionHealthScore,
1516
worstSeverity,
16-
type SeoDetailView,
17-
type SeoSectionSummary,
1817
} from './seo-section-summary'
19-
import {
20-
pickSeverityClass,
21-
seoHealthTier,
22-
type SeoSeverity,
23-
} from './seo-severity'
18+
import type { SeoSeverity } from './seo-severity'
19+
import type { SeoDetailView, SeoSectionSummary } from './seo-section-summary'
2420

2521
type OverviewRow = {
2622
id: SeoDetailView

0 commit comments

Comments
 (0)