Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@putout/engine-runner

Package Overview
Dependencies
Maintainers
1
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@putout/engine-runner

run putout plugins

  • 1.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-8.44%
Maintainers
1
Weekly downloads
 
Created
Source

putout-engine-runner NPM version Dependency Status

Load putout plugins.

Install

npm i @putout/engine-runner

Supported Plugin Types

Template plugins

Template plugins is the most prefarable format of a plugin, simplest to use.

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

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

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

// optional
module.exports.exclude = () => {
};

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

include and exclude returns an array of @babel/types, or code blocks:

const __ = 'hello';

Where __ can be any node. All this possible with help of @putout/compare. Templates format supported in traverse and find plugins as well.

Traverse plugins

Traverse plugins gives you more power to filter and fix nodes you need.

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

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

module.exports.traverse = ({push}) => {
    return {
        'debugger'(path) {
            push(path);
        }
    }
};

Find plugins

Find plugins gives you all the control over traversing, but it's the slowest format. Because traversers not merged in contrast with other plugin formats.

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

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

module.exports.find = (ast, {push, traverse}) => {
    traverse(ast, {
        'debugger'(path) {
            push(path);
        }
    }
};

Replace Plugins

Convert code in declarative way. Simplest possible form, no need to use fix. Just from and to parts.

Simplest replace example:

module.exports.report = () => 'any message here';

module.exports.replace = () => {
    'const a = 1': 'const b = 1',
};

Simplest remove example:

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

module.exports.replace = () => {
    'debugger': '',
};

Templates:

module.exports.report = () => 'any message here';

module.exports.replace = () => {
    'var _a = 1': 'const _a = 1',
};

Example

const {runPlugins} = require('@putout/engine-runner');
const {parse} = require('@putout/engin-parser');

const plugins = [{
    rule: "remove-debugger",
    msg: "",        // optional
    options: {},    // optional
    plugin:
        include: () => ['debugger'],
        fix: (path) => path.remove(),
        report: () => `debugger should not be used`,
}];

const ast = parse('const m = "hi"; debugger');
const places = runPlugins({
    ast,
    shebang: false,     // default
    fix: true,          // default
    fixCount: 1         // default
    plugins,
    parser: 'babel',    // default
});

License

MIT

Keywords

FAQs

Package last updated on 31 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc