Skip to content

putout v24.3.0

Choose a tag to compare

@coderaiser coderaiser released this 24 Jan 17:39
· 12162 commits to master since this release

ESLint API

image

Forget the years, forget distinctions. Leap into the boundless and make it your home!
Zhuangzi

Hi foks! Let's talk about ESLint API a little bit more.

ESLint begins his work as a formatter when 🐊Putout done his transformations. That's why it used a lot in different parts of application, for testing purpose and using API in a simplest possible way. You can access it with:

import {eslint} from 'putout/eslint';

To use it simply write:

const [source, places] = await eslint({
    name: 'hello.js',
    code: `const t = 'hi'\n`,
    fix: false,
    config: {
        extends: [
            'plugin:putout/recommended',
        ],
    },
});

Isn't it looks similar to 🐊Putout way? It definitely is! But... It has a couple differences you should remember:

If you want to apply 🐊Putout transformations using putout/putout ESLint rule, enable putout with the same called flag:

const [source, places] = await eslint({
    name: 'hello.js',
    code: `const t = 'hi'\n`,
    fix: true,
    putout: true,
    config: {
        extends: [
            'plugin:putout/recommended',
        ],
    },
});

It is disabled by default, because ESLint always runs after 🐊Putout transformations, so there is no need to traverse tree again.

What with 🎩ESCover?

🎩ESCover is ready to be used in a regular basis 🎉!
The only thing is: it works with EcmaScript Modules only. And this is for a reason: for CommonJS you can use c8 and nyc/istanbul. But there is no tool that shows coverage for files changed with node loaders.

What's inside of 🎩ESCover?

Inside of 🎩ESCover you can find the plugin for 🐊Putout which sets markers that should be called.
Results saved to coverage/lcov.info to read them when done.

-☝️ lcov was created in 2002, almost twenty years ago.
-☝️ Linux kernel developers created it to know what is going on with the coverage.
-☝️ It's written in PERL and has text based format.
-☝️ This is most popular coverage format of all times supported by a lot of tools (like coveralls).

So if we run our ESM application with:

estrace npm test

We will receive something similar to:

SF:/Users/coderaiser/escover/lib/transform.js
DA:1,1
DA:3,1
DA:7,1
DA:9,1
DA:10,1
DA:12,1
DA:24,1
DA:25,1
DA:27,1
DA:28,1
DA:29,1
DA:32,1
end_of_record

Where:

  • SF - is path to source;
  • DA - is line number, and count of running;
  • end_of_record latest recored for current file entry;

As for me this is really human readable, and very compact form. The only thing I don't get for now is: counters, I see no reason why do I need them 🤷‍♂️, if you have a reason create an issue. It can be added in one line of code.

That's all for today!
Have a nice day 🏝!

🔥 feature

  • (putout) eslint: add ability to enable putout/putout rule with a flag
  • (putout/eslint) add ability to enable putout