Skip to content

Commit 4a04864

Browse files
hiroppyevilebottnawi
authored andcommitted
style: introduce prettier (#1647)
1 parent 4767a31 commit 4a04864

Some content is hidden

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

66 files changed

+1735
-681
lines changed

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": "webpack",
2+
"extends": ["webpack", "prettier"],
33
"globals": {
44
"document": true,
55
"window": true
@@ -12,7 +12,7 @@
1212
"consistent-return": "off",
1313
"no-param-reassign": "off",
1414
"no-underscore-dangle": "off",
15-
"prefer-destructuring": ["error", {"object": false, "array": false}],
15+
"prefer-destructuring": ["error", { "object": false, "array": false }],
1616
"prefer-rest-params": "off",
1717
"strict": ["error", "safe"]
1818
}

.github/ISSUE_TEMPLATE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
General questions, how-to questions, and support requests will be closed.
77
-->
88

9-
* Operating System:
10-
* Node Version:
11-
* NPM Version:
12-
* webpack Version:
13-
* webpack-dev-server Version:
9+
- Operating System:
10+
- Node Version:
11+
- NPM Version:
12+
- webpack Version:
13+
- webpack-dev-server Version:
1414

1515
<!--
1616
Please place an x, no spaces, in all [ ] that apply
@@ -37,11 +37,11 @@
3737
-->
3838

3939
```js
40-
// webpack.config.js
40+
// webpack.config.js
4141
```
4242

4343
```js
44-
// additional code, remove if not needed.
44+
// additional code, remove if not needed.
4545
```
4646

4747
### Expected Behavior

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
client-src/live/web_modules/
2+
node_modules
3+
CHANGELOG.md

.prettierrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
printWidth: 80,
3+
tabWidth: 2,
4+
singleQuote: true,
5+
trailingComma: 'es5',
6+
arrowParens: 'always',
7+
overrides: [
8+
{
9+
files: '*.json',
10+
options: {
11+
useTabs: false,
12+
},
13+
},
14+
],
15+
};

CONTRIBUTING.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,18 @@ Pull requests often need some real-world testing.
3939

4040
1. In your `package.json`, change the line with `webpack-dev-server` to:
4141

42-
```json
43-
"webpack-dev-server": "github:webpack/webpack-dev-server#pull/<ID>/head"
44-
```
42+
```json
43+
"webpack-dev-server": "github:webpack/webpack-dev-server#pull/<ID>/head"
44+
```
4545

46-
`<ID>` is the ID of the pull request.
46+
`<ID>` is the ID of the pull request.
4747

4848
2. Run `npm install`.
4949

5050
3. Go to the `webpack-dev-server` module (`cd node_modules/webpack-dev-server`), and run `npm run prepublish`.
5151

5252
The pull request is now ready to be tested.
5353

54+
---
5455

55-
------------
56-
57-
*Many thanks to [create-react-app](https://github.com/facebookincubator/create-react-app/blob/master/CONTRIBUTING.md) for the inspiration with this contributing guide*
56+
_Many thanks to [create-react-app](https://github.com/facebookincubator/create-react-app/blob/master/CONTRIBUTING.md) for the inspiration with this contributing guide_

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The easiest way to use it is with the CLI. In the directory where your
5454
```console
5555
node_modules/.bin/webpack-dev-server
5656
```
57+
5758
_**Note**: Many CLI options are available with `webpack-dev-server`. Explore this [link](https://webpack.js.org/configuration/dev-server/)._
5859

5960
### With NPM Scripts
@@ -154,25 +155,18 @@ This project is heavily inspired by [peerigon/nof5](https://github.com/peerigon/
154155

155156
#### [MIT](./LICENSE)
156157

157-
158158
[npm]: https://img.shields.io/npm/v/webpack-dev-server.svg
159159
[npm-url]: https://npmjs.com/package/webpack-dev-server
160-
161160
[node]: https://img.shields.io/node/v/webpack-dev-server.svg
162161
[node-url]: https://nodejs.org
163-
164162
[deps]: https://david-dm.org/webpack/webpack-dev-server.svg
165163
[deps-url]: https://david-dm.org/webpack/webpack-dev-server
166-
167164
[tests]: http://img.shields.io/travis/webpack/webpack-dev-server.svg
168165
[tests-url]: https://travis-ci.org/webpack/webpack-dev-server
169-
170166
[cover]: https://codecov.io/gh/webpack/webpack-dev-server/branch/master/graph/badge.svg
171167
[cover-url]: https://codecov.io/gh/webpack/webpack-dev-server
172-
173168
[chat]: https://badges.gitter.im/webpack/webpack.svg
174169
[chat-url]: https://gitter.im/webpack/webpack
175-
176170
[docs-url]: https://webpack.js.org/configuration/dev-server/#devserver
177171
[hash-url]: https://twitter.com/search?q=webpack
178172
[middleware-url]: https://github.com/webpack/webpack-dev-middleware

bin/options.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const options = {
2424
inline: {
2525
type: 'boolean',
2626
default: true,
27-
describe: 'Inline mode (set to false to disable including client scripts like livereload)'
27+
describe:
28+
'Inline mode (set to false to disable including client scripts like livereload)'
2829
},
2930
progress: {
3031
type: 'boolean',
@@ -158,7 +159,8 @@ const options = {
158159
},
159160
'allowed-hosts': {
160161
type: 'string',
161-
describe: 'A comma-delimited string of hosts that are allowed to access the dev server',
162+
describe:
163+
'A comma-delimited string of hosts that are allowed to access the dev server',
162164
group: CONNECTION_GROUP
163165
}
164166
};

bin/utils.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
const open = require('opn');
1111

1212
const colors = {
13-
info (useColor, msg) {
13+
info(useColor, msg) {
1414
if (useColor) {
1515
// Make text blue and bold, so it *pops*
1616
return `\u001b[1m\u001b[34m${msg}\u001b[39m\u001b[22m`;
1717
}
1818

1919
return msg;
2020
},
21-
error (useColor, msg) {
21+
error(useColor, msg) {
2222
if (useColor) {
2323
// Make text red and bold, so it *pops*
2424
return `\u001b[1m\u001b[31m${msg}\u001b[39m\u001b[22m`;
@@ -33,12 +33,14 @@ const defaultTo = (value, def) => {
3333
return value == null ? def : value;
3434
};
3535

36-
function version () {
37-
return `webpack-dev-server ${require('../package.json').version}\n` +
38-
`webpack ${require('webpack/package.json').version}`;
36+
function version() {
37+
return (
38+
`webpack-dev-server ${require('../package.json').version}\n` +
39+
`webpack ${require('webpack/package.json').version}`
40+
);
3941
}
4042

41-
function status (uri, options, log, useColor) {
43+
function status(uri, options, log, useColor) {
4244
const contentBase = Array.isArray(options.contentBase)
4345
? options.contentBase.join(', ')
4446
: options.contentBase;
@@ -55,13 +57,19 @@ function status (uri, options, log, useColor) {
5557

5658
if (contentBase) {
5759
log.info(
58-
`Content not from webpack is served from ${colors.info(useColor, contentBase)}`
60+
`Content not from webpack is served from ${colors.info(
61+
useColor,
62+
contentBase
63+
)}`
5964
);
6065
}
6166

6267
if (options.historyApiFallback) {
6368
log.info(
64-
`404s will fallback to ${colors.info(useColor, options.historyApiFallback.index || '/index.html')}`
69+
`404s will fallback to ${colors.info(
70+
useColor,
71+
options.historyApiFallback.index || '/index.html'
72+
)}`
6573
);
6674
}
6775

@@ -88,14 +96,14 @@ function status (uri, options, log, useColor) {
8896
}
8997
}
9098

91-
function bonjour (options) {
99+
function bonjour(options) {
92100
const bonjour = require('bonjour')();
93101

94102
bonjour.publish({
95103
name: 'Webpack Dev Server',
96104
port: options.port,
97105
type: 'http',
98-
subtypes: [ 'webpack' ]
106+
subtypes: ['webpack']
99107
});
100108

101109
process.on('exit', () => {

bin/webpack-dev-server.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ const webpack = require('webpack');
2727

2828
const options = require('./options');
2929

30-
const {
31-
colors,
32-
status,
33-
version,
34-
bonjour,
35-
defaultTo
36-
} = require('./utils');
30+
const { colors, status, version, bonjour, defaultTo } = require('./utils');
3731

3832
const Server = require('../lib/Server');
3933

@@ -43,7 +37,7 @@ const createLogger = require('../lib/utils/createLogger');
4337

4438
let server;
4539

46-
const signals = [ 'SIGINT', 'SIGTERM' ];
40+
const signals = ['SIGINT', 'SIGTERM'];
4741

4842
signals.forEach((signal) => {
4943
process.on(signal, () => {
@@ -70,7 +64,9 @@ try {
7064
require.resolve('webpack-cli');
7165
} catch (err) {
7266
console.error('The CLI moved into a separate package: webpack-cli');
73-
console.error('Please install \'webpack-cli\' in addition to webpack itself to use the CLI');
67+
console.error(
68+
"Please install 'webpack-cli' in addition to webpack itself to use the CLI"
69+
);
7470
console.error('-> When using npm: npm i -D webpack-cli');
7571
console.error('-> When using yarn: yarn add -D webpack-cli');
7672

@@ -97,7 +93,7 @@ const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
9793
// we should use portfinder.
9894
const DEFAULT_PORT = 8080;
9995

100-
function processOptions (config) {
96+
function processOptions(config) {
10197
// processOptions {Promise}
10298
if (typeof config.then === 'function') {
10399
config.then(processOptions).catch((err) => {
@@ -109,9 +105,7 @@ function processOptions (config) {
109105
return;
110106
}
111107

112-
const firstWpOpt = Array.isArray(config)
113-
? config[0]
114-
: config;
108+
const firstWpOpt = Array.isArray(config) ? config[0] : config;
115109

116110
const options = config.devServer || firstWpOpt.devServer || {};
117111

@@ -141,7 +135,8 @@ function processOptions (config) {
141135

142136
if (!options.publicPath) {
143137
// eslint-disable-next-line
144-
options.publicPath = firstWpOpt.output && firstWpOpt.output.publicPath || '';
138+
options.publicPath =
139+
(firstWpOpt.output && firstWpOpt.output.publicPath) || '';
145140

146141
if (
147142
!/^(https?:)?\/\//.test(options.publicPath) &&
@@ -214,11 +209,7 @@ function processOptions (config) {
214209
typeof options.stats === 'object' &&
215210
typeof options.stats.colors === 'undefined'
216211
) {
217-
options.stats = Object.assign(
218-
{},
219-
options.stats,
220-
{ colors: argv.color }
221-
);
212+
options.stats = Object.assign({}, options.stats, { colors: argv.color });
222213
}
223214

224215
if (argv.lazy) {
@@ -277,9 +268,10 @@ function processOptions (config) {
277268
// that wouldn't throw errors. E.g. both argv.port and options.port
278269
// were specified, but since argv.port is 8080, options.port will be
279270
// tried first instead.
280-
options.port = argv.port === DEFAULT_PORT
281-
? defaultTo(options.port, argv.port)
282-
: defaultTo(argv.port, options.port);
271+
options.port =
272+
argv.port === DEFAULT_PORT
273+
? defaultTo(options.port, argv.port)
274+
: defaultTo(argv.port, options.port);
283275

284276
if (options.port != null) {
285277
startDevServer(config, options);
@@ -325,7 +317,10 @@ function startDevServer(config, options) {
325317
}).apply(compiler);
326318
}
327319

328-
const suffix = (options.inline !== false || options.lazy === true ? '/' : '/webpack-dev-server/');
320+
const suffix =
321+
options.inline !== false || options.lazy === true
322+
? '/'
323+
: '/webpack-dev-server/';
329324

330325
try {
331326
server = new Server(compiler, options, log);

0 commit comments

Comments
 (0)