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

Externalise rules #1

Closed wooorm closed 8 years ago

wooorm commented 8 years ago

Hey! Nice work, cool to see new rules :)

I recommend externalising these rules as separate packages. That makes them composable and usable for people who, for example, only want one of these rules. Or, for use cases where someone sets up an .mdastrc file and flow.

For an example, check out chcokr/mdast-lint-sentence-newline.

Again, very nice work :smile: And let me know if you have any questions regarding mdast/mdast-lint

vhf commented 8 years ago

Hey, thanks for checking it out! mdast and mdast-lint have already been - and will continue to be - invaluable to vhf/free-programming-books

I will try generalising some of my rules and externalise them, for the ones that are not too tightly coupled to our internal formatting rules. It'll take some time though.

Quick question: is there a way to pass parameters to processor.process and access them in a rule file? Sample use case: passing the filename of the file being linted, and having a rule lint slightly differently according to the filename. (Concretely, it would allow me to pass the language of a file to the linter, useful for Intl (UTF8) alphabetical ordering.)

wooorm commented 8 years ago

Great to hear, very good! :smile:

The filename can be accessed through 'file.filename'. For example, see this rule: https://github.com/wooorm/mdast-lint/blob/master/lib/rules/no-file-name-irregular-characters.js.

I haven't created options which are available for everything: the Parser, the Compiler, and plugins. but, I'm also not sure if your language case needs this. Could you not pass the language to the plug-ins, or a rule? (noteworthy: rules can have setting passed too, https://github.com/wooorm/mdast-lint/blob/master/lib/rules/file-extension.js)

vhf commented 8 years ago

Done! I published all my rules as NPM packages.

wooorm commented 8 years ago

:ok_hand: