Skip to content

Commit ff590cb

Browse files
Merge pull request #43 from HackYourFuture-CPH/no-trailing-whitespace
New lint rule: no trailing whitespace in markdown
2 parents e3160dd + 2464ca0 commit ff590cb

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Programme
22

3-
> [!WARNING]
3+
> [!WARNING]
44
> This repository is under construction. If you're looking for the current HYF curriculum, check out [Curriculum](https://github.com/HackYourFuture-CPH/curriculum).
55
66
Documents the HYF programme, courses and modules.

support/src/parse.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,21 @@ export type ParsedImage = {
1717
export type ParseResult = {
1818
readonly links: readonly ParsedLink[];
1919
readonly images: readonly ParsedImage[];
20+
readonly trailingWhitespace: readonly SourceLocation[];
2021
};
2122

2223
export const parse = (content: string): ParseResult => {
24+
const trailingWhitespace: SourceLocation[] = [];
25+
26+
content.split(/\n/).forEach((line, index) => {
27+
if (line.endsWith(" ")) {
28+
trailingWhitespace.push({
29+
line0: index,
30+
column0: line.trimEnd().length,
31+
});
32+
}
33+
});
34+
2335
const parser = mit();
2436
const tokens = parser.parse(content, {});
2537

@@ -64,5 +76,6 @@ export const parse = (content: string): ParseResult => {
6476
return {
6577
links: parsedLinks,
6678
images: parsedImages,
79+
trailingWhitespace,
6780
};
6881
};

support/src/validateLinks.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ const findAllFiles = async (): Promise<string[]> => {
2828
};
2929

3030
const findMarkdownFiles = (files: string[]): string[] => {
31-
const ignorePattern = /^(README|LICENSE|contributing\/)/;
32-
return files.filter(
33-
(f) => f.toLocaleLowerCase().endsWith(".md") && !ignorePattern.test(f),
34-
);
31+
return files.filter((f) => f.toLocaleLowerCase().endsWith(".md"));
3532
};
3633

3734
const scanForLinks = async (filenames: string[]): Promise<ParsedFile[]> => {
@@ -70,6 +67,16 @@ const main = async () => {
7067
let errors = 0;
7168

7269
for (const parsedFile of parsedFiles) {
70+
for (const ws of parsedFile.trailingWhitespace) {
71+
showError(
72+
parsedFile.filename,
73+
ws,
74+
"VL003/trailing-whitespace",
75+
"Trailing whitespace",
76+
);
77+
++errors;
78+
}
79+
7380
for (const img of parsedFile.images) {
7481
if (!isExternalLink(img.src)) {
7582
const resolved = path.join(dirname(parsedFile.filename), img.src);

0 commit comments

Comments
 (0)