Skip to content

Comments

Fix static analysis failures: TypeScript migration, typedoc errors, ESLint/HTMLHint cleanup#431

Merged
pethers merged 22 commits intomainfrom
copilot/improve-article-analysis-quality
Feb 22, 2026
Merged

Fix static analysis failures: TypeScript migration, typedoc errors, ESLint/HTMLHint cleanup#431
pethers merged 22 commits intomainfrom
copilot/improve-article-analysis-quality

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

CI failing on typedoc TS errors (playwright module not found, discriminated union narrowing), 26 ESLint warnings, 34 HTMLHint errors, and 2 tsc errors. Also migrates remaining JS scripts to TypeScript for codebase consistency.

Static analysis fixes

  • ESLint (26 → 0): Prefix unused vars with _, add caughtErrorsIgnorePattern: '^_' to config
  • TypeScript (2 → 0): Add missing organ to MockArticlePayload.documents test fixture
  • HTMLHint (34 → 0): Close unclosed <span class="separator"> in 26 news files, escape > and " in meta attributes
  • Typedoc (2 → 0): Exclude validate-articles-playwright.ts from typedoc tsconfig (playwright not a dep), fix ValidationSuccess narrowing with explicit cast

TypeScript migration

Converted 9 scripts/*.js.ts with full type annotations:

Script Key types
coalition-dashboard PartyNode extends d3.SimulationNodeDatum, CoalitionLink
committees-dashboard CommitteeData, NetworkNode, HeatMapCell
validate-against-cia-schemas ValidationResult, ValidationReport
validate-translations ValidationChecks, discriminated union ValidationResult
sync-cia-schemas SyncResults, SchemaVersionEntry
back-to-top DOM null narrowing, typed event handlers

Deleted empty take-screenshot.js/.ts (159 lines JSDoc, 0 executable code). Updated package.json to tsx, excluded browser scripts from tsconfig.scripts.json and tsconfig.typedoc.json.

Article generation improvements

  • Explicit generateArticleContent switch cases for month-ahead, weekly-review, monthly-review, breaking (previously fell to default)
  • Enhanced generateGenericContent with key takeaways and policy significance sections
  • Extended generateMetadata to all 8 article types
  • Fixed content error: "171 seats > 175 majority" → "171 seats < 175"

Reference updates

  • Updated 399 news HTML <script> refs: back-to-top.jsback-to-top.ts with type="module"
  • Updated article-template.ts for future article generation
  • Fixed vitest.config.js coverage excludes .js.ts

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Add politicalContext, policyImplications, keyTakeaways, thematicAnalysis,
legislativePipeline, oppositionStrategy, coalitionDynamics, whatThisMeans,
whyItMatters, committeeBreakdown, propsBreakdown, motionsBreakdown to the
newKeys array to ensure comprehensive validation across all 14 languages.

Co-authored-by: pethers <[email protected]>
Copilot AI changed the title [WIP] Enhance analytical depth in article generation Add missing ContentLabelSet fields to test validation Feb 22, 2026
Copilot AI requested a review from pethers February 22, 2026 06:30
Copilot AI and others added 2 commits February 22, 2026 06:50
…adata coverage

- Add explicit switch cases for month-ahead, weekly-review, monthly-review, breaking
- Enhance generateGenericContent with key takeaways and policy significance sections
- Add generateMetadata coverage for weekly-review, monthly-review, month-ahead, breaking
- Add 8 new tests for enhanced generic content, metadata, and multi-language support

Co-authored-by: pethers <[email protected]>
Copilot AI changed the title Add missing ContentLabelSet fields to test validation Enhance article generation with analytical sections and complete type coverage Feb 22, 2026
@github-actions github-actions bot added deployment Deployment configuration testing Test coverage refactor Code refactoring size-xl Extra large change (> 1000 lines) labels Feb 22, 2026
@github-actions
Copy link
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copilot AI and others added 10 commits February 22, 2026 07:08
- Fix 2 TypeScript errors (MockArticlePayload missing organ in documents type)
- Fix 26 ESLint warnings (unused variables/args/catch bindings)
- Add caughtErrorsIgnorePattern to ESLint config
- Fix 34 HTMLHint errors (unclosed spans, unescaped special chars)
- Remove unused path import from vite.config.js

Co-authored-by: pethers <[email protected]>
The original file contains only a JSDoc documentation block with no
executable code, so the TypeScript version is identical.

Co-authored-by: Copilot <[email protected]>
Add TypeScript version of the CIA schema validator script with:
- Proper type annotations for all variables, parameters, and return types
- ValidationResult and ValidationReport interfaces
- ESM imports using node: protocol
- unknown catch bindings with proper casting
- Class property declarations
- Strict mode compatible annotations

Co-authored-by: Copilot <[email protected]>
Add scripts/validate-translations.ts with:
- Interfaces for ColorCodes, LanguageConfig, ValidationSuccess,
  ValidationError, ValidationResult, and ValidationChecks
- Proper type annotations for all variables, parameters, return types
- Discriminated union type for validation results
- unknown catch binding with (error as Error).message cast
- ESM import syntax preserved
- Strict TypeScript compliance verified

Co-authored-by: Copilot <[email protected]>
Add scripts/sync-cia-schemas.ts with full type annotations, interfaces
for data structures, proper error handling with unknown catch bindings,
and node: protocol imports. Original .js file is preserved.

Co-authored-by: Copilot <[email protected]>
Add TypeScript version with:
- Interfaces for SchemaHashResult, SchemaUpdate, SchemaError, UpdateReport
- Typed class properties with access modifiers
- Proper return type annotations on all methods
- unknown catch bindings with (error as Error).message
- ESM imports from node: protocol
- readonly modifier on CIA_SCHEMAS array

Co-authored-by: Copilot <[email protected]>
Add TypeScript version with:
- Proper type annotations for all variables, parameters, return types
- ESM import syntax with node: protocol
- Interfaces for FailedGeneration and GenerationResults
- Class property declarations with access modifiers
- unknown error catch bindings with (error as Error).message casts
- Strict mode compatible

Co-authored-by: Copilot <[email protected]>
Add TypeScript version with:
- Interfaces for ViewportSize, ValidationConfig, ScreenshotInfo,
  ValidationCheckResult, ArticleValidationResult, ValidationSummary,
  ValidationResults, and AccessibilityNode
- Full type annotations on all variables, parameters, and return types
- ESM imports from node: protocol
- Typed Playwright imports (Browser, Page)
- unknown catch bindings with (error as Error).message casts
- Record<string, ScreenshotInfo[]> for grouped screenshots

Original .js file preserved.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions bot added translation Translation updates rtl RTL language support (Arabic, Hebrew) performance Performance optimization news News articles and content generation labels Feb 22, 2026
@github-actions
Copy link
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request migrates JavaScript files in the scripts/ directory to TypeScript and resolves all static analysis errors across ESLint (26→0 warnings), TypeScript (2→0 errors), and HTMLHint (34→0 errors). The migration includes 9 scripts with comprehensive type annotations, while fixing HTML validation issues and updating configuration files.

Changes:

  • Converted 9 scripts/*.js files to TypeScript with full type safety (coalition-dashboard, committees-dashboard, validate-translations, validate-articles-playwright, validate-against-cia-schemas, sync-cia-schemas, check-cia-schema-updates, generate-types-from-cia-schemas, back-to-top)
  • Fixed ESLint warnings by prefixing unused variables with _ and adding caughtErrorsIgnorePattern to eslint.config.js
  • Fixed TypeScript errors by adding missing organ property to MockArticlePayload.documents interface
  • Fixed 34 HTMLHint errors: closed unclosed <span class="separator"> tags across 26 news files, escaped HTML entities (> as &gt;, " as &quot;) in meta attributes
  • Updated package.json scripts to use npx tsx for TypeScript execution
  • Removed empty take-screenshot.js/.ts (159 lines JSDoc, 0 executable lines)
  • Extended data-transformers.ts to support new article types (month-ahead, weekly-review, monthly-review, breaking)

Reviewed changes

Copilot reviewed 58 out of 59 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
eslint.config.js Added caughtErrorsIgnorePattern: '^_' to ignore caught errors prefixed with underscore
vitest.config.js Updated coverage excludes to reference .ts extensions for migrated dashboard scripts
tsconfig.scripts.json Updated excludes to reference .ts extensions for browser-loaded scripts
vite.config.js Removed unused path import
package.json Updated script commands to use npx tsx for TypeScript execution
scripts/*.ts (9 files) Full TypeScript migration with comprehensive interface definitions and type annotations
tests/*.test.js Fixed ESLint warnings by prefixing unused variables; added missing organ property to MockArticlePayload
news/*.html (26+ files) Fixed unclosed <span> tags and escaped special characters in meta attributes
scripts/data-transformers.ts Added support for month-ahead, weekly-review, monthly-review, breaking article types
Comments suppressed due to low confidence (1)

scripts/validate-against-cia-schemas.ts:1

  • The shebang line has been changed from #!/usr/bin/env node to #!/usr/bin/env npx tsx. This change is inconsistent with the sync-cia-schemas.ts file (line 1) which still uses #!/usr/bin/env node.

For TypeScript files executed with tsx via package.json scripts (npx tsx scripts/...), the shebang should remain #!/usr/bin/env node for portability and convention. The tsx execution is already handled by the npm script commands in package.json. Using #!/usr/bin/env npx tsx in the shebang creates unnecessary indirection and may cause issues in environments where npx behaves differently.

Comment on lines +1 to +51
/**
* @module Infrastructure/Accessibility
* @category Infrastructure
*
* @title Back-to-Top Navigation Utility - Accessibility & User Experience
*
* @description
* Provides a "back to top" button that scrolls long-form political intelligence
* articles to the top with accessibility support (WCAG 2.1 AA).
*
* @author Hack23 AB (Accessibility & User Experience)
* @license Apache-2.0
* @version 1.0.0
* @since 2024-06-20
*/
(function (): void {
'use strict';

const maybeButton: HTMLElement | null = document.getElementById('back-to-top');

if (!maybeButton) return;

const backToTopButton: HTMLElement = maybeButton;

// Show/hide button based on scroll position
function toggleButtonVisibility(): void {
if (window.pageYOffset > 300) {
backToTopButton.classList.add('visible');
} else {
backToTopButton.classList.remove('visible');
}
}

// Scroll to top with accessibility support
function scrollToTop(): void {
// Check if user prefers reduced motion
const prefersReducedMotion: boolean = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

window.scrollTo({
top: 0,
behavior: prefersReducedMotion ? 'auto' : 'smooth'
});
}

// Add event listeners
window.addEventListener('scroll', toggleButtonVisibility);
backToTopButton.addEventListener('click', scrollToTop);

// Initial check
toggleButtonVisibility();
})();
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

All news article HTML files (over 300 occurrences) still reference ../scripts/back-to-top.js, but this file has been migrated to TypeScript (.ts).

Browser-loaded TypeScript files need to be compiled to JavaScript before they can be referenced in HTML <script> tags. Either:

  1. The HTML files need to be updated to reference back-to-top.js after build (if Vite compiles it), or
  2. The TypeScript files need to remain as .js for browser loading, or
  3. A build step needs to compile .ts browser scripts to .js and output them with .js extensions

Currently, the PR description states "HTML <script> refs to back-to-top.js in news articles need updating" as remaining work, confirming this is incomplete.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 52265f3. Updated all 399 news HTML files from <script src="../scripts/back-to-top.js"> to <script type="module" src="../scripts/back-to-top.ts"> — Vite handles .ts files natively in HTML when using type="module". Also updated article-template.ts so future generated articles use the correct reference.

vitest.config.js Outdated
Comment on lines 70 to 78
'scripts/sync-cia-schemas.js',
'scripts/check-cia-schema-updates.js',
'scripts/generate-types-from-cia-schemas.js',
'scripts/generate-news-backport.js',
'scripts/load-cia-stats.js',
'scripts/update-stats-from-cia.js',
'scripts/validate-against-cia-schemas.js',
'scripts/validate-against-cia-schemas.ts',
// CLI validation script (not importable, uses process.exit)
'scripts/validate-translations.js',
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The vitest.config.js coverage excludes still reference .js extensions for files that have been migrated to TypeScript. Lines 70-72 and 78 should be updated to reflect the TypeScript migration:

  • scripts/sync-cia-schemas.jsscripts/sync-cia-schemas.ts
  • scripts/check-cia-schema-updates.jsscripts/check-cia-schema-updates.ts
  • scripts/generate-types-from-cia-schemas.jsscripts/generate-types-from-cia-schemas.ts
  • scripts/validate-translations.jsscripts/validate-translations.ts

These files are still listed with .js extensions in the exclude patterns even though they've been converted to TypeScript.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 52265f3. Updated all 4 remaining .js coverage excludes to .ts: sync-cia-schemas, check-cia-schema-updates, generate-types-from-cia-schemas, and validate-translations.

<p>Opposition motions speak directly to these swing segments. For Center voters uncomfortable with SD cooperation: preventive detention motions highlight civil liberties conflicts, positioning C as coalition's conscience. For SD soft supporters queasy about radicalism: procurement labor standards motions emphasize workers' rights, appealing to nationalist-but-not-fascist sentiments. For S-to-M defectors: corporate taxation motions remind former social democrats why they historically supported progressive economics. Each motion calibrated for specific persuasion target.</p>

<p>The parliamentary arithmetic projections show campaign's electoral stakes. Current seat distribution: S: 100, M: 68, SD: 73, C: 25, V: 24, KD: 19, MP: 18, L: 16 (343 contested seats; 6 adjustment seats allocated by national vote). September 2026 scenarios: Scenario A (Left bloc gains): S: 105, M: 65, SD: 70, C: 20, V: 26, KD: 18, MP: 20, L: 15 = Left majority (S+V+MP+C: 171 seats > 175 majority threshold). Scenario B (Tidö holds): S: 98, M: 70, SD: 75, C: 18, V: 22, KD: 20, MP: 16, L: 16 = Tidö maintains narrow majority (M+SD+KD+L: 181 seats). Scenario C (Hung parliament): S: 102, M: 68, SD: 72, C: 22, V: 24, KD: 19, MP: 18, L: 16 = No clear majority, extended coalition negotiations.</p>
<p>The parliamentary arithmetic projections show campaign's electoral stakes. Current seat distribution: S: 100, M: 68, SD: 73, C: 25, V: 24, KD: 19, MP: 18, L: 16 (343 contested seats; 6 adjustment seats allocated by national vote). September 2026 scenarios: Scenario A (Left bloc gains): S: 105, M: 65, SD: 70, C: 20, V: 26, KD: 18, MP: 20, L: 15 = Left majority (S+V+MP+C: 171 seats &gt; 175 majority threshold). Scenario B (Tidö holds): S: 98, M: 70, SD: 75, C: 18, V: 22, KD: 20, MP: 16, L: 16 = Tidö maintains narrow majority (M+SD+KD+L: 181 seats). Scenario C (Hung parliament): S: 102, M: 68, SD: 72, C: 22, V: 24, KD: 19, MP: 18, L: 16 = No clear majority, extended coalition negotiations.</p>
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The HTML entity escaping is correct here. The > character (greater-than) must be escaped as &gt; in HTML meta attribute values. However, for consistency and readability, consider also escaping the comparison context: the sentence "171 seats > 175 majority threshold" is slightly confusing since 171 is not greater than 175. This appears to be a logic error in the content itself (not the HTML encoding).

The correct comparison should likely be checking if the sum exceeds some threshold, but the numbers don't support the stated "Left majority" claim since 171 < 175.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch on the logic error. Fixed in 52265f3 — changed "Left majority (S+V+MP+C: 171 seats > 175 majority threshold)" to "Left bloc short of majority (S+V+MP+C: 171 seats < 175 majority threshold)" since 171 is indeed less than 175.

@pethers
Copy link
Member

pethers commented Feb 22, 2026

@copilot apply changes based on the comments in this thread

…ludes, content logic

- Update 399 news HTML files: back-to-top.js → back-to-top.ts with type=module
- Update article-template.ts to generate correct script reference
- Fix vitest.config.js: update 4 remaining .js excludes to .ts
- Fix content logic error: 171 seats < 175 threshold (was incorrectly >)

Co-authored-by: pethers <[email protected]>
Copy link
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot apply changes based on the comments in this thread

All three review comments addressed in 52265f3:

  1. Updated 399 news HTML files + article template: back-to-top.jsback-to-top.ts with type="module"
  2. Fixed 4 remaining .js.ts coverage excludes in vitest.config.js
  3. Fixed content logic error: 171 < 175 (was incorrectly >)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request. There are 300 or more changed files, try reducing the number of files in this pull request and requesting a review from Copilot again.

@github-actions
Copy link
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

…t not installed)

The script uses playwright which is not a project dependency. Exclude it
from tsconfig.scripts.json, matching the pattern used for other browser-
specific scripts (coalition-dashboard.ts, committees-dashboard.ts, back-to-top.ts).

Co-authored-by: pethers <[email protected]>
Copilot AI changed the title Convert scripts/ to TypeScript, fix all lint/typecheck/HTMLHint errors Migrate scripts/ to TypeScript, fix all static analysis failures Feb 22, 2026
@pethers pethers requested a review from Copilot February 22, 2026 10:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request. There are 300 or more changed files, try reducing the number of files in this pull request and requesting a review from Copilot again.

@github-actions
Copy link
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

…narrowing

- Exclude validate-articles-playwright.ts from tsconfig.typedoc.json (playwright not a dependency)
- Fix type narrowing in validate-translations.ts:405 (use `as` cast after error check)

Co-authored-by: pethers <[email protected]>
Copilot AI changed the title Migrate scripts/ to TypeScript, fix all static analysis failures Fix static analysis failures: TypeScript migration, typedoc errors, ESLint/HTMLHint cleanup Feb 22, 2026
@github-actions
Copy link
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

@pethers pethers marked this pull request as ready for review February 22, 2026 10:36
@pethers pethers merged commit 328ae7d into main Feb 22, 2026
23 checks passed
@pethers pethers deleted the copilot/improve-article-analysis-quality branch February 22, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dashboard Interactive dashboards (Chart.js/D3.js) dependencies Dependency updates deployment Deployment configuration html-css HTML/CSS changes i18n Internationalization/localization javascript JavaScript code changes news News articles and content generation performance Performance optimization refactor Code refactoring rtl RTL language support (Arabic, Hebrew) size-xl Extra large change (> 1000 lines) testing Test coverage translation Translation updates visualization Data visualization features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants