@putout/plugin-apply-overrides
🐊Putout plugin adds ability apply 'overrides'
Last updated 4 months ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @putout/plugin-apply-overrides 
SYNC missed versions from official npm registry.

@putout/plugin-apply-overrides NPM version

🐊Putout plugin adds ability to apply overrides.

Checkout in 🐊Putout Editor.

When you write testable code and want to avoid mocking required or imported modules, one of a solutions to use simple form of dependency injection:

import {readDirSync as _readdirSync} from 'node:fs/promises';

export const readRules = (dirOpt, rulesDir, overrides = {}) => {
    const {
        cwd,
        readdirSync = _readdirSync,
    } = overrides;
};

Pass overrides as last parameter, in this case use can test easily your function readFules:

import {test, stub} from 'supertape';

test('readRules', (t) => {
    const readdirSync = stub().returns([]);
    const rules = readRules('', '', {
        readdirSync,
    });
    
    t.equal(rules, []);
    t.end();
});

Then only issue is, when you have lots of parameters, your function declaration will be to long, or to hard to read, so recommended way is to use overrides variable.

Install

npm i @putout/plugin-apply-overrides

Rule

{
    "rules": {
        "apply-overrides": "on"
    }
}

❌ Example of incorrect code

async function matchToFlatDir(path, config, {readESLintConfig = _readESLintConfig} = {}) {}

✅ Example of correct code

async function matchToFlatDir(path, config, overrides = {}) {
    const {
        readESLintConfig = _readESLintConfig,
    } = overrides;
}

License

MIT

Current Tags

  • 2.1.0                                ...           latest (4 months ago)

6 Versions

  • 2.1.0                                ...           4 months ago
  • 2.0.0                                ...           4 months ago
  • 1.3.0                                ...           8 months ago
  • 1.2.0                                ...           8 months ago
  • 1.1.0                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE