vhf / free-programming-books-lint

A rudimentary Markdown linter based on remark-lint for the free-programming-books project.
31 stars 12 forks source link

fpb-lint check lists alphabetical order of non alphabetical language pages #4

Closed tt512 closed 3 years ago

tt512 commented 3 years ago

Hi!

I guess fpb-lint doesn't check alphabetical order of lists because ja is not included in langsToAlphabetize and dictionary order of Japanese is not alphabetical also. However fpb-lint checks alphabetical order on Japanese document.

/home/tat/free-programming-books/free-programming-books-ja.md
  4:3-17:80  warning  Alphabetical ordering: swap l.17 and l.16  alphabetize-lists  remark-lint
  4:3-17:80  warning  Alphabetical ordering: swap l.11 and l.10  alphabetize-lists  remark-lint

⚠ 2 warnings

In addition, I found out alphabetize-lists plugin appended increasingly to preset.plugin list in forEach loop by inserting log for debugging.

diff --git a/lib/lint.js b/lib/lint.js
index 8fb2f5e..b5347b0 100644
--- a/lib/lint.js
+++ b/lib/lint.js
@@ -80,6 +80,9 @@ const commonPreset = {
       preset.plugins.push([require('remark-lint-alphabetize-lists'), lang]);
     }
     const processor = remark().use(preset);
+    console.log(JSON.stringify({
+      filename: filename.split('/').pop(), lang: lang, alphabetize: langsToAlphabetize.includes(lang),
+      remarkLintAlphabetizeListsFor: preset.plugins.filter(x => x[0] === require('remark-lint-alphabetize-lists')).map(x => x[1])}));

     processor.process(doc, (err, file) => {
       if (report(err || file) !== 'no issues found') {

output:

...
{"filename":"HOWTO.md","lang":"en-US","alphabetize":true,"remarkLintAlphabetizeListsFor":["en-US"]}
{"filename":"HOWTO.pt_BR.md","lang":"books/HOWTO.pt-BR","alphabetize":false,"remarkLintAlphabetizeListsFor":["en-US"]}
{"filename":"free-courses-bg.md","lang":"bg","alphabetize":true,"remarkLintAlphabetizeListsFor":["en-US","bg"]}
{"filename":"free-courses-de.md","lang":"de","alphabetize":true,"remarkLintAlphabetizeListsFor":["en-US","bg","de"]}
{"filename":"free-courses-en.md","lang":"en","alphabetize":true,"remarkLintAlphabetizeListsFor":["en-US","bg","de","en"]}
{"filename":"free-courses-es.md","lang":"es","alphabetize":true,"remarkLintAlphabetizeListsFor":["en-US","bg","de","en","es"]}
{"filename":"free-courses-fi.md","lang":"fi","alphabetize":true,"remarkLintAlphabetizeListsFor":["en-US","bg","de","en","es","fi"]}
{"filename":"free-courses-hi.md","lang":"hi","alphabetize":false,"remarkLintAlphabetizeListsFor":["en-US","bg","de","en","es","fi"]}
...

I think it's not expected behavior, so I'll create PR.

vhf commented 3 years ago

Well done, thanks for the detailed issue and the fix!