Skip to content

putout v18.0.0

Compare
Choose a tag to compare
@coderaiser coderaiser released this 28 May 11:24
· 7997 commits to master since this release

New API for Processors

Processors had simple but not intuitive API, for example process(rawSource, {fix}) -> [places, processedSource] took two arguments: rawSource and fix from options. It require implementor to take decision about handling boolean option fix, and added conditions in all Processors. Now it's split into two methods:

  • find - returns places that can be shown by putout
  • fix - returns modified source

Also there is new names for preProcess and postProcess:

  • branch(source) -> list - gets javascript array from source
  • merge(source, list) -> source - join list into source

If you wandering:

🤷‍♂️ Why not split and join?
☝️ split is string method and join is array method, so using them in something other with different set of arguments and doing technically different task - makes code unclear and breaks Principle of least astonishment.

🤷‍♂️ Why it looks like a git commands?
☝️ Yes it looks, and there is an idea behind it. Git commands has same names:

  • branch to list branches;
  • merge to merge one branch into another;

So in a similar manner Processor branch splits source into a list of JavaScript sources, and merge do vice versa: join it back.

🤷‍♂️ How to convert processors I already written for putout < v18 to a new format?
☝️ New rule convert-process-to-find was added in @putout/plugin-putout@6.5.0. It will help you to migrate to new API with less possible pain.

🤷‍♂️ How can I test my processors so they was as stable and easily maintainable as putout?
☝️ You can use @putout/test/processor for this purpose, it will help you to write simplest possible tests with help of supertape.

Here is updated working diagram:
image

🐞 fix

  • (@putout/processsor-markdown) rm unused dependencies

🔥 feature

  • (package) @putout/processor-css v3.0.0
  • (package) @putout/processor-json v3.0.0
  • (package) @putout/processor-markdown v5.0.0
  • (package) @putout/processor-javascript v3.0.0
  • (package) @putout/processor-ignore v2.0.0
  • (package) @putout/processor-yaml v2.0.0
  • (package) @putout/engine-processor v4.0.0
  • (@putout/remove-useless-functions) add support of async
  • (@putout/engine-processor) convert process to find
  • (@putout/engine-processor) runProcessors: speed up: 1m13.010s -> 1m11.628s (mac os)