const fs = require("fs"); const path = require("path"); // Получаем путь к активному файлу из аргументов командной строки const filePath = process.argv[2]; const content = fs.readFileSync(filePath, "utf8"); const Eyo = require("eyo-kernel"); const safeEyo = new Eyo(); safeEyo.dictionary.loadSafeSync(); const unsafeEyo = new Eyo(); unsafeEyo.dictionary.loadNotSafeSync(); function mainAct() { const errors = []; const paragraphs = content .split(/\n\s*\n/) .filter((p) => p.trim().length > 90); if (paragraphs.length > 5) errors.push( `${path.basename(filePath)}:1:2:error:Не должно быть больше 5 параграфов` ); const segmenter = new Intl.Segmenter("ru", { granularity: "grapheme" }); const segments = Array.from(segmenter.segment(content)); const charCount = segments.length; if (charCount < 550) { errors.push( `${path.basename( filePath )}:1:1:error:Файл содержит ${charCount} символов, что меньше 550.` ); } else if (charCount > 1950) { errors.push( `${path.basename( filePath )}:1:1:error:Файл содержит ${charCount} символов, что больше 950.` ); } if (errors.length > 0) { errors.forEach((error) => console.error(error)); process.exit(1); } } function you() { const youRegex = /(? -1) { console.error( `${path.basename(filePath)}:${ i + 1 }:${sem}:warning:Не желательно использовать ;` ); process.exit(1); } // Проверяем, если строка не пустая и следующая тоже не пустая if ( lines[i].trim().length > 140 && lines[i].trim() !== "" && lines[i + 1].trim() !== "" ) { console.error( `${path.basename(filePath)}:${ i + 1 }:1:error:Абзацы разделены менее чем одной пустой строкой` ); return true; } } return false; } if (filePath.endsWith(".txt")) { mainAct(); const pRes = paragraph(); const pYou = you(); if (pRes || pYou) process.exit(1); let isYo = false; safeEyo.lint(content).forEach(({ before, after, position }) => { isYo = true; console.error( `${path.basename(filePath)}:${position.line}:${ position.column }:error:Замените "${before}" на "${after}"` ); }); unsafeEyo.lint(content).forEach(({ before, after, position }) => { isYo = true; console.error( `${path.basename(filePath)}:${position.line}:${ position.column }:warning:Вероятно, "${before}" пишется как "${after}"` ); }); if (isYo) process.exit(1); }