Skip to content

Commit 0638f16

Browse files
committed
style: lint fmt
1 parent 34d9c75 commit 0638f16

Some content is hidden

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

41 files changed

+5264
-1602
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ node_modules
22
types
33
demo
44
dist
5-
swc_build
5+
swc_build

.eslintrc.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,36 @@ module.exports = {
33
parser: '@typescript-eslint/parser',
44
parserOptions: {
55
ecmaVersion: 6,
6-
sourceType: 'module'
6+
sourceType: 'module',
77
},
88
env: {
99
es6: true,
1010
browser: true,
1111
jest: true,
1212
commonjs: true,
13-
node: true
13+
node: true,
1414
},
15-
plugins: [
16-
'@typescript-eslint',
17-
'prettier'
18-
],
19-
extends: [
20-
'eslint:recommended',
21-
'plugin:@typescript-eslint/eslint-recommended',
22-
'plugin:@typescript-eslint/recommended',
23-
'prettier/@typescript-eslint'
24-
],
15+
plugins: ['@typescript-eslint'],
16+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
2517
globals: {
2618
wx: true,
2719
App: true,
2820
Page: true,
29-
Component: true
21+
Component: true,
22+
Behavior: true,
3023
},
3124
rules: {
32-
'prettier/prettier': 'error',
25+
'no-console': 0,
3326
'@typescript-eslint/ban-ts-ignore': 'off',
3427
'@typescript-eslint/no-empty-function': 'off',
3528
'@typescript-eslint/explicit-function-return-type': 'off',
3629
'@typescript-eslint/no-explicit-any': 'off',
37-
'@typescript-eslint/no-non-null-assertion': 'off'
30+
'@typescript-eslint/no-non-null-assertion': 'off',
31+
indent: ['error', 2, { SwitchCase: 1 }],
32+
'comma-spacing': 'error',
33+
semi: ['error', 'never'],
34+
quotes: ['error', 'single'],
35+
'object-curly-spacing': ['error', 'always'],
36+
'@typescript-eslint/ban-ts-comment': 'off',
3837
},
39-
}
38+
}

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ npm run dev // 构建 dev 版本
4040

4141
```js
4242
// component.js
43-
const computedBehavior = require("miniprogram-computed").behavior;
44-
const behaviorTest = require("./behavior-test"); // 引入自定义 behavior
43+
const computedBehavior = require('miniprogram-computed').behavior
44+
const behaviorTest = require('./behavior-test') // 引入自定义 behavior
4545

4646
Component({
4747
behaviors: [behaviorTest, computedBehavior],
@@ -53,18 +53,18 @@ Component({
5353
sum(data) {
5454
// 注意: computed 函数中不能访问 this ,只有 data 对象可供访问
5555
// 这个函数的返回值会被设置到 this.data.sum 字段中
56-
return data.a + data.b + data.c; // data.c 为自定义 behavior 数据段
56+
return data.a + data.b + data.c // data.c 为自定义 behavior 数据段
5757
},
5858
},
5959
methods: {
6060
onTap() {
6161
this.setData({
6262
a: this.data.b,
6363
b: this.data.a + this.data.b,
64-
});
64+
})
6565
},
6666
},
67-
});
67+
})
6868
```
6969

7070
```js
@@ -73,7 +73,7 @@ module.exports = Behavior({
7373
data: {
7474
c: 2,
7575
},
76-
});
76+
})
7777
```
7878

7979
```xml
@@ -86,7 +86,7 @@ module.exports = Behavior({
8686
### watch 基本用法
8787

8888
```js
89-
const computedBehavior = require("miniprogram-computed").behavior;
89+
const computedBehavior = require('miniprogram-computed').behavior
9090

