Skip to content

Commit 7c9ca03

Browse files
author
Adolph-WSY
authored
chore: declare the reference for the operationUtils file (#69)
1 parent a676ddd commit 7c9ca03

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

bin/vue-codemod.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const {
3030
runAllTransformation: runAllTransformation,
3131
params
3232
} = yargs
33-
.usage('Usage: $0 [file pattern]')
33+
.usage('Usage: vue-codemod [file pattern] <option>')
3434
.option('transformation', {
3535
alias: 't',
3636
type: 'string',
@@ -63,6 +63,16 @@ const {
6363

6464
// TODO: port the `Runner` interface of jscodeshift
6565
async function main() {
66+
if (
67+
(transformationName == undefined || transformationName == '') &&
68+
runAllTransformation == undefined
69+
) {
70+
console.log(
71+
'You need at least one option in command, enter vue-codemod -h to see help. '
72+
)
73+
return
74+
}
75+
6676
// Remind user to back up files
6777
const answer = question(
6878
'Warning!!\n' +

src/operationUtils.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import type { Node } from 'vue-eslint-parser/ast/nodes'
22
import type { Token } from 'vue-eslint-parser/ast/tokens'
3-
// import * as fixutils from "./fixUtils";
3+
/**
4+
* The following function is adapted from https://github.com/eslint/eslint/blob/master/lib/linter/rule-fixer.js
5+
* MIT License https://github.com/eslint/eslint/blob/master/LICENSE
6+
*/
7+
48
export type Operation = {
59
range: number[]
610
text: string
711
}
8-
// TODO: for simplicity of implementation, we've skipped all `{ ...expr }` cases
912

1013
/**
1114
* Creates a fix command that inserts text at the specified index in the source text.
1215
* @param {int} index The 0-based index at which to insert the new text.
1316
* @param {string} text The text to insert.
14-
* @returns {Object} The fix command.
17+
* @returns {Operation} The fix command.
1518
* @private
1619
*/
1720
export function insertTextAt(index: number, text: string): Operation {
@@ -26,7 +29,7 @@ export function insertTextAt(index: number, text: string): Operation {
2629
* The fix is not applied until applyFixes() is called.
2730
* @param {Node|Token} nodeOrToken The node or token to insert after.
2831
* @param {string} text The text to insert.
29-
* @returns {Object} The fix command.
32+
* @returns {Operation} The fix command.
3033
*/
3134
export function insertTextAfter(
3235
nodeOrToken: Node | Token,
@@ -41,7 +44,7 @@ export function insertTextAfter(
4144
* @param {int[]} range The range to replace, first item is start of range, second
4245
* is end of range.
4346
* @param {string} text The text to insert.
44-
* @returns {Object} The fix command.
47+
* @returns {Operation} The fix command.
4548
*/
4649
export function insertTextAfterRange(range: number[], text: string): Operation {
4750
return insertTextAt(range[1], text)
@@ -52,7 +55,7 @@ export function insertTextAfterRange(range: number[], text: string): Operation {
5255
* The fix is not applied until applyFixes() is called.
5356
* @param {Node|Token} nodeOrToken The node or token to insert before.
5457
* @param {string} text The text to insert.
55-
* @returns {Object} The fix command.
58+
* @returns {Operation} The fix command.
5659
*/
5760
export function insertTextBefore(
5861
nodeOrToken: Node | Token,
@@ -67,7 +70,7 @@ export function insertTextBefore(
6770
* @param {int[]} range The range to replace, first item is start of range, second
6871
* is end of range.
6972
* @param {string} text The text to insert.
70-
* @returns {Object} The fix command.
73+
* @returns {Operation} The fix command.
7174
*/
7275
export function insertTextBeforeRange(
7376
range: number[],
@@ -81,7 +84,7 @@ export function insertTextBeforeRange(
8184
* The fix is not applied until applyFixes() is called.
8285
* @param {Node|Token} nodeOrToken The node or token to remove.
8386
* @param {string} text The text to insert.
84-
* @returns {Object} The fix command.
87+
* @returns {Operation} The fix command.
8588
*/
8689
export function replaceText(
8790
nodeOrToken: Node | Token,
@@ -96,7 +99,7 @@ export function replaceText(
9699
* @param {int[]} range The range to replace, first item is start of range, second
97100
* is end of range.
98101
* @param {string} text The text to insert.
99-
* @returns {Object} The fix command.
102+
* @returns {Operation} The fix command.
100103
*/
101104
export function replaceTextRange(range: number[], text: string): Operation {
102105
return {
@@ -109,7 +112,7 @@ export function replaceTextRange(range: number[], text: string): Operation {
109112
* Creates a fix command that removes the node or token from the source.
110113
* The fix is not applied until applyFixes() is called.
111114
* @param {Node|Token} nodeOrToken The node or token to remove.
112-
* @returns {Object} The fix command.
115+
* @returns {Operation} The fix command.
113116
*/
114117
export function remove(nodeOrToken: Node | Token): Operation {
115118
return removeRange(nodeOrToken.range)
@@ -120,7 +123,7 @@ export function remove(nodeOrToken: Node | Token): Operation {
120123
* The fix is not applied until applyFixes() is called.
121124
* @param {int[]} range The range to remove, first item is start of range, second
122125
* is end of range.
123-
* @returns {Object} The fix command.
126+
* @returns {Operation} The fix command.
124127
*/
125128
export function removeRange(range: number[]): Operation {
126129
return {
@@ -133,7 +136,7 @@ export function removeRange(range: number[]): Operation {
133136
* Get text of Node
134137
* @param {Node} node The node to get text
135138
* @param {string} source The full text of the source code
136-
* @returns {string} The text of the node
139+
* @returns {Operation} The text of the node
137140
*/
138141
export function getText(node: Node, source: string): string {
139142
const start = node?.range[0]

src/packageTransformation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ const globalAddConfig: {
4949
}
5050

5151
/**
52-
* Creates a fix command that inserts text at the specified index in the source text.
53-
* @param {int} index The 0-based index at which to insert the new text.
54-
* @param {string} text The text to insert.
55-
* @returns {Object} The fix command.
56-
* @private
52+
* Upgrade the package.json file
53+
* @returns Whether the conversion was successful
5754
*/
5855
export function transform(): boolean {
5956
debug('Find package.json.')

0 commit comments

Comments
 (0)