-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: goldstein: convert: rm useless import of try-catch
- Loading branch information
1 parent
44a3d27
commit 8192b7a
Showing
6 changed files
with
45 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
import tryCatch from 'try-catch'; | ||
const a = tryCatch(f, 'hello') | ||
const a = tryCatch(f, 'hello'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import tryCatch from 'try-catch'; | ||
const a = tryCatch(f, 'hello') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
import {createGoldsteinTry} from '../../types/try.js'; | ||
|
||
export const report = () => `Use 'try' instead of 'tryCatch/tryToCatch'`; | ||
export const report = () => `Remove import of 'tryCatch/tryToCatch'`; | ||
export const replace = () => ({ | ||
'tryCatch(__args)': createTry({ | ||
async: false, | ||
}), | ||
'await tryToCatch(__args)': createTry({ | ||
async: true, | ||
}), | ||
'import tryCatch from "try-catch"': '', | ||
'import tryToCatch from "try-to-catch"': '', | ||
'const tryCatch = require("try-catch")': '', | ||
'const tryToCatch = require("try-to-catch")': '', | ||
}); | ||
|
||
const createTry = ({async}) => ({__args}, path) => { | ||
const [callee, ...args] = __args; | ||
|
||
path.node.goldstein = createGoldsteinTry({ | ||
async, | ||
callee, | ||
args, | ||
}); | ||
|
||
return path; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {createTest} from '@putout/test'; | ||
import * as removeImportTry from './index.js'; | ||
|
||
const test = createTest(import.meta.url, { | ||
printer: 'putout', | ||
plugins: [ | ||
['remove-import-try', removeImportTry], | ||
], | ||
}); | ||
|
||
test('plugin-goldstein: remove-import-try: report', (t) => { | ||
t.report('try', `Remove import of 'tryCatch/tryToCatch'`); | ||
t.end(); | ||
}); | ||
|
||
test('plugin-goldstein: remove-import-try: transform', (t) => { | ||
t.transform('try'); | ||
t.end(); | ||
}); |