UNPKG

eslint-remote-tester

Version:
41 lines (40 loc) 1.81 kB
import React from 'react'; import { Static, Text, Box } from 'ink'; import { ResultsStore, RESULT_TEMPLATE, RESULTS_TEMPLATE_CI_BASE, RESULT_COMPARISON_TEMPLATE, } from '../../file-client/index.js'; import { useExitAfterRender } from '../hooks/index.js'; const START_MESSAGE = '\nResults:'; const NO_ERRORS = ['No errors']; // This is used to override ink's text wrapping. Especially on Github CI the max // line width is not really the terminals width. The CI will handle text wrapping. const LINE_WIDTH = 500; function formatComparisonResults(comparisonResults) { if (!comparisonResults) return []; const { added, removed } = comparisonResults; return [ '\nComparison results:', RESULT_COMPARISON_TEMPLATE.header('added'), ...added.map(RESULT_COMPARISON_TEMPLATE.results), ' ', // Line break RESULT_COMPARISON_TEMPLATE.header('removed'), ...removed.map(RESULT_COMPARISON_TEMPLATE.results), ]; } /** * Results of the scan * - Displayed only on CI mode after scan has completed */ export default function Results() { useExitAfterRender(); const results = ResultsStore.getResults(); const formattedResults = results.map(result => [RESULTS_TEMPLATE_CI_BASE(result), RESULT_TEMPLATE(result)].join('\n')); const comparisonResults = ResultsStore.getComparisonResults(); const formattedComparisonResults = formatComparisonResults(comparisonResults); const items = [ ...formattedComparisonResults, START_MESSAGE, ...(formattedResults.length > 0 ? formattedResults : NO_ERRORS), ].filter(Boolean); return (React.createElement(Static, { items: items }, (result, index) => (React.createElement(Box, { width: LINE_WIDTH, key: index }, React.createElement(Text, null, result))))); }