@putout/operator-add-args
🐊Putout operator adds ability to add args to referenced variables that was not defined
Last updated 2 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/operator-add-args 
SYNC missed versions from official npm registry.

@putout/operator-add-args NPM version

????Putout operator adds ability to add argument that was not defined before.

Install

npm i putout @putout/operator-add-args

API

If you want to create ????Putout plugin that will add args according to your needs just:

const {operator} = require('putout');
const {addArgs} = operator;

export const {
    report,
    fix,
    traverse,
} = addArgs({
    comparePlaces: ['{comparePlaces}', 'test("__a", (__args) => __body)'],
    t: ['{comparePlaces}', [
        'test("__a", (__args) => __body)',
        'test.only("__a", (__args) => __body)',
    ]],
    maybe: ['{maybe}', [
        'module.exports.__a = (__args) => __body',
    ]],
});

For couple args it will look this way:

export const {
    report,
    fix,
    traverse,
} = addArgs({
    path: ['vars, path', [
        '(__a) => __body',
        '() => __body',
    ]],
});

It will set vars if absent, or keep used name. If you have a file index.spec.js:

-test('', () => {
+test('', ({comparePlaces}) => {
    comparePlaces();
});

Plugin supports options, so you can pass it in .putout.json:

{
    "rules": {
        "tape/add-args": ["on", {
            "args": {
                "comparePlaces": ["{comparePlaces}", "test('__a', (__args) => __body)"]
            }
        }]
    }
}

Exclude

If you want exclude index.spec.js:

test('', (path, printer, semantics, {printComment} => {
    comparePlaces();
});

You can use exclude list:

{
    "rules": {
        "tape/add-args": ["on", {
            "args": {
                "comparePlaces": ["{comparePlaces}", {
                    "include": "test('__a', (__args) => __body)",
                    "exclude": [
                        "(__a, __b, __c, __object) => __object"
                    ]
                }]
            }
        }]
    }
}

type

If you want include only calls, and exclude all other types of nodes, use type:

{
    "rules": {
        "tape/add-args": ["on", {
            "args": {
                "process": ["{process}", {
                    "include": "test('__a', (__args) => __body)",
                    "type": "call"
                }]
            }
        }]
    }
}

And nodes like:

process.hello;

Will be ignored.

License

MIT

Current Tags

  • 15.1.0                                ...           latest (2 months ago)

40 Versions

  • 15.1.0                                ...           2 months ago
  • 15.0.0                                ...           2 months ago
  • 14.1.0                                ...           2 months ago
  • 14.0.0                                ...           3 months ago
  • 13.0.0                                ...           4 months ago
  • 12.1.0                                ...           9 months ago
  • 12.0.0                                ...           10 months ago
  • 11.0.1                                ...           a year ago
  • 11.0.0                                ...           a year ago
  • 10.0.1                                ...           a year ago
  • 10.0.0                                ...           a year ago
  • 9.1.0                                ...           a year ago
  • 9.0.0                                ...           a year ago
  • 8.0.1                                ...           2 years ago
  • 8.0.0                                ...           2 years ago
  • 7.1.0                                ...           3 years ago
  • 7.0.1                                ...           3 years ago
  • 7.0.0                                ...           3 years ago
  • 6.0.3                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.1.0                                ...           3 years ago
  • 5.0.0                                ...           3 years ago
  • 4.4.3                                ...           3 years ago
  • 4.4.2                                ...           3 years ago
  • 4.4.1                                ...           3 years ago
  • 4.4.0                                ...           3 years ago
  • 4.3.0                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (3)
Dev Dependencies (10)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |