get-alex / alex

Catch insensitive, inconsiderate writing
https://alexjs.com
MIT License
4.81k stars 207 forks source link

Add support for custom formatters #308

Closed k-yle closed 3 years ago

k-yle commented 3 years ago

This PR adds support for custom formatters instead of vfile-reporter, like what eslint does.

Use case: you want machine-readable output to integrate with other CI tooling, such as the Gitlab CI .

codecov-io commented 3 years ago

Codecov Report

Merging #308 (c3dcbde) into main (3474dd9) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #308   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           87        85    -2     
=========================================
- Hits            87        85    -2     
Impacted Files Coverage Δ
cli.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3474dd9...c3dcbde. Read the comment docs.

wooorm commented 3 years ago

Hi there!

unified also allows custom formatters, and this is built into the code we’re using: see engine options the reporter and reporterOptions. I’m fine with adding this but don’t see why we shouldn’t use what’s build in already

k-yle commented 3 years ago

Hi @wooorm, it makes a lot more sense doing it that way! I've changed it to use vfile reporters like unified does, which works and the CI passes (2nd to last commit).

However, when I tried to use reporter and reporterOptions, I get the following error from unified which I can't figure out (latest commit):

Error: Cannot `stringify` without `Compiler`
  at assertCompiler (./node_modules/unified/index.js:444:11)
  at Function.stringify (./node_modules/unified/index.js:347:5)
  at stringify (./node_modules/unified-engine/lib/file-pipeline/stringify.js:45:23)
  at wrapped (./node_modules/trough/wrap.js:25:19)
  at next (./node_modules/trough/index.js:57:24)
  at Object.run (./node_modules/trough/index.js:31:10)
  at run (./node_modules/unified-engine/lib/file-pipeline/index.js:29:10)
  at wrapped (./node_modules/trough/wrap.js:25:19)
  at next (./node_modules/trough/index.js:57:24)
  at done (./node_modules/trough/wrap.js:55:16)

this is from the latest commit in this branch. any advice would be appreciated

thanks!

k-yle commented 3 years ago

thanks for the help @wooorm, I've made the changes you suggested, and all tests are passing again

wooorm commented 3 years ago

thanks @k-yle, released!