refactor: 문서 개선 중
This commit is contained in:
@@ -124,7 +124,7 @@ function strip(src) {
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
function positiveChecks(text, lines, docMode, rulesMode) {
|
||||
function positiveChecks(text, lines, docMode, rulesMode, recordKind = '') {
|
||||
const out = [];
|
||||
const sentences = text.split(/(?<=[.?!])\s+|\n{2,}/).map(x => x.trim()).filter(Boolean);
|
||||
|
||||
@@ -217,14 +217,21 @@ function positiveChecks(text, lines, docMode, rulesMode) {
|
||||
// 바꿔 둔 자리) 판단할 수 없으니 건너뛴다. 「이름 : 값」 줄도 문장이 아니라 건너뛴다.
|
||||
const DANGLING = /(때|고|며|면|를|을|는|은|이|가|에서|으로|에|와|과|도|서|아|어|지|니|라서|라|의)$/;
|
||||
let inFront = lines[0] === '---';
|
||||
let currentSection = '';
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (inFront) { if (i > 0 && line === '---') inFront = false; continue; }
|
||||
const heading = /^##\s+(.+?)\s*$/.exec(line.trim());
|
||||
if (heading) currentSection = heading[1];
|
||||
const t = line.trimEnd();
|
||||
if (!t.trim() || t !== line) continue; // 빈 줄 · 끝에 공백(인라인 코드 자리)
|
||||
if (/^\s*(#|-|\*|\d+\.|:::|<!--|\||>)/.test(t) || t.includes(' : ')) continue;
|
||||
const next = (lines[i + 1] ?? '').trim();
|
||||
if (next !== '') continue; // 문단이 이어진다
|
||||
// REFERENCE의 `적용 조건`은 Studio schema상 독립 문장 본문이 아니라 조건 값 목록이다.
|
||||
// `~할 때`, 명사구 같은 fragment를 문장으로 늘리면 오히려 렌더링이 장황해진다.
|
||||
// 이 예외는 해당 kind/section에만 한정하고, 다른 본문의 dangling 문장은 계속 막는다.
|
||||
if (recordKind === 'REFERENCE' && currentSection === '적용 조건') continue;
|
||||
if (DANGLING.test(t)) {
|
||||
out.push({ id: 'dangling-sentence', sev: ERR, line: i + 1,
|
||||
msg: `문장이 끝나지 않은 채 문단이 끝납니다("…${t.slice(-24)}"). 지우다 남은 조각이거나 마침표가 빠졌습니다.` });
|
||||
@@ -289,6 +296,8 @@ const files = args.filter(a => !a.startsWith('--'));
|
||||
let errTotal = 0;
|
||||
for (const file of files) {
|
||||
const raw = readFileSync(file, 'utf8');
|
||||
const front = /^---\r?\n([\s\S]*?)\r?\n---/.exec(raw);
|
||||
const recordKind = front?.[1].match(/^kind:\s*(\S+)/m)?.[1] ?? '';
|
||||
const text = strip(raw);
|
||||
const lines = text.split('\n');
|
||||
const hits = [];
|
||||
@@ -302,7 +311,7 @@ for (const file of files) {
|
||||
}
|
||||
}
|
||||
});
|
||||
for (const p of positiveChecks(text, lines, docMode, rulesMode)) hits.push({ line: null, ...p, match: null });
|
||||
for (const p of positiveChecks(text, lines, docMode, rulesMode, recordKind)) hits.push({ line: null, ...p, match: null });
|
||||
|
||||
const errs = hits.filter(h => h.sev === ERR);
|
||||
const warns = hits.filter(h => h.sev === WARN);
|
||||
|
||||
Reference in New Issue
Block a user