Skip to content

Commit 4d698a2

Browse files
committed
✅ account for punctuation in linebreak check
1 parent 2ab1e0d commit 4d698a2

File tree

4 files changed

+61
-20
lines changed

4 files changed

+61
-20
lines changed

scripts/bad-linebreaks-test.mjs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ const afterMD = './scripts/test-samples/bad-linebreaks-sample-after.md';
77
const beforeMD = './scripts/test-samples/bad-linebreaks-sample-before.md';
88

99
// verify hash values to detect file tampering
10-
const knownAfterHash = '5f29c1fb4abd747c2dd801e12c600ee3';
11-
const knownBeforeHash = '406e900af5cd9af66abbe5b3ab6bcf3e';
12-
const afterHash = await getHashSlingingSlasher(afterMD);
10+
const knownBeforeHash = '5dfa7a6c97c43bf3321f2e9ccafd3ce8';
11+
const knownAfterHash = '9ed9cc827a7ffa71e6c243a23d7e24a3';
1312
const beforeHash = await getHashSlingingSlasher(beforeMD);
14-
assert.strictEqual(afterHash, knownAfterHash);
13+
const afterHash = await getHashSlingingSlasher(afterMD);
1514
assert.strictEqual(beforeHash, knownBeforeHash);
15+
assert.strictEqual(afterHash, knownAfterHash);
1616

1717
let fixed, totalMatches;
1818

1919
({ fixed, totalMatches } = findBadStuff(beforeMD, true));
20-
assert.strictEqual(totalMatches.badLinebreaks, 12);
21-
assert.strictEqual(totalMatches.extraWhitespace, 114);
22-
assert.strictEqual(fixed, fs.readFileSync(afterMD, 'utf8').toString());
20+
assert.strictEqual(totalMatches.badLinebreaks, 44);
21+
assert.strictEqual(totalMatches.extraWhitespace, 131);
22+
validateLines(fixed, fs.readFileSync(afterMD, 'utf8').toString());
2323

2424
({ fixed, totalMatches } = findBadStuff(afterMD, true));
2525
assert.strictEqual(totalMatches.badLinebreaks, 0);
2626
assert.strictEqual(totalMatches.extraWhitespace, 0);
27-
assert.strictEqual(fixed, fs.readFileSync(afterMD, 'utf8').toString());
27+
validateLines(fixed, fs.readFileSync(afterMD, 'utf8').toString());
2828

2929
({ fixed, totalMatches } = findBadStuff(beforeMD));
30-
assert.strictEqual(totalMatches.badLinebreaks, 12);
31-
assert.strictEqual(totalMatches.extraWhitespace, 114);
30+
assert.strictEqual(totalMatches.badLinebreaks, 44);
31+
assert.strictEqual(totalMatches.extraWhitespace, 131);
3232

3333
function getHashSlingingSlasher(file) { // 💀
3434
return new Promise((res, rej) => {
@@ -39,3 +39,16 @@ function getHashSlingingSlasher(file) { // 💀
3939
stream.on('end', () => res(hash.digest('hex')));
4040
});
4141
}
42+
43+
function validateLines(actual, expected) {
44+
45+
const expectedLines = expected.split('\n');
46+
const actualLines = actual.split('\n');
47+
48+
for (let i = 0; i < expectedLines.length; i++) {
49+
const eLine = expectedLines[i];
50+
const aLine = actualLines[i];
51+
assert.strictEqual(aLine, eLine);
52+
}
53+
54+
}

scripts/bad-linebreaks.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const tokenTypeEnum = Object.freeze({
1414
SPACE: 'space',
1515
});
1616

17-
const reBadLinebreaks = /(?<=[\w\d ])\n(?=[\w\d ])/g;
17+
const reBadLinebreaks = /(?<=[\w\d \p{P}])\n(?=[\w\d ])/gu;
1818
const reExtraWhitespaceParagraph = /^ +| (?= )| +$/gm;
1919
const reExtraWhitespaceList = /(?<=^ {0,}[-*+] |\d+\. ) +|(?<=\w+ ) +| +$/gm;
2020

scripts/test-samples/bad-linebreaks-sample-after.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ BBB: This is a sentence.
1313

1414
CCC: This is a sentence with trailing spaces.
1515

16-
CCC: This is a sentence.
17-
DDD: This is also a sentence.
18-
EEE: Hmmmmmm.
16+
CCC: This is a sentence. DDD: This is also a sentence. EEE: Hmmmmmm.
1917

2018
```
2119
here be code
@@ -53,6 +51,10 @@ let biscuits = "delicious";
5351
* one more
5452
+ time
5553

54+
RPR: thanks especially to Roderigo for helping out to arrange that meeting. We can see you in the room, Roderigo. Thank you. All right. So on to the usual items. So let’s start, let’s see if we have approval for last -- actually, I don’t think we fully committed them yet, so we should probably -- let’s return to that perhaps later in the meeting once we’ve got that. All right, what about the current agenda? Are there any objections to the current agenda? And I will say because I’m working on a laptop, I cannot see the element room right now. If any of the other chairs do see anything, please just interrupt. I’m going to take silence as approval. I will say with today’s current agenda, or this week’s current agenda, it is packed. It is oversubscribed. You’ll see that we have many really good items in the overflow slot at the moment. We’re going to work you know, we’re going to do our best to claw some back. Maybe some people will consider deprioritizing items. I know I’ve already heard some some candidates there that we may do. But the main thing is we need to really work hard to keep -- to do food time keeping and stick to our time boxes. And with that, I think I can hand over to Samina.
55+
56+
RPR: thanks especially to Roderigo for helping out to arrange that meeting. We can see you in the room, Roderigo. Thank you. All right. So on to the usual items. So let’s start, let’s see if we have approval for last -- actually, I don’t think we fully committed them yet, so we should probably -- let’s return to that perhaps later in the meeting once we’ve got that. All right, what about the current agenda? Are there any objections to the current agenda? And I will say because I’m working on a laptop, I cannot see the element room right now. If any of the other chairs do see anything, please just interrupt. I’m going to take silence as approval. I will say with today’s current agenda, or this week’s current agenda, it is packed. It is oversubscribed. You’ll see that we have many really good items in the overflow slot at the moment. We’re going to work you know, we’re going to do our best to claw some back. Maybe some people will consider deprioritizing items. I know I’ve already heard some some candidates there that we may do. But the main thing is we need to really work hard to keep -- to do food time keeping and stick to our time boxes. And with that, I think I can hand over to Samina.
57+
5658
## story time!
5759

5860
True! nervous, very, very dreadfully nervous I had been and am; but why will you say that I am mad? The disease had sharpened my senses, not destroyed, not dulled them. Above all was the sense of hearing acute. I heard all things in the heaven and in the earth. I heard many things in hell. How then am I mad? Hearken! and observe how healthily, how calmly I can tell you the whole story.
@@ -75,19 +77,15 @@ It was open, wide, wide open, and I grew furious as I gazed upon it. I saw it wi
7577

7678
And now have I not told you that what you mistake for madness is but over-acuteness of the senses? now, I say, there came to my ears a low, dull, quick sound, such as a watch makes when enveloped in cotton. I knew that sound well, too. It was the beating of the old man's heart. It increased my fury, as the beating of a drum stimulates the soldier into courage.
7779

78-
But even yet I refrained and kept still. I scarcely breathed. I held the lantern motionless. I tried how steadily I could maintain the ray upon the eye. Meantime the hellish tattoo of the heart increased. It grew quicker and quicker, and louder and louder, every instant. The old man's terror must have been extreme! It grew louder, I say, louder every moment!—do you mark me well? I have told you that I am nervous: so I am. And now at the dead hour of the night, amid the dreadful silence of that old house, so strange a noise as this excited me to uncontrollable terror. Yet, for some minutes longer I refrained and stood still. But the beating grew louder, louder! I thought the heart must burst. And now a new anxiety seized me—the sound would be heard by a neighbor!
79-
The old man's hour had come! With a loud yell, I threw open the lantern and leaped into the room. He shrieked once—once only. In an instant I dragged him to the floor, and pulled the heavy bed over him. I then smiled gaily, to find the deed so far done. But for many minutes the heart beat on with a muffled sound. This, however, did not vex me; it would not be heard through the wall. At length it ceased. The old man was dead. I removed the bed and examined the corpse.
80-
Yes, he was stone, stone dead. I placed my hand upon the heart and held it there many minutes.
81-
There was no pulsation. He was stone dead. His eye would trouble me no more.
80+
But even yet I refrained and kept still. I scarcely breathed. I held the lantern motionless. I tried how steadily I could maintain the ray upon the eye. Meantime the hellish tattoo of the heart increased. It grew quicker and quicker, and louder and louder, every instant. The old man's terror must have been extreme! It grew louder, I say, louder every moment!—do you mark me well? I have told you that I am nervous: so I am. And now at the dead hour of the night, amid the dreadful silence of that old house, so strange a noise as this excited me to uncontrollable terror. Yet, for some minutes longer I refrained and stood still. But the beating grew louder, louder! I thought the heart must burst. And now a new anxiety seized me—the sound would be heard by a neighbor! The old man's hour had come! With a loud yell, I threw open the lantern and leaped into the room. He shrieked once—once only. In an instant I dragged him to the floor, and pulled the heavy bed over him. I then smiled gaily, to find the deed so far done. But for many minutes the heart beat on with a muffled sound. This, however, did not vex me; it would not be heard through the wall. At length it ceased. The old man was dead. I removed the bed and examined the corpse. Yes, he was stone, stone dead. I placed my hand upon the heart and held it there many minutes. There was no pulsation. He was stone dead. His eye would trouble me no more.
8281

8382
If still you think me mad, you will think so no longer when I describe the wise precautions I took for the concealment of the body. The night waned, and I worked hastily, but in silence.
8483

8584
I took up three planks from the flooring of the chamber, and deposited all between the scantlings. I then replaced the boards so cleverly, so cunningly, that no human eye—not even his—could have detected anything wrong. There was nothing to wash out—no stain of any kind—no bloodspot whatever. I had been too wary for that.
8685

8786
When I had made an end of these labors, it was four o'clock—still dark as midnight. As the bell sounded the hour, there came a knocking at the street door. I went down to open it with a light heart—for what had I now to fear? There entered three men, who introduced themselves, with perfect suavity, as officers of the police. A shriek had been heard by a neighbor during the night; suspicion of foul play had been aroused; information had been lodged at the police office, and they (the officers) had been deputed to search the premises.
8887

89-
I smiled—for what had I to fear? I bade the gentlemen welcome. The shriek, I said, was my own in a dream. The old man, I mentioned, was absent in the country. I took my visitors all over the house. I bade them search—search well. I led them, at length, to his chamber.
90-
I showed them his treasures, secure, undisturbed. In the enthusiasm of my confidence, I brought chairs into the room, and desired them here to rest from their fatigues, while I myself, in the wild audacity of my perfect triumph, placed my own seat upon the very spot beneath which reposed the corpse of the victim.
88+
I smiled—for what had I to fear? I bade the gentlemen welcome. The shriek, I said, was my own in a dream. The old man, I mentioned, was absent in the country. I took my visitors all over the house. I bade them search—search well. I led them, at length, to his chamber. I showed them his treasures, secure, undisturbed. In the enthusiasm of my confidence, I brought chairs into the room, and desired them here to rest from their fatigues, while I myself, in the wild audacity of my perfect triumph, placed my own seat upon the very spot beneath which reposed the corpse of the victim.
9189

9290
The officers were satisfied. My manner had convinced them. I was singularly at ease. They sat, and while I answered cheerily, they chatted of familiar things. But, ere long, I felt myself getting pale and wished them gone. My head ached, and I fancied a ringing in my ears; but still they sat, and still chatted. The ringing became more distinct;—it continued and became more distinct. I talked more freely to get rid of the feeling, but it continued and gained definitiveness—until, at length, I found that the noise was not within my ears.
9391

scripts/test-samples/bad-linebreaks-sample-before.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,36 @@ let biscuits = "delicious";
5959
* one more
6060
+ time
6161

62+
RPR: thanks especially to Roderigo for helping out to arrange that meeting. We can see you
63+
in the room, Roderigo. Thank you. All right. So on to the usual items. So let’s start,
64+
let’s see if we have approval for last -- actually, I don’t think we fully committed them yet,
65+
so we should probably -- let’s return to that perhaps later in the meeting once we’ve got that.
66+
All right, what about the current agenda? Are there any objections to the current agenda? And
67+
I will say because I’m working on a laptop, I cannot see the element room right now. If any of
68+
the other chairs do see anything, please just interrupt. I’m going to take silence as
69+
approval. I will say with today’s current agenda, or this week’s current agenda, it is packed.
70+
It is oversubscribed. You’ll see that we have many really good items in the overflow slot at
71+
the moment. We’re going to work you know, we’re going to do our best to claw some back.
72+
Maybe some people will consider deprioritizing items. I know I’ve already heard some some
73+
candidates there that we may do. But the main thing is we need to really work hard to keep --
74+
to do food time keeping and stick to our time boxes. And with that, I think I can hand over to
75+
Samina.
76+
77+
RPR: thanks especially to Roderigo for helping out to arrange that meeting. We can see you
78+
in the room, Roderigo. Thank you. All right. So on to the usual items. So let’s start,
79+
let’s see if we have approval for last -- actually, I don’t think we fully committed them yet,
80+
so we should probably -- let’s return to that perhaps later in the meeting once we’ve got that.
81+
All right, what about the current agenda? Are there any objections to the current agenda? And
82+
I will say because I’m working on a laptop, I cannot see the element room right now. If any of
83+
the other chairs do see anything, please just interrupt. I’m going to take silence as
84+
approval. I will say with today’s current agenda, or this week’s current agenda, it is packed.
85+
It is oversubscribed. You’ll see that we have many really good items in the overflow slot at
86+
the moment. We’re going to work you know, we’re going to do our best to claw some back.
87+
Maybe some people will consider deprioritizing items. I know I’ve already heard some some
88+
candidates there that we may do. But the main thing is we need to really work hard to keep --
89+
to do food time keeping and stick to our time boxes. And with that, I think I can hand over to
90+
Samina.
91+
6292
## story time!
6393

6494
True! nervous, very, very dreadfully nervous I had been and am; but why will you say that I am mad? The disease had sharpened my senses, not destroyed,

0 commit comments

Comments
 (0)