README
@putout/plugin-apply-try-catch
🐊Putout
plugin adds ability to apply tryCatch and tryToCatch.
Install
npm i @putout/plugin-apply-try-catch
Rule
{
"rules": {
"apply-try-catch/try-catch": "on",
"apply-try-catch/try-to-catch": "on",
"apply-try-catch/await": "on",
"apply-try-catch/args": "on",
"apply-try-catch/declare": "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');
License
MIT