Skip to content

Commit ee0d544

Browse files
xrkffggAmour1688
andauthored
chore: add tslint (#37)
* chore: tslint * chore: workflow lint Co-authored-by: Amour1688 <[email protected]>
1 parent 6b0b753 commit ee0d544

File tree

10 files changed

+322
-107
lines changed

10 files changed

+322
-107
lines changed

.eslintrc.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,31 @@ module.exports = {
1212
jest: true,
1313
es6: true,
1414
},
15-
extends: 'eslint-config-airbnb-base',
15+
parser: '@typescript-eslint/parser',
16+
plugins: ['@typescript-eslint', 'import'],
17+
extends: [
18+
'eslint-config-airbnb-base',
19+
'plugin:@typescript-eslint/recommended'
20+
],
1621
rules: {
1722
'no-nested-ternary': [0],
1823
'no-param-reassign': [0],
1924
'no-use-before-define': [0],
2025
'no-plusplus': [0],
2126
'import/no-extraneous-dependencies': [0],
2227
'consistent-return': [0],
23-
'no-bitwise': [0]
28+
'no-bitwise': [0],
29+
'prefer-destructuring': [2, { 'array': false }],
30+
'import/extensions': [2, 'ignorePackages', { ts: 'never' }],
31+
'@typescript-eslint/ban-ts-comment': [0],
32+
'@typescript-eslint/explicit-module-boundary-types': [0],
33+
'@typescript-eslint/no-explicit-any': [0]
2434
},
35+
settings: {
36+
'import/resolver': {
37+
node: {
38+
extensions: ['.js', '.jsx', '.ts', '.tsx']
39+
}
40+
}
41+
}
2542
};

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ jobs:
1010
uses: actions/checkout@v2
1111

1212
- name: install
13-
run: yarn install --pure-lockfile
14-
13+
run: yarn install
14+
15+
- name: lint
16+
run: yarn lint
17+
1518
- name: test
1619
run: yarn test

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"publish": "lerna publish",
88
"test": "lerna run test",
9+
"lint": "lerna run lint",
910
"dev": "node scripts/dev.js",
1011
"site": "node scripts/site.js"
1112
},

packages/babel-plugin-jsx/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"scripts": {
1414
"dev": "npm run build && webpack-dev-server",
1515
"build": "tsc",
16-
"lint": "eslint --ext .js src",
16+
"lint": "eslint 'src/*.ts'",
1717
"test": "npm run build && jest --coverage"
1818
},
1919
"bugs": {
@@ -27,6 +27,7 @@
2727
"@ant-design-vue/babel-helper-vue-transform-on": "^1.0.0",
2828
"@babel/helper-module-imports": "^7.0.0",
2929
"@babel/plugin-syntax-jsx": "^7.0.0",
30+
"@babel/traverse": "^7.0.0",
3031
"@babel/types": "^7.0.0",
3132
"camelcase": "^6.0.0",
3233
"html-tags": "^3.1.0",
@@ -37,6 +38,8 @@
3738
"@babel/preset-env": "^7.0.0",
3839
"@rollup/plugin-babel": "^5.0.3",
3940
"@types/svg-tags": "^1.0.0",
41+
"@typescript-eslint/eslint-plugin": "^3.6.1",
42+
"@typescript-eslint/parser": "^3.6.1",
4043
"@vue/compiler-dom": "3.0.0-rc.1",
4144
"@vue/test-utils": "2.0.0-beta.0",
4245
"babel-jest": "^26.0.1",

packages/babel-plugin-jsx/src/parseDirectives.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as t from '@babel/types';
22
import { NodePath } from '@babel/traverse';
33
import { createIdentifier } from './utils';
4-
import { State, ExcludesBoolean } from './';
4+
import { State, ExcludesBoolean } from '.';
5+
6+
type Tag = t.Identifier | t.MemberExpression | t.StringLiteral | t.CallExpression;
57

68
/**
79
* Get JSX element type
@@ -17,32 +19,31 @@ const getType = (path: NodePath<t.JSXOpeningElement>) => {
1719
}
1820
return t.isJSXIdentifier(attribute.get('name'))
1921
&& (attribute.get('name') as NodePath<t.JSXIdentifier>).get('name') === 'type'
20-
&& t.isStringLiteral(attribute.get('value'))
21-
},
22-
);
22+
&& t.isStringLiteral(attribute.get('value'));
23+
});
2324

2425
return typePath ? typePath.get('value.value') : '';
2526
};
2627

2728
const parseModifiers = (value: t.Expression) => {
2829
let modifiers: string[] = [];
2930
if (t.isArrayExpression(value)) {
30-
modifiers = (value as t.ArrayExpression).elements.map(el => t.isStringLiteral(el) ? el.value : '').filter(Boolean)
31+
modifiers = (value as t.ArrayExpression).elements.map((el) => (t.isStringLiteral(el) ? el.value : '')).filter(Boolean);
3132
}
3233
return modifiers;
33-
}
34+
};
3435

3536
const parseDirectives = (args: {
3637
name: string,
3738
path: NodePath<t.JSXAttribute>,
3839
value: t.StringLiteral | t.Expression | null,
3940
state: State,
40-
tag: t.Identifier | t.MemberExpression | t.StringLiteral | t.CallExpression,
41+
tag: Tag,
4142
isComponent: boolean
4243
}) => {
4344
const {
4445
name, path, value, state, tag, isComponent,
45-
} = args
46+
} = args;
4647
let modifiers: string[] = name.split('_');
4748
let arg;
4849
let val;
@@ -93,14 +94,19 @@ const parseDirectives = (args: {
9394
};
9495
};
9596

96-
const resolveDirective = (path: NodePath<t.JSXAttribute>, state: State, tag: any, directiveName: string) => {
97+
const resolveDirective = (
98+
path: NodePath<t.JSXAttribute>,
99+
state: State,
100+
tag: Tag,
101+
directiveName: string,
102+
) => {
97103
if (directiveName === 'show') {
98104
return createIdentifier(state, 'vShow');
99105
}
100106
if (directiveName === 'model') {
101107
let modelToUse;
102108
const type = getType(path.parentPath as NodePath<t.JSXOpeningElement>);
103-
switch (tag.value) {
109+
switch ((tag as t.StringLiteral).value) {
104110
case 'select':
105111
modelToUse = createIdentifier(state, 'vModelSelect');
106112
break;
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// https://github.com/vuejs/vue-next/blob/master/packages/shared/src/patchFlags.ts
2+
// tslint:disable: no-bitwise
23
export const enum PatchFlags {
34
TEXT = 1,
45
CLASS = 1 << 1,
@@ -17,17 +18,17 @@ export const enum PatchFlags {
1718

1819
// dev only flag -> name mapping
1920
export const PatchFlagNames = {
20-
[PatchFlags.TEXT]: `TEXT`,
21-
[PatchFlags.CLASS]: `CLASS`,
22-
[PatchFlags.STYLE]: `STYLE`,
23-
[PatchFlags.PROPS]: `PROPS`,
24-
[PatchFlags.FULL_PROPS]: `FULL_PROPS`,
25-
[PatchFlags.HYDRATE_EVENTS]: `HYDRATE_EVENTS`,
26-
[PatchFlags.STABLE_FRAGMENT]: `STABLE_FRAGMENT`,
27-
[PatchFlags.KEYED_FRAGMENT]: `KEYED_FRAGMENT`,
28-
[PatchFlags.UNKEYED_FRAGMENT]: `UNKEYED_FRAGMENT`,
29-
[PatchFlags.DYNAMIC_SLOTS]: `DYNAMIC_SLOTS`,
30-
[PatchFlags.NEED_PATCH]: `NEED_PATCH`,
31-
[PatchFlags.HOISTED]: `HOISTED`,
32-
[PatchFlags.BAIL]: `BAIL`
33-
}
21+
[PatchFlags.TEXT]: 'TEXT',
22+
[PatchFlags.CLASS]: 'CLASS',
23+
[PatchFlags.STYLE]: 'STYLE',
24+
[PatchFlags.PROPS]: 'PROPS',
25+
[PatchFlags.FULL_PROPS]: 'FULL_PROPS',
26+
[PatchFlags.HYDRATE_EVENTS]: 'HYDRATE_EVENTS',
27+
[PatchFlags.STABLE_FRAGMENT]: 'STABLE_FRAGMENT',
28+
[PatchFlags.KEYED_FRAGMENT]: 'KEYED_FRAGMENT',
29+
[PatchFlags.UNKEYED_FRAGMENT]: 'UNKEYED_FRAGMENT',
30+
[PatchFlags.DYNAMIC_SLOTS]: 'DYNAMIC_SLOTS',
31+
[PatchFlags.NEED_PATCH]: 'NEED_PATCH',
32+
[PatchFlags.HOISTED]: 'HOISTED',
33+
[PatchFlags.BAIL]: 'BAIL',
34+
};

packages/babel-plugin-jsx/src/sugar-fragment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as t from '@babel/types'
1+
import * as t from '@babel/types';
22
import { addNamespace } from '@babel/helper-module-imports';
33
import { NodePath } from '@babel/traverse';
4-
import { State } from './';
4+
import { State } from '.';
55

66
const transformFragment = (path: NodePath<t.JSXElement>, Fragment: t.JSXMemberExpression) => {
77
const children = path.get('children') || [];

0 commit comments

Comments
 (0)