Skip to content

putout v23.6.0

Choose a tag to compare

@coderaiser coderaiser released this 09 Jan 18:27
· 12361 commits to master since this release

🎩 A Couple words about coverage

image

Astride the Ox, I reach home.
I am serene. The Ox too can rest.
The dawn has come. In blissful repose,
Within my thatched dwelling
I have abandoned the whip and ropes.
(c) Zen Ten Bulls

Hi guys!

I think you know that 🐊Putout has 100% test coverage. Why so? The thing is writing parsers is very hard task, but wary not! There is a helpers 😏 !

Mock the import!

Mock-import exists for about a year and used to mock things when you using EcmaScript Modules. It uses 🐊Putout and changes ImportDeclarations to VariableDeclaration when you need it the most.
So such code:

import {readFile} from 'fs/promises';

Becomes:

const {readFile} = global.__mockImportCache.get('fs/promises');

It works amazing! But there is a problem with coverage:

Taking into accord this two factors...

🧨 New player in the game get you covered!

One more coverage tool come into world: 🎩 ESCover. It's also based on 🐊Putout and what t does is changing:

export const sum = (a, b) => {
    return a + b;
};

Into this:

export const sum = (a, b) => {
    return __c4['🧨'](5, 4), a + b;
};

__c4 is a variable with a special meaning. It provides function which gives information about line and number of current instruction.
Here is how report looks like when every thing is fine:

# CAP version 13

1..3
# files: 3
# covered: 3

# 🌴 ok

When something isn't right:

# CAP version 13

# /Users/coderaiser/escover/example/example.js
🧨 should be covered
---
lines:
 ️- 1 at file:///Users/coderaiser/escover/example/example.js:1

1..3
# files: 3
# covered: 2

# 🧨 fail: 1

🎩ESCover on early stages of development, so a lot things can change!

🤷‍♂️ What more can I do with 🐊Putout?

You can trace execution of functions with help of ESTrace. It provides such information:

coderaiser@cloudcmd:~/estrace$ node --loader estrace example/lint.js
..💣 lint([]) 16.05mb file:///Users/coderaiser/estrace/example/lint.js:5
....💣 getFiles([]) 16.05mb file:///Users/coderaiser/estrace/example/lint.js:12
....💥 getFiles 16.06mb file:///Users/coderaiser/estrace/example/lint.js:12
....💣 lintFiles([]) 16.06mb file:///Users/coderaiser/estrace/example/lint.js:22
....💥 lintFiles 16.06mb file:///Users/coderaiser/estrace/example/lint.js:22
..💥 lint 16.06mb file:///Users/coderaiser/estrace/example/lint.js:5

And does such transformations. Let's suppost you have a function: const fn = (a) => a. EStrace will replace it with:

const fn = (a) => {
    try {
        var __estrace_context = __estrace.enter('<anonymous:2>', 'file://hello.js:2', arguments);
        return a;
    } finally {
        __estrace.exit('<anonymous:2>', 'file://hello.js:2', __estrace_context);
    }
};

🤷‍♂️ What with new rules?

@putout/plugin-convert-commonjs-to-esm doesn't require simport anymore. Only built-in modules 💪 (Thanks to @putout/plugin-declare-undefined-variables which supports native node.js modules, and will declare it, when you use it 😉).

@putout/plugin-nodejs got new rule: convert-dirname-to-url. What it does?

Changes:

import {readFile} from 'fs/promises';
const file1 = join(__dirname, '../../package.json');

To:

import {readFile} from 'fs/promises';
const file1 = new URL('../../package.json', import.meta.url).pathname;

This will help to get rid of __dirname in EcmaScript Modules. Here is fast draft and results.

🦔 Real world uses

I just found out (I knew that they were going, but who knew…) that folks from Stylelint used 🐊 Putout to convert their codebase to ESM 🎉 but got a little problems with jest: it doesn't recognize import.meta.url 🤷‍♂️. This is why 📼 Supertape exists, simple testing with native speed.
Thank you guys! That's awesome and very inspiring!

That's all for today! Happy holidays 🎄!

🐞 fix

  • (@putout/engine-runner) find: options
  • (eslint-plugin-putout) add-newline-after-function-call: multiple empty lines
  • feature(@putout/plugin-declare-undefined-variables) add fixtures
  • feature(@putout/engine-runner) add support to clear replace watermarks after fix round is done
  • (@putout/engine-parser) btoa: get back node v14 support
  • (@putout/engine-parser) sourcemap url

🔥 feature

  • (package) @putout/plugin-nodejs v2.0.0
  • (@putout/plugin-nodejs) drop support of putout < 23
  • (@putout/plugin-nodejs) add convert-dirname-to-url
  • (@putout/plugin-putout) declare: add isESM
  • (package) @putout/plugin-convert-commonjs-to-esm v7.0.0
  • (@putout/plugin-convert-commonjs-to-esm) drop support of putout < 23
  • (@putout/plugin-convert-commonjs-to-esm) commonjs: use node.js built-ins, instead of simport
  • (@putout/operator-declare) add ability to pass only "esm" or only "commonjs"
  • (@putout/eslint-config) padding-line-between-statements: add newline before "for", after block-like
  • (eslint-plugin-putout) add-newline-before-function-call: add support of AssignmentExpression
  • (@putout/plugin-tape) add convert-equal-to-deep-equal
  • (@putout/plugin-gitignore) add support of .idea
  • (@putout/plugin-eslint) add apply-safe-align
  • (eslint-plugin-putout) add safe+align
  • (@putout/plugin-declare-undefined-variables) add fixtures
  • (@putout/plugin-putout) declare: add compareAny, compareAll
  • (@putout/plugin-putout) declare: add replaceWithMultiple
  • (@putout/plugin-convert-commonjs-to-esm) require: add support of MemberExpression
  • (@putout/plugin-tape) convert-equal-to-not-ok: add support of equal/notEqual with one argument passed
  • (@putout/plugin-remove-useless-return) add support of nested functions
  • (@putout/compare) is: parseTemplate: avoid caching exception as undefined
  • (@putout/engine-runner) add support to clear replace watermarks after fix round is done