Skip to content

Commit e5acbb2

Browse files
committed
Merge branch 'dev' of https://github.com/originjs/vue-codemod into dev
2 parents be2c9a1 + 1944c9e commit e5acbb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1537
-743
lines changed

.eslintignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.github
2+
bin
3+
playground
4+
src/__tests__
5+
transformations/__testfixtures__
6+
transformations/__tests__
7+
vue-transformations/__testfixtures__
8+
vue-transformations/__tests__
9+
.editorconfig
10+
.eslintignore
11+
.eslintrc.js
12+
.gitignore
13+
.prettierignore
14+
.prettierrc
15+
LICENSE
16+
package.json
17+
README.md
18+
tsconfig.json
19+
yarn.lock

.eslintrc.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const DOMGlobals = ['window', 'document']
2+
const NodeGlobals = ['module', 'require']
3+
4+
module.exports = {
5+
parser: '@typescript-eslint/parser',
6+
parserOptions: {
7+
sourceType: 'module'
8+
},
9+
rules: {
10+
'no-unused-vars': [
11+
'error',
12+
// we are only using this rule to check for unused arguments since TS
13+
// catches unused variables but not args.
14+
{ varsIgnorePattern: '.*', args: 'none' }
15+
],
16+
// since we target ES2015 for baseline support, we need to forbid object
17+
// rest spread usage (both assign and destructure)
18+
'no-restricted-syntax': [
19+
'error',
20+
'ObjectExpression > SpreadElement',
21+
'ObjectPattern > RestElement'
22+
]
23+
},
24+
overrides: [
25+
// tests, no restrictions (runs in Node / jest with jsdom)
26+
{
27+
files: ['**/__tests__/**', 'test-dts/**'],
28+
rules: {
29+
'no-restricted-globals': 'off',
30+
'no-restricted-syntax': 'off'
31+
}
32+
},
33+
// shared, may be used in any env
34+
{
35+
files: ['packages/shared/**'],
36+
rules: {
37+
'no-restricted-globals': 'off'
38+
}
39+
},
40+
// Packages targeting DOM
41+
{
42+
files: ['packages/{vue,vue-compat,runtime-dom}/**'],
43+
rules: {
44+
'no-restricted-globals': ['error', ...NodeGlobals]
45+
}
46+
},
47+
// Packages targeting Node
48+
{
49+
files: ['packages/{compiler-sfc,compiler-ssr,server-renderer}/**'],
50+
rules: {
51+
'no-restricted-globals': ['error', ...DOMGlobals],
52+
'no-restricted-syntax': 'off'
53+
}
54+
},
55+
// Private package, browser only + no syntax restrictions
56+
{
57+
files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
58+
rules: {
59+
'no-restricted-globals': ['error', ...NodeGlobals],
60+
'no-restricted-syntax': 'off'
61+
}
62+
}
63+
]
64+
}

.prettierignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.github
2+
bin
3+
playground
4+
src/__tests__
5+
transformations/__testfixtures__
6+
transformations/__tests__
7+
vue-transformations/__testfixtures__
8+
vue-transformations/__tests__
9+
.editorconfig
10+
.eslintignore
11+
.eslintrc.js
12+
.gitignore
13+
.prettierignore
14+
.prettierrc
15+
LICENSE
16+
package.json
17+
README.md
18+
tsconfig.json
19+
yarn.lock

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
semi: false
2+
singleQuote: true
3+
printWidth: 80
4+
trailingComma: 'none'
5+
endOfLine: 'lf'
6+
arrowParens: 'avoid'

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
"build": "tsc",
1313
"prepublishOnly": "tsc",
1414
"playground": "npm run build && cd ./playground && npm install && npm run dev",
15-
"test": "jest"
15+
"test": "jest",
16+
"fix": "npm-run-all --parallel lint:fix format:fix",
17+
"lint:codes": "eslint . --ext .ts",
18+
"lint:fix": "npm run lint:codes --fix",
19+
"format:prettier": "prettier --config .prettierrc .",
20+
"format:fix": "prettier --write --config .prettierrc ."
1621
},
1722
"repository": {
1823
"type": "git",
@@ -43,8 +48,11 @@
4348
"@types/lodash": "^4.14.170",
4449
"@types/node": "^12.12.47",
4550
"@types/yargs": "^15.0.4",
51+
"@typescript-eslint/parser": "^4.27.0",
52+
"eslint": "^7.29.0",
4653
"jest": "^26.1.0",
47-
"prettier": "^2.0.4",
54+
"npm-run-all": "^4.1.5",
55+
"prettier": "^2.3.1",
4856
"ts-jest": "^26.1.1",
4957
"typescript": "^4.1.3"
5058
},
@@ -56,10 +64,6 @@
5664
"<rootDir>/node_modules/"
5765
]
5866
},
59-
"prettier": {
60-
"semi": false,
61-
"singleQuote": true
62-
},
6367
"engines": {
6468
"node": ">= 10.0"
6569
}

src/VueTransformation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
interface FileInfo {
22
/** The absolute path to the current file. */
3-
path: string;
3+
path: string
44
/** The source code of the current file. */
5-
source: string;
5+
source: string
66
}
77

88
interface Options {
9-
[option: string]: any;
9+
[option: string]: any
1010
}
1111

1212
export default interface VueTransformation {
13-
(file: FileInfo, options: Options): string | null | undefined | void;
13+
(file: FileInfo, options: Options): string | null | undefined | void
1414
type: string
1515
}

src/astUtils.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
Expression,
1010
ObjectExpression,
1111
FunctionExpression,
12-
ArrowFunctionExpression,
12+
ArrowFunctionExpression
1313
} from 'jscodeshift'
1414
import type { Context } from './wrapAstTransformation'
1515

@@ -42,8 +42,9 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
4242
return null
4343
}
4444

45-
const declarationKind = declarator.closest(j.VariableDeclaration).nodes()[0]
46-
.kind
45+
const declarationKind = declarator
46+
.closest(j.VariableDeclaration)
47+
.nodes()[0].kind
4748

4849
if (declarationKind !== 'const') {
4950
// TODO: check reassignments (=, for in)
@@ -54,7 +55,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
5455
}
5556

5657
function hasRenderOrTemplateProps(obj: ObjectExpression) {
57-
return obj.properties.some((prop) => {
58+
return obj.properties.some(prop => {
5859
// skip spread properties
5960
if (j.SpreadElement.check(prop) || j.SpreadProperty.check(prop)) {
6061
return false
@@ -124,7 +125,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
124125

125126
return (
126127
returnStatements.length > 0 &&
127-
returnStatements.every((path) =>
128+
returnStatements.every(path =>
128129
!!path.node.argument ? isPromiseExpression(path.node.argument) : true
129130
)
130131
)
@@ -146,7 +147,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
146147
comp: ASTNode | null,
147148
{
148149
mayBeAsyncComponent = false,
149-
shouldCheckProps = false,
150+
shouldCheckProps = false
150151
}: {
151152
mayBeAsyncComponent?: boolean
152153
shouldCheckProps?: boolean
@@ -172,13 +173,13 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
172173
// export default {}
173174
const defaultObjectExport = root
174175
.find(j.ExportDefaultDeclaration)
175-
.map((path) => {
176+
.map(path => {
176177
const decl = path.node.declaration
177178

178179
if (
179180
isLikelyVueOptions(decl, {
180181
shouldCheckProps: !isInSFC,
181-
mayBeAsyncComponent: !isInSFC,
182+
mayBeAsyncComponent: !isInSFC
182183
})
183184
) {
184185
return wrapOptionsInPaths(decl)
@@ -188,7 +189,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
188189
const init = getConstDeclarationInit(decl)
189190
return isLikelyVueOptions(init, {
190191
shouldCheckProps: !isInSFC,
191-
mayBeAsyncComponent: !isInSFC,
192+
mayBeAsyncComponent: !isInSFC
192193
})
193194
? wrapOptionsInPaths(init)
194195
: null
@@ -220,7 +221,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
220221

221222
return false
222223
})
223-
.map((path) => {
224+
.map(path => {
224225
const arg = path.node.arguments[0]
225226
if (isLikelyVueOptions(arg)) {
226227
return wrapOptionsInPaths(arg)
@@ -242,10 +243,10 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
242243
.find(j.NewExpression, {
243244
callee: {
244245
type: 'Identifier',
245-
name: 'Vue',
246-
},
246+
name: 'Vue'
247+
}
247248
})
248-
.map((path) => {
249+
.map(path => {
249250
const arg = path.node.arguments[0]
250251
if (isLikelyVueOptions(arg)) {
251252
return wrapOptionsInPaths(arg)
@@ -275,7 +276,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
275276
node.callee.property.name === 'component'
276277
)
277278
})
278-
.map((path) => {
279+
.map(path => {
279280
if (path.node.arguments.length !== 2) {
280281
return null
281282
}
@@ -311,7 +312,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
311312
}
312313

313314
const componentsProp = node.properties.find(
314-
(prop) =>
315+
prop =>
315316
j.ObjectProperty.check(prop) &&
316317
((j.Identifier.check(prop.key) && prop.key.name === 'components') ||
317318
(j.StringLiteral.check(prop.key) && prop.key.value === 'components'))
@@ -338,7 +339,7 @@ export function getVueOptions(context: Context): Collection<VueOptionsType> {
338339
}
339340

340341
const subComponentDefinitions = componentsObject.properties
341-
.map((prop) => {
342+
.map(prop => {
342343
if (j.ObjectProperty.check(prop)) {
343344
if (isLikelyVueOptions(prop.value, { mayBeAsyncComponent: true })) {
344345
return prop.value

src/operationUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type Operation = {
1717
export function insertTextAt(index: number, text: string): Operation {
1818
return {
1919
range: [index, index],
20-
text,
20+
text
2121
}
2222
}
2323

@@ -101,7 +101,7 @@ export function replaceText(
101101
export function replaceTextRange(range: number[], text: string): Operation {
102102
return {
103103
range,
104-
text,
104+
text
105105
}
106106
}
107107

@@ -125,6 +125,6 @@ export function remove(nodeOrToken: Node | Token): Operation {
125125
export function removeRange(range: number[]): Operation {
126126
return {
127127
range,
128-
text: '',
128+
text: ''
129129
}
130130
}

src/runTransformation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type JSTransformationModule =
3030
type VueTransformationModule =
3131
| VueTransformation
3232
| {
33-
default: VueTransformation,
33+
default: VueTransformation
3434
}
3535

3636
export type TransformationModule =
@@ -138,7 +138,7 @@ export default function runTransformation(
138138
j,
139139
jscodeshift: j,
140140
stats: () => {},
141-
report: () => {},
141+
report: () => {}
142142
}
143143

144144
const out = transformation(fileInfo, api, params)

0 commit comments

Comments
 (0)