@putout/plugin-apply-try-catch
putout plugin adds ability apply try-catch
Last updated 4 years ago by coderaiser .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @putout/plugin-apply-try-catch 
SYNC missed versions from official npm registry.

@putout/plugin-apply-try-catch NPM version

????Putout plugin adds ability to apply tryCatch and tryToCatch. Renamed to @putout/plugin-try-catch.

Install

npm i @putout/plugin-apply-try-catch

Rule

{
    "rules": {
        "apply-try-catch/await": "on",
        "apply-try-catch/args": "on",
        "apply-try-catch/declare": "on",
        "apply-try-catch/expand-arguments": "on",
        "apply-try-catch/try-catch": "on",
        "apply-try-catch/try-to-catch": "on"
    }
}

try-catch

❌ Example of incorrect code

try {
    log('hello');
} catch(error) {
}

✅ Example of correct code

import tryCatch from 'try-catch';
const [error] = tryCatch(log, 'hello');

try-to-catch

❌ Example of incorrect code

try {
    await send('hello');
} catch(error) {
}

✅ Example of correct code

import tryToCatch from 'try-catch';
const [error] = await tryToCatch(send, 'hello');

await

❌ Example of incorrect code

await tryCatch(a, b);
tryToCatch(a, b);

✅ Example of correct code

await tryToCatch(a, b);

args

❌ Example of incorrect code

tryCatch(send('hello'));

✅ Example of correct code

tryCatch(send, 'hello');

declare

❌ Example of incorrect code

const [error] = tryCatch(fs.readFileSync, 'hello.txt');

✅ Example of correct code

import tryCatch from 'try-catch';
const [error] = tryCatch(fs.readFileSync, 'hello.txt');

expand-arguments

❌ Example of incorrect code

import tryCatch from 'try-catch';

test('some message', (t) => {
    const fn = () => copymitter('/hello');
    const [error] = tryCatch(fn);
    
    t.equal(error.message, 'to should be a string!');
    t.end();
});

✅ Example of correct code

import tryCatch from 'try-catch';

test('some message', (t) => {
    const [error] = tryCatch(copymitter, '/hello');
    
    t.equal(error.message, 'to should be a string!');
    t.end();
});

License

MIT

Current Tags

  • 2.8.1                                ...           latest (4 years ago)

15 Versions

  • 2.8.1                                ...           4 years ago
  • 2.8.0                                ...           4 years ago
  • 2.7.0                                ...           4 years ago
  • 2.6.1                                ...           4 years ago
  • 2.6.0                                ...           4 years ago
  • 2.5.0                                ...           4 years ago
  • 2.4.0                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (8)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |