Skip to content

Commit c3d6765

Browse files
committed
feat: update prettierc
1 parent 1bfe002 commit c3d6765

File tree

44 files changed

+746
-830
lines changed

Some content is hidden

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

44 files changed

+746
-830
lines changed

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 120,
6+
"overrides": [
7+
{
8+
"files": ".prettierrc",
9+
"options": { "parser": "json" }
10+
}
11+
]
12+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"license": "MIT",
99
"private": true,
1010
"scripts": {
11-
"format": "yarn prettier --write **/*.md",
11+
"format": "prettier --write **/*.md",
1212
"lint": "textlint **/*.md",
1313
"lint:fix": "yarn lint --fix"
1414
},

前端/2014-09-26-write-article-use-jekyll-github-markdown.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: "写作环境的搭建(Jekyll+GitHub+Markdown)"
3+
title: '写作环境的搭建(Jekyll+GitHub+Markdown)'
44
category: 前端
55
tags: [Jekyll, 写作, Git]
66
published: true

前端/2015-05-14-learning-reactjs.md

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ React 的创建是为了数据的频繁交互:通过组件化轻松展现数
2323
声明变量采用首字母小写
2424

2525
```js
26-
var myDivElement = <div className="foo" />;
27-
React.render(myDivElement, document.body);
26+
var myDivElement = <div className="foo" />
27+
React.render(myDivElement, document.body)
2828
```
2929

3030
### 渲染 React 组件
@@ -34,9 +34,9 @@ React.render(myDivElement, document.body);
3434
```js
3535
var MyComponent = React.createClass({
3636
/*...*/
37-
});
38-
var myElement = <MyComponent someProperty={true} />;
39-
React.render(myElement, document.body);
37+
})
38+
var myElement = <MyComponent someProperty={true} />
39+
React.render(myElement, document.body)
4040
```
4141

4242
## 关于 JSX
@@ -97,19 +97,19 @@ var Component = React.createClass({
9797
<div {...this.props} title="zzz">
9898
this is a div
9999
</div>
100-
);
100+
)
101101
},
102-
});
102+
})
103103

104-
React.render(<Component name="xxx" title="yyy" />, document.body);
104+
React.render(<Component name="xxx" title="yyy" />, document.body)
105105
```
106106

107107
### style 属性
108108

109109
在 React 中写行内样式时,要这样写,不能采用引号的书写方式
110110

111111
```js
112-
React.render(<div style={{ color: "red" }}>xxxxx</div>, document.body);
112+
React.render(<div style={{ color: 'red' }}>xxxxx</div>, document.body)
113113
```
114114

115115
## UI 交互
@@ -119,14 +119,11 @@ React.render(<div style={{ color: "red" }}>xxxxx</div>, document.body);
119119
```js
120120
var HelloWorld = React.createClass({
121121
render: function () {
122-
return <div data-title={this.props.title}>{this.props.content}</div>;
122+
return <div data-title={this.props.title}>{this.props.content}</div>
123123
},
124-
});
124+
})
125125

126-
React.render(
127-
<HelloWorld title="this is title" content="this is content" />,
128-
document.body
129-
);
126+
React.render(<HelloWorld title="this is title" content="this is content" />, document.body)
130127
```
131128

132129
通过`this.props`我们可以拿到组件被使用时的属性,this.props 就是组件的属性集合。React 将组件的子节点封装到了 children 属性中,当子节点只有一个的时候直接通过`this.props.children`获取子节点的内容。当子节点的个数大于 1 时,`this.props.children`返回的是一个数组。
@@ -138,25 +135,22 @@ React.render(
138135
```js
139136
var ColorButton = React.createClass({
140137
getInitialState: function () {
141-
return { bColor: "green" };
138+
return { bColor: 'green' }
142139
},
143140
render: function () {
144141
return (
145-
<button
146-
onClick={this.handleClick}
147-
style={{ backgroundColor: this.state.bColor }}
148-
>
142+
<button onClick={this.handleClick} style={{ backgroundColor: this.state.bColor }}>
149143
click
150144
</button>
151-
);
145+
)
152146
},
153147
// 点击按钮,切换按钮的颜色:
154148
handleClick: function (event) {
155-
this.setState({ bColor: this.state.bColor === "green" ? "red" : "green" });
149+
this.setState({ bColor: this.state.bColor === 'green' ? 'red' : 'green' })
156150
},
157-
});
151+
})
158152

159-
React.render(<ColorButton />, document.body);
153+
React.render(<ColorButton />, document.body)
160154
```
161155

162156
`getInitialState`是用来初始化 state,`handleClick`是用来处理我们点击事件的,如果想要拿到当前操作的 DOM,通过参数 event 获取。
@@ -172,32 +166,32 @@ var RenderComponent = React.createClass({
172166
render: function () {
173167
return (
174168
<ul>
175-
{this.props["data-list"].map(function (item) {
176-
return <li>{item}</li>;
169+
{this.props['data-list'].map(function (item) {
170+
return <li>{item}</li>
177171
})}
178172
</ul>
179-
);
173+
)
180174
},
181-
});
175+
})
182176

183177
var StateComponent = React.createClass({
184178
getInitialState: function () {
185-
return { list: ["xxx", "yyy"] };
179+
return { list: ['xxx', 'yyy'] }
186180
},
187181
render: function () {
188182
return (
189183
<div>
190184
<button onClick={this.handleClick}>click</button>
191185
<RenderComponent data-list={this.state.list} />
192186
</div>
193-
);
187+
)
194188
},
195189
handleClick: function () {
196-
this.setState({ list: [1, 2, 3] });
190+
this.setState({ list: [1, 2, 3] })
197191
},
198-
});
192+
})
199193

200-
React.render(<StateComponent />, document.body);
194+
React.render(<StateComponent />, document.body)
201195
```
202196

203197
React 还允许我们下面的方式自定义属性的默认值:
@@ -206,11 +200,11 @@ React 还允许我们下面的方式自定义属性的默认值:
206200
var ComponentWithDefaultProps = React.createClass({
207201
getDefaultProps: function () {
208202
return {
209-
value: "default value",
210-
};
203+
value: 'default value',
204+
}
211205
},
212206
/* ... */
213-
});
207+
})
214208
```
215209

216210
`getDefaultProps()`的值将会被缓存,当`this.props.value`的值没有被父组件指定时,将会使用这个默认值。
@@ -227,31 +221,23 @@ var Avatar = React.createClass({
227221
<ProfilePic username={this.props.username} />
228222
<ProfileLink username={this.props.username} />
229223
</div>
230-
);
224+
)
231225
},
232-
});
226+
})
233227

234228
var ProfilePic = React.createClass({
235229
render: function () {
236-
return (
237-
<img
238-
src={"http://graph.facebook.com/" + this.props.username + "/picture"}
239-
/>
240-
);
230+
return <img src={'http://graph.facebook.com/' + this.props.username + '/picture'} />
241231
},
242-
});
232+
})
243233

244234
var ProfileLink = React.createClass({
245235
render: function () {
246-
return (
247-
<a href={"http://www.facebook.com/" + this.props.username}>
248-
{this.props.username}
249-
</a>
250-
);
236+
return <a href={'http://www.facebook.com/' + this.props.username}>{this.props.username}</a>
251237
},
252-
});
238+
})
253239

254-
React.render(<Avatar username="pwh" />, document.getElementById("example"));
240+
React.render(<Avatar username="pwh" />, document.getElementById('example'))
255241
```
256242

257243
上面的例子中,组件 Avatar 包含了组件 ProfilePic 和 ProfileLink。在 React 当中,**所有者就是可以设置其他组件 props 的组件**。说的通俗点:如果组件 X 出现在了组件 Y 的 render()方法中,那么组件 Y 就是所有者。正如我们之前所讨论的,组件不能改变 props—props 应同所有者初始化它们时保持一致。
@@ -269,16 +255,16 @@ React.render(<Avatar username="pwh" />, document.getElementById("example"));
269255
```js
270256
var Component = React.createClass({
271257
render: function () {
272-
var results = this.props.results;
258+
var results = this.props.results
273259
return (
274260
<ol>
275261
{results.map(function (result) {
276-
return <li key={result.id}>{result.text}</li>;
262+
return <li key={result.id}>{result.text}</li>
277263
})}
278264
</ol>
279-
);
265+
)
280266
},
281-
});
267+
})
282268
```
283269

284270
### 单向数据流

前端/2015-05-31-reactjs_tutorial_part_1.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,7 @@ block content
139139
接下来我们在`public/javascripts/src/`目录中创建一个简单的 react.js 组件,`helloworld.jsx`
140140

141141
```js
142-
React.render(
143-
<h1>Hello, world from React.js!</h1>,
144-
document.getElementById("example")
145-
);
142+
React.render(<h1>Hello, world from React.js!</h1>, document.getElementById('example'))
146143
```
147144

148145
> Because we are using the `react-tools` node package, we want to add the compiled javascript code to our templates. Change you `views/layout.jade` file to the following:

前端/2015-06-06-reactjs_tutorial_part_2.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ $ npm install --save-dev gulp
3535
Gulp 安装好之后,我们建立一个`gulpfile.js`文件:
3636

3737
```js
38-
var gulp = require("gulp");
38+
var gulp = require('gulp')
3939

40-
gulp.task("default", function () {
40+
gulp.task('default', function () {
4141
// place code for your default task here
42-
});
42+
})
4343
```
4444

4545
> Now we need to install the Gulp packages that we will need to build our application. To start, let's install [browserify](https://www.npmjs.com/package/browserify), [reactify](https://www.npmjs.com/package/reactify) and [vinyl-source-stream](https://www.npmjs.com/package/vinyl-source-stream). To install these packages, run the following command:
@@ -71,21 +71,21 @@ $ npm install --save-dev react browserify reactify vinyl-source-stream
7171
下一步就是编写 Gulp 任务来将`.jsx`文件自动编译成可用的 JavaScript 文件。一个 Gulp 任务就是一个函数,包含编译文件的一系列步骤。我们需要修改`gulpfile.js`
7272

7373
```js
74-
var gulp = require("gulp");
74+
var gulp = require('gulp')
7575

76-
var browserify = require("browserify");
77-
var reactify = require("reactify");
78-
var source = require("vinyl-source-stream");
76+
var browserify = require('browserify')
77+
var reactify = require('reactify')
78+
var source = require('vinyl-source-stream')
7979

80-
gulp.task("js", function () {
81-
browserify("./public/javascripts/src/app.jsx")
80+
gulp.task('js', function () {
81+
browserify('./public/javascripts/src/app.jsx')
8282
.transform(reactify)
8383
.bundle()
84-
.pipe(source("app.js"))
85-
.pipe(gulp.dest("public/javascripts/build/"));
86-
});
84+
.pipe(source('app.js'))
85+
.pipe(gulp.dest('public/javascripts/build/'))
86+
})
8787

88-
gulp.task("default", ["js"]);
88+
gulp.task('default', ['js'])
8989
```
9090

9191
> Now running `gulp` from the command line will trigger the build of our React app; however, there are some things we need to do to our react app first!
@@ -103,10 +103,10 @@ gulp.task("default", ["js"]);
103103
首先,我们需要为 browersify 创建一个入口,建立一个`app.jsx`文件就可以了:
104104

105105
```js
106-
var React = require("react");
107-
var HelloWorld = require("./HelloWorld.jsx");
106+
var React = require('react')
107+
var HelloWorld = require('./HelloWorld.jsx')
108108

109-
React.render(<HelloWorld />, document.getElementById("example"));
109+
React.render(<HelloWorld />, document.getElementById('example'))
110110
```
111111

112112
> This file is taking our `HelloWorld` component and rendering it in the div with id "example". This code is taken from our original `helloworld.jsx` file from last tutorial. Instead of doing everything in that file, we are now requiring a module `HelloWorld` and rendering it in `app.jsx`. The reason for this is that as our application gets more complex, we have more control of how our files are broken out.
@@ -118,13 +118,13 @@ React.render(<HelloWorld />, document.getElementById("example"));
118118
下一件事是已有的`helloworld.jsx`文件修改成 React 组件,`HelloWorld.jsx`
119119

120120
```js
121-
var React = require("react");
121+
var React = require('react')
122122

123123
module.exports = React.createClass({
124124
render: function () {
125-
return <h1>Hello, world from a React.js Component!</h1>;
125+
return <h1>Hello, world from a React.js Component!</h1>
126126
},
127-
});
127+
})
128128
```
129129

130130
> Notice that the `HelloWorld.jsx` and `app.jsx` files are combined to be very similar to how the 'helloworld.jsx' looked. Again, the reason for breaking our app into these two files are for future modules to be added.
@@ -159,17 +159,17 @@ body
159159
为了更好得使用 Gulp,我们可以实现一个内建的`watch`功能,能够自动监测和编译`.jsx`文件。添加任务:
160160

161161
```js
162-
gulp.task("watch", function () {
163-
gulp.watch("public/javascripts/src/**/*.jsx", ["js"]);
164-
});
162+
gulp.task('watch', function () {
163+
gulp.watch('public/javascripts/src/**/*.jsx', ['js'])
164+
})
165165
```
166166

167167
> Also add that task to your default Gulp task:
168168
169169
同时将`watch`任务添加到默认任务中:
170170

171171
```js
172-
gulp.task("default", ["js", "watch"]);
172+
gulp.task('default', ['js', 'watch'])
173173
```
174174

175175
> Now when we run `gulp` it will watch for changes in our `.jsx` and rebuild our javascript with that change! Awesome!

前端/2015-06-22-reactjs_tutorial_part_interlude.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ $ bower install bootstrap-sass-official --save
105105
现在`bootstrap-sass-official`库已经安装好,我们可以将我们想要使用的 Bootstrap 更新到`style.scss`。到现在为止,我们直接导入整个 bootstrap 库,让我们更新`style.scss`如下所示:
106106

107107
```css
108-
@import "../../libraries/bootstrap-sass-official/assets/stylesheets/bootstrap";
108+
@import '../../libraries/bootstrap-sass-official/assets/stylesheets/bootstrap';
109109

110110
body {
111111
padding: 50px;
112-
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
112+
font: 14px 'Lucida Grande', Helvetica, Arial, sans-serif;
113113
}
114114

115115
a {
@@ -163,8 +163,8 @@ link(rel='stylesheet', href='/stylesheets/css/style.css')
163163
在介绍 Twitter Bootstrap 之后,我们还需要加入新的 JavaScript 库:jQuery。由于我们已经可以将 JSX 代码编译成 JavaScript,让我们花点时间把 JavaScript 连接到单个`app.js`中。只需要告诉 JSX 导入相应的库即可,由于我们已经使用了 browserify,所以很简单就可以加入到`app.jsx`文件:
164164

165165
```js
166-
var $ = (jQuery = require("../../libraries/jquery/dist/jquery"));
167-
var bootstrap = require("../../libraries/bootstrap-sass-official/assets/javascripts/bootstrap");
166+
var $ = (jQuery = require('../../libraries/jquery/dist/jquery'))
167+
var bootstrap = require('../../libraries/bootstrap-sass-official/assets/javascripts/bootstrap')
168168
```
169169

170170
> Doing this points both `jQuery ($)` and `bootstrap` to the appropriate file which were installed via Bower. When we re-run our browserify gulp task, these two libraries get pulled in! Simple as that.

0 commit comments

Comments
 (0)