UNPKG

eslint-remote-tester

Version:
64 lines (63 loc) 3.69 kB
import config from '../config/index.js'; import { CACHE_LOCATION } from '../file-client/index.js'; // Regexp for converting `[INFO][LINTING] reponame` to `[INFO/LINTING] reponame` const CI_TEMPLATE_TASK_REGEXP = /\]\[/; /** * Format seconds into display format, e.g. 36092 -> 10h 1m 32s */ function formatSeconds(timeSeconds) { const hours = Math.floor(timeSeconds / 3600); const minutes = Math.floor((timeSeconds % 3600) / 60); const seconds = Math.floor(timeSeconds % 60); return [ hours && `${hours}h`, minutes && `${minutes}m`, seconds && `${seconds}s`, ] .filter(Boolean) .join(' '); } export const TASK_TEMPLATE = (task) => { switch (task.step) { case 'START': return `[STARTING] ${task.repository}`; case 'CLONE': return `[CLONING] ${task.repository}`; case 'PULL': return `[PULLING] ${task.repository}`; case 'READ': return `[READING] ${task.repository}`; case 'LINT': { const status = task.currentFileIndex === 0 ? '' : `${task.currentFileIndex}/`; return `[LINTING] ${task.repository} - ${status}${task.fileCount} files`; } default: return `Unknown step ${task.step}`; } }; export const REPOSITORIES_STATUS_TEMPLATE = (scannedRepositories) => `Repositories (${scannedRepositories}/${config.repositories.length})`; export const CI_STATUS_TEMPLATE = (scannedRepositories, errorCount, tasks) => `[INFO/STATUS] ${REPOSITORIES_STATUS_TEMPLATE(scannedRepositories)} [INFO/STATUS] Errors (${errorCount}) ${tasks.map(task => CI_TASK_TEMPLATE(task)).join('\n')}\n`; export const CACHE_STATUS_TEMPLATE = (repositoriesCount, location) => `[INFO] Cached repositories (${repositoriesCount}) at ${location}`; const CI_TASK_TEMPLATE = (task) => `[INFO]${TASK_TEMPLATE(task)}`.replace(CI_TEMPLATE_TASK_REGEXP, '/'); export const LINT_END_TEMPLATE = (repository, errorCount) => errorCount > 0 ? `[ERROR] ${repository} ${errorCount} errors` : `[SUCCESS] ${repository}`; export const LINT_SLOW_TEMPLATE = (lintTime, file) => { const path = file.replace(`${CACHE_LOCATION}/`, '').split('/'); const fileName = path.pop(); return `[WARN] Linting ${fileName} took ${lintTime}s at ${path.join('/')}`; }; export const LINT_FAILURE_TEMPLATE = (repository, rule) => `[ERROR] ${repository} crashed${rule ? `: ${rule}` : ''}`; export const WORKER_FAILURE_TEMPLATE = (repository, errorCode) => `[ERROR] Worker crashed on ${repository}${errorCode ? ` (${errorCode})` : ''}`; export const PULL_FAILURE_TEMPLATE = (repository) => `[ERROR] ${repository} failed to pull`; export const CLONE_FAILURE_TEMPLATE = (repository) => `[ERROR] ${repository} failed to clone`; export const READ_FAILURE_TEMPLATE = (repository) => `[ERROR] ${repository} failed to read files`; export const WRITE_FAILURE_TEMPLATE = (repository, e) => `[ERROR] ${repository} failed to write results: ${e.message}`; export const OVERFLOWING_ROWS_TOP = (overflowingRowCount) => `[\u25B2 to see ${overflowingRowCount} lines above]`; export const OVERFLOWING_ROWS_BOTTOM = (overflowingRowCount) => `[\u25BC to see ${overflowingRowCount} lines below]`; export const RESULT_COMPARISON_FINISHED = (added, removed) => `[DONE] Result comparison: Added ${added}. Removed ${removed}.`; export const SCAN_TIMELIMIT_REACHED = (timeSeconds) => `[DONE] Reached scan time limit ${formatSeconds(timeSeconds)}`; export const SCAN_FINISHED = (scannedRepositories) => `[DONE] Finished scan of ${scannedRepositories} repositories`; export const DEBUG_TEMPLATE = (message) => `[DEBUG ${new Date().toTimeString().split(' ')[0]}] ${message}`;