npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@putout/eslint

v3.5.0

Published

Wrapper that simplifies ESLint API and makes it compatible with 🐊Putout

Downloads

16,043

Readme

@putout/eslint NPM version

Wrapper that simplifies ESLint API and makes it compatible with 🐊Putout.

☝️ FlatConfig supported from the box.

Install

npm i @putout/eslint

Environment Variables

  • ☝️ To set custom config file for ESLint use ESLINT_CONFIG_FILE env variable:
  • ☝️ To disable ESLint support use NO_ESLINT=1 env variable:
  • ☝️ If you want to ignore ESLint warnings (which is unfixable errors in 🐊Putout language) use NO_ESLINT_WARNINGS=1:
NO_ESLINT_WARNINGS=1 putout --fix lib

## API

### `eslint(options)`

**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:

```js
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,
});

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

And you can even override any of ESLint ⚙️ options with help of config property:

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

If you want to apply 🐊Putout transformations using putout/putout ESLint rule, enable 🐊Putout with the same called but lowercased 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.

createPlugin(options)

You can also simplify creating of plugins for ESLint with help of createPlugin. 🐊Putout-based ESLint plugin are highly inspired by Putout Plugins API of Includer.

So it must contain classic 4 methods:

module.exports.report = () => 'debugger statement should not be used';

module.exports.fix = (path) => {
    return '';
};

module.exports.include = () => [
    'DebuggerStatement',
];

module.exports.filter = (path) => {
    return true;
};

The main difference with Includer is:

  • fix works with text;
  • include does not support 🦎PutoutScript;
  • there is no exclude;

Take a look at more sophisticated example, rule remove-duplicate-extensions:

const getValue = ({source}) => source?.value;

module.exports.report = () => 'Avoid duplicate extensions in relative imports';
module.exports.include = () => [
    'ImportDeclaration',
    'ImportExpression',
    'ExportAllDeclaration',
    'ExportNamedDeclaration',
];

module.exports.fix = ({text}) => {
    return text.replace('.js.js', '.js');
};

module.exports.filter = ({node}) => {
    const value = getValue(node);
    return /\.js\.js/.test(value);
};

To use it just add couple lines to your main plugin file:

const {createPlugin} = require('@putout/eslint/create-plugin');

const createRule = (a) => ({
    [a]: createPlugin(require(`./${a}`)),
});

module.exports.rules = {
    ...createRule('remove-duplicate-extensions'),
};

Or just:

const {createPlugin} = require('@putout/eslint/create-plugin');

module.exports.rules = {
    'remove-duplicate-extensions': createPlugin(require('./remove-duplicate-extensions')),
};

lint(source, {fix, plugins, options, filename})

When you need to run ESLint with one plugin (rule), just use lint it will do the thing.

const lint = require('@putout/eslint/lint');
const {createPlugin} = require('@putout/eslint/create-plugin');
const removeDebugger = require('./remove-debugger');

const [code, places] = lint('debugger', {
    fix: true, // default
    plugins: [
        ['remove-debugger', createPlugin(removeDebugger)],
    ],
});

When you want to skip plugins, and just provide options and filename you can:

const lint = require('@putout/eslint/lint');

const [code, places] = lint('debugger', {
    filename: 'index.js',
    options: [{
        rules: {
            semi: 'error',
        },
    }],
});

License

MIT