9191
Component({
9292
behaviors: [computedBehavior],
@@ -96,21 +96,21 @@ Component({
9696
sum: 2,
9797
},
9898
watch: {
99-
"a, b": function (a, b) {
99+
'a, b': function (a, b) {
100100
this.setData({
101101
sum: a + b,
102-
});
102+
})
103103
},
104104
},
105105
methods: {
106106
onTap() {
107107
this.setData({
108108
a: this.data.b,
109109
b: this.data.a + this.data.b,
110-
});
110+
})
111111
},
112112
},
113-
});
113+
})
114114
```
115115

116116
```xml
@@ -125,7 +125,7 @@ Component({
125125
由于通过 behavior 的方式引入不能获得类型支持, 因此为了获得类型的支持, 可以使用一个辅助组件构造器:
126126

127127
```ts
128-
import { ComponentWithComputed } from "miniprogram-computed";
128+
import { ComponentWithComputed } from 'miniprogram-computed'
129129

130130
ComponentWithComputed({
131131
data: {
@@ -134,20 +134,20 @@ ComponentWithComputed({
134134
sum: 2,
135135
},
136136
watch: {
137-
"a, b": function (a, b) {
137+
'a, b': function (a, b) {
138138
this.setData({
139139
sum: a + b,
140-
});
140+
})
141141
},
142142
},
143143
computed: {
144144
sum(data) {
145145
// 注意: computed 函数中不能访问 this ,只有 data 对象可供访问
146146
// 这个函数的返回值会被设置到 this.data.sum 字段中
147-
return data.a + data.b + data.sum; // data.c 为自定义 behavior 数据段
147+
return data.a + data.b + data.sum // data.c 为自定义 behavior 数据段
148148
},
149149
},
150-
});
150+
})
151151
```
152152

153153
当使用该构造器的时候, 编译器可以给 `computed``watch` 提供自动提示和类型支持。
@@ -158,7 +158,7 @@ ComponentWithComputed({
158158

159159
**关于 TS 兼容问题**
160160

161-
若在小程序中用 `TypeScript` 进行开发并使用到了 `Component` 构造器。这时定义 `computed``watch` 字段会出现类型报错。
161+
若在小程序中用 `TypeScript` 进行开发并使用到了 `Component` 构造器。这时定义 `computed``watch` 字段会出现类型报错。
162162

163163
针对此问题,推荐使用 `ComponentWithComputed` 构造器代替 `Component` 构造器。
164164

@@ -215,7 +215,7 @@ ComponentWithComputed({
215215
`watch` 字段上可以使用 `**` 通配符,是它能够监听这个字段下的子字段的变化(类似于小程序基础库本身的 observers )。
216216

217217
```js
218-
const computedBehavior = require("miniprogram-computed").behavior;
218+
const computedBehavior = require('miniprogram-computed').behavior
219219

220220
Component({
221221
behaviors: [computedBehavior],
@@ -226,20 +226,20 @@ Component({
226226
},
227227
},
228228
watch: {
229-
"obj.**": function (obj) {
229+
'obj.**': function (obj) {
230230
this.setData({
231231
sum: obj.a + obj.b,
232-
});
232+
})
233233
},
234234
},
235235
methods: {
236236
onTap() {
237237
this.setData({
238-
"obj.a": 10,
239-
});
238+
'obj.a': 10,
239+
})
240240
},
241241
},
242-
});
242+
})
243243
```
244244

245245
除此以外:
@@ -248,4 +248,5 @@ Component({
248248
- 对于使用了 `**` 通配符的字段,则会进行深比较,来尝试精确检测对象是否真的发生了变化,这要求对象字段不能包含循环(类似于 `JSON.stringify` )。
249249

250250
### 关于低版本兼容
251-
对于 IOS `9.3` 以下的版本,由于无法原生支持 `Proxy`,这里会使用 `proxy-polyfill` 去代替。
251+
252+
对于 IOS `9.3` 以下的版本,由于无法原生支持 `Proxy`,这里会使用 `proxy-polyfill` 去代替。

UPDATE.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
## 0.0.6
22

3-
* 支持 properties。
3+
- 支持 properties。
44

55
## 0.0.7
66

7-
* 修复 setData 设置 properties 会报 can't call setData in computed getter function! 问题
7+
- 修复 setData 设置 properties 会报 can't call setData in computed getter function! 问题
88

99
## 2.0.0
1010

11-
* 基于 observers 重构,开始支持 watch
11+
- 基于 observers 重构,开始支持 watch
1212

1313
## 2.1.0
1414

15-
* 支持 watch 的 `.**` 语法
15+
- 支持 watch 的 `.**` 语法
1616

1717
## 3.0.0
1818

19-
* 修复 computed 中使用自定义 behavior 数据段时,初始化视图的 computed data 不渲染的问题。
20-
* 支持 mobx-miniprogram 扩展库。
21-
* 更新 computed 数据追踪方式。
19+
- 修复 computed 中使用自定义 behavior 数据段时,初始化视图的 computed data 不渲染的问题。
20+
- 支持 mobx-miniprogram 扩展库。
21+
- 更新 computed 数据追踪方式。
2222

2323
## 4.0.0
2424

25-
* 使用 TypeScript 重构。
26-
* 优化部分生命周期逻辑。
25+
- 使用 TypeScript 重构。
26+
- 优化部分生命周期逻辑。
2727

2828
# 4.1.1
2929

30-
* 优化打包方式
31-
* 优化 dev 开发流程
30+
- 优化打包方式
31+
- 优化 dev 开发流程
3232

3333
# 4.2.x
3434

35-
* 增加 polyfill
35+
- 增加 polyfill
3636

3737
# 4.3.0
3838

39-
* 修复引用类型的部分问题
39+
- 修复引用类型的部分问题

config/base.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import path from "path";
1+
import path from 'path'
22

33
export interface BaseConfig {
4-
entry: string;
5-
srcPath: string;
6-
bundlePath: string;
7-
demoPath: string;
8-
bundleInDemoPath: string;
9-
typesPath: string;
10-
swcBuildPath: string;
11-
tsConfigPath: string;
4+
entry: string
5+
srcPath: string
6+
bundlePath: string
7+
demoPath: string
8+
bundleInDemoPath: string
9+
typesPath: string
10+
swcBuildPath: string
11+
tsConfigPath: string
1212
}
1313

14-
const srcPath = path.resolve(__dirname, "../src");
15-
const bundlePath = path.resolve(__dirname, "../dist");
16-
const demoPath = path.resolve(__dirname, "../demo");
17-
const bundleInDemoPath = path.resolve(demoPath, "./computed");
18-
const swcBuildPath = path.resolve(__dirname, "../swc_build");
19-
const typesPath = path.resolve(__dirname, "../types");
20-
const tsConfigPath = path.resolve(__dirname, "../tsconfig.json");
14+
const srcPath = path.resolve(__dirname, '../src')
15+
const bundlePath = path.resolve(__dirname, '../dist')
16+
const demoPath = path.resolve(__dirname, '../demo')
17+
const bundleInDemoPath = path.resolve(demoPath, './computed')
18+
const swcBuildPath = path.resolve(__dirname, '../swc_build')
19+
const typesPath = path.resolve(__dirname, '../types')
20+
const tsConfigPath = path.resolve(__dirname, '../tsconfig.json')
2121

2222
export const baseConfig: BaseConfig = {
23-
entry: "index",
23+
entry: 'index',
2424
srcPath, // 源码路径
2525
bundlePath, // 编译产物路径
2626
demoPath, // demo 路径
2727
bundleInDemoPath, // 编译产物在 demo 里的路径
2828
typesPath, // .d.ts 类型声明路径
2929
swcBuildPath, // swc 转译生成路径
3030
tsConfigPath, // tsc 配置文件
31-
};
31+
}

config/build.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
const swcOptions = {
99
jsc: {
1010
parser: {
11-
syntax: "typescript",
11+
syntax: 'typescript',
1212
tsx: false,
1313
decorators: false,
1414
dynamicImport: false,
1515
},
1616
transform: null,
17-
target: "es5",
17+
target: 'es5',
1818
externalHelpers: false,
1919
keepClassNames: false,
2020
minify: {
@@ -26,29 +26,29 @@ const swcOptions = {
2626
},
2727
minify: false,
2828
module: {
29-
type: "commonjs",
29+
type: 'commonjs',
3030
strict: false,
3131
strictMode: true,
3232
lazy: false,
3333
noInterop: false,
3434
},
35-
};
35+
}
3636

3737
// esbuild 配置
3838
const esbuildOptions = {
39-
outfile: "index.js",
39+
outfile: 'index.js',
4040
bundle: true,
41-
format: "cjs",
41+
format: 'cjs',
4242
minify: true,
43-
external: ["rfdc", "fast-deep-equal"]
44-
};
43+
external: ['rfdc', 'fast-deep-equal'],
44+
}
4545

4646
export interface BuildConfig {
47-
swcOptions: any;
48-
esbuildOptions: any;
47+
swcOptions: any
48+
esbuildOptions: any
4949
}
5050

5151
export const buildConfig: BuildConfig = {
5252
swcOptions,
5353
esbuildOptions,
54-
};
54+
}

config/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { baseConfig, BaseConfig } from "./base";
2-
import { buildConfig, BuildConfig } from "./build";
1+
import { baseConfig, BaseConfig } from './base'
2+
import { buildConfig, BuildConfig } from './build'
33

44
interface Config extends BaseConfig, BuildConfig {}
55

66
const config: Config = {
77
...baseConfig,
88
...buildConfig,
9-
};
9+
}
1010

11-
export default config;
11+
export default config

0 commit comments

Comments
 (0)