-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add markdown lint #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+786
−1
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e82af96
feat: Add markdown lint
saraed-zenika a45eae6
feat: Lint must not rewrite files
saraed-zenika 17e7334
feat: Fix lint errors
saraed-zenika bbc6fbd
feat: add TU function containsAnyError
saraed-zenika 231628f
feat: change the textlint command
saraed-zenika 4a321ed
feat: Fix message lint
saraed-zenika 73a8589
feat: fix issue prettier
saraed-zenika 874e78f
feat : add
saraed-zenika db828ba
feat: fix quality code
saraed-zenika 51e08f3
feat: fix lint rules and add tests (PR)
saraed-zenika ff24985
feat: fix issue (PR)
saraed-zenika fd95b25
Adjust output format
gmembre-zenika 295d3a5
add exclude files
gmembre-zenika ceb8bf2
os
gmembre-zenika 982573e
lint
gmembre-zenika File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| const titleOrCommentLinePattern = /^\s*(##.*)|(<!-- \.slide: class="page-.*)$/; | ||
| const nPreviousEmpty = 3; | ||
|
|
||
| function allEmpty(lines) { | ||
| return lines.every((l) => l.trim() === ""); | ||
| } | ||
|
|
||
| export async function containsAnyError(readStream) { | ||
| // Buffer circulaire pour stocker les nPreviousEmpty lignes précédentes | ||
| const prevLines = []; | ||
| var index = 1; | ||
| var containsError = false; | ||
|
|
||
| for await (const line of readStream) { | ||
| // Vérifie si la ligne courante match le pattern | ||
| if (titleOrCommentLinePattern.test(line)) { | ||
| if (!allEmpty(prevLines)) { | ||
| console.info( | ||
| `ligne n°${index} There must be at least ${nPreviousEmpty} blank lines before the block "${line}" .` | ||
| ); | ||
| containsError = true; | ||
| } | ||
| } | ||
|
|
||
| // Increment du nombre de ligne | ||
| index += 1; | ||
|
|
||
| // Ajoute la ligne actuelle dans le buffer, limite la taille à nPreviousEmpty | ||
| prevLines.push(line); | ||
| if (prevLines.length > nPreviousEmpty) { | ||
| prevLines.shift(); // enlève la plus vieille ligne | ||
| } | ||
| } | ||
|
|
||
| return containsError; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| const test = require("node:test"); | ||
| const assert = require("node:assert"); | ||
| const readline = require("readline"); | ||
| const { containsAnyError } = require("./lint"); | ||
| const { Readable } = require("node:stream"); | ||
|
|
||
| test("Lint - Contains any error should return false using a title that follows 3 empty lines.", async () => { | ||
| const content = ` | ||
| # Titre de la formation | ||
|
|
||
|
|
||
|
|
||
| ## Sommaire | ||
| `; | ||
|
|
||
| const actual = await containsAnyError(createReadStream(content)); | ||
| assert.strictEqual(actual, false); | ||
| }); | ||
|
|
||
| test("Lint - Contains any error should return true using a title that not follows 3 empty lines.", async () => { | ||
| const content = ` | ||
| # Titre de la formation | ||
|
|
||
| ## Sommaire | ||
| `; | ||
|
|
||
| const actual = await containsAnyError(createReadStream(content)); | ||
| assert.strictEqual(actual, true); | ||
| }); | ||
|
|
||
| test("Lint - Contains any error should return false using a specific html comment that follows 3 empty lines.", async () => { | ||
| const content = ` | ||
| # Titre de la formation | ||
|
|
||
|
|
||
|
|
||
| <!-- .slide: class="page-title" --> | ||
| `; | ||
|
|
||
| const actual = await containsAnyError(createReadStream(content)); | ||
| assert.strictEqual(actual, false); | ||
| }); | ||
|
|
||
| test("Lint - Contains any error should return true using a specific html comment that not follows 3 empty lines.", async () => { | ||
gmembre-zenika marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const content = ` | ||
| # Titre de la formation | ||
|
|
||
| <!-- .slide: class="page-title" --> | ||
| `; | ||
|
|
||
| const actual = await containsAnyError(createReadStream(content)); | ||
| assert.strictEqual(actual, true); | ||
| }); | ||
|
|
||
| function createReadStream(content) { | ||
| return readline.createInterface({ | ||
| input: Readable.from(content), | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.