-
-
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: rules: add convert-t-raise-to-raise
- Loading branch information
1 parent
86c5230
commit cb5d441
Showing
13 changed files
with
113 additions
and
17 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
4 changes: 4 additions & 0 deletions
4
rules/goldstein/lib/convert-t-compile-to-compile/fixture/done.js
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,4 @@ | ||
test('goldstein: keyword: import', ({compile}) => { | ||
compile('import'); | ||
}); | ||
|
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
3 changes: 3 additions & 0 deletions
3
rules/goldstein/lib/convert-t-raise-to-raise/fixture/convert-t-raise-to-raise-fix.js
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,3 @@ | ||
test('goldstein: keyword: try: not-supported', async ({raise}) => { | ||
await raise('not-supported', `After 'try' only '{', 'await' and 'function call' can come (1:8)`); | ||
}); |
3 changes: 3 additions & 0 deletions
3
rules/goldstein/lib/convert-t-raise-to-raise/fixture/convert-t-raise-to-raise.js
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,3 @@ | ||
test('goldstein: keyword: try: not-supported', (t) => { | ||
t.raise('not-supported', `After 'try' only '{', 'await' and 'function call' can come (1:8)`); | ||
}); |
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,18 @@ | ||
import {types} from 'putout'; | ||
import {transform} from '../transform.js'; | ||
|
||
const { | ||
ObjectProperty, | ||
ObjectPattern, | ||
Identifier, | ||
} = types; | ||
|
||
const COMPUTED = false; | ||
const SHORTHAND = true; | ||
|
||
export const report = () => `Use 'raise()' instead of 't.raise()'`; | ||
|
||
export const replace = () => ({ | ||
't.end()': '', | ||
't.raise(__a, __b)': transform('raise', '__a, __b'), | ||
}); |
19 changes: 19 additions & 0 deletions
19
rules/goldstein/lib/convert-t-raise-to-raise/index.spec.js
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 plugin from './index.js'; | ||
|
||
const test = createTest(import.meta.url, { | ||
printer: 'putout', | ||
plugins: [ | ||
['convert-t-raise-to-raise', plugin], | ||
], | ||
}); | ||
|
||
test('rules: convert-t-raise-to-raise: report', (t) => { | ||
t.report('convert-t-raise-to-raise', `Use 'raise()' instead of 't.raise()'`); | ||
t.end(); | ||
}); | ||
|
||
test('rules: convert-t-raise-to-raise: transform', (t) => { | ||
t.transform('convert-t-raise-to-raise'); | ||
t.end(); | ||
}); |
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,25 @@ | ||
import {types} from 'putout'; | ||
|
||
const { | ||
ObjectProperty, | ||
ObjectPattern, | ||
Identifier, | ||
} = types; | ||
|
||
const COMPUTED = false; | ||
const SHORTHAND = true; | ||
|
||
export const transform = (name, args) => (vars, path) => { | ||
const {block} = path.scope; | ||
|
||
path.scope.block.async = true; | ||
|
||
const id = Identifier(name); | ||
const param = ObjectPattern([ | ||
ObjectProperty(id, id, COMPUTED, SHORTHAND), | ||
]); | ||
|
||
block.params = [param]; | ||
|
||
return `await ${name}(${args})`; | ||
}; |
1 change: 0 additions & 1 deletion
1
rules/goldstein/test/fixture/convert-t-compile-to-compile-fix.js
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,4 +1,3 @@ | ||
test('goldstein: keyword: import', async ({compile}) => { | ||
await compile('import'); | ||
t.end(); | ||
}); |
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,3 @@ | ||
test('goldstein: keyword: try: not-supported', (t) => { | ||
t.raise('not-supported', `After 'try' only '{', 'await' and 'function call' can come (1:8)`); | ||
}); |
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,3 @@ | ||
test('goldstein: keyword: try: not-supported', (t) => { | ||
t.raise('not-supported', `After 'try' only '{', 'await' and 'function call' can come (1:8)`); | ||
}); |
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