Skip to content

Commit d814dfc

Browse files
committed
add flow
1 parent b59b35f commit d814dfc

40 files changed

+550
-258
lines changed

.eslintrc.js

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ const ERROR = 2;
3838
// import type {Bar, Foo} from 'Foo';
3939
// Also supports 'let' and 'const'.
4040
const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
41-
const maxLenIgnorePattern = String.raw`^(?:var|let|const|import type)\s+` +
42-
'{?' + variableNamePattern + '(?:,' + variableNamePattern + ')*}?' +
41+
const maxLenIgnorePattern =
42+
String.raw`^(?:var|let|const|import type)\s+` +
43+
'{?' +
44+
variableNamePattern +
45+
'(?:,' +
46+
variableNamePattern +
47+
')*}?' +
4348
String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./"'\s\d\-]+\)?[^;\n]*[;\n]`;
4449

4550
function getBaseConfig() {
@@ -49,14 +54,7 @@ function getBaseConfig() {
4954
ecmaVersion: 6,
5055
sourceType: 'module',
5156
},
52-
extends:[
53-
"plugin:flowtype/recommended"
54-
]
55-
plugins: [
56-
'babel',
57-
'flowtype',
58-
'react',
59-
],
57+
plugins: ['flowtype', 'react'],
6058

6159
// Tries to match the jshint configuration as closely as possible, with the
6260
// exeception of a few things that jshint doesn't check, but that we really
@@ -129,23 +127,23 @@ function getBaseConfig() {
129127
// Best Practices <http://eslint.org/docs/rules/#best-practices>
130128

131129
// probably a bug, we shouldn't actually even use this yet, because of IE8
132-
'accessor-pairs': [WARNING, {setWithoutGet: true}],
130+
'accessor-pairs': [WARNING, { setWithoutGet: true }],
133131
// probably too noisy ATM
134132
'block-scoped-var': OFF,
135133
// cyclomatic complexity, we're too far gone
136-
'complexity': OFF,
134+
complexity: OFF,
137135
// require return statements to either always or never specify values
138136
'consistent-return': WARNING,
139137
// style guide: Always use brackets, even when optional.
140-
'curly': [WARNING, 'all'],
138+
curly: [WARNING, 'all'],
141139
// we don't do this/care about this
142140
'default-case': OFF,
143141
// disabled in favor of our temporary fork
144142
'dot-notation': OFF,
145143
// we don't do this/care about this, but probably should eventually
146144
'dot-location': OFF,
147145
// disabled as it's too noisy ATM
148-
'eqeqeq': [OFF, 'allow-null'],
146+
eqeqeq: [OFF, 'allow-null'],
149147
// we don't do this/care about this, equivalent to jshint forin
150148
'guard-for-in': OFF,
151149
// we have too many internal examples/tools using this
@@ -183,7 +181,7 @@ function getBaseConfig() {
183181
// Should be effectively equivalent to jshint W028 - allowing the use
184182
// of labels in very specific situations. ESLint no-empty-labels was
185183
// deprecated.
186-
'no-labels': [ERROR, {allowLoop: true, allowSwitch: true}],
184+
'no-labels': [ERROR, { allowLoop: true, allowSwitch: true }],
187185
// lone blocks create no scope, will ignore blocks with let/const
188186
'no-lone-blocks': WARNING,
189187
// equivalent to jshint loopfunc
@@ -195,7 +193,7 @@ function getBaseConfig() {
195193
// equivalent to jshint multistr, consider using es6 template strings
196194
'no-multi-str': ERROR,
197195
// equivalent to jshint W02OFF, similar to no-extend-native
198-
'no-native-reassign': [ERROR, {exceptions: ['Map', 'Set']}],
196+
'no-native-reassign': [ERROR, { exceptions: ['Map', 'Set'] }],
199197
// equivalent to jshint evil/W054
200198
'no-new-func': ERROR,
201199
// don't use constructors for side-effects, equivalent to jshint nonew
@@ -237,17 +235,17 @@ function getBaseConfig() {
237235
// equivalent to jshint withstmt
238236
'no-with': OFF,
239237
// require radix argument in parseInt, we do this in most places already
240-
'radix': WARNING,
238+
radix: WARNING,
241239
// we don't do this/care about this
242240
'vars-on-top': OFF,
243241
// equivalent to jshint immed
244242
'wrap-iife': OFF,
245243
// probably too noisy ATM
246-
'yoda': OFF,
244+
yoda: OFF,
247245

248246
// Strict Mode <http://eslint.org/docs/rules/#strict-mode>
249247
// jshint wasn't checking this, and the compiler should add this anyways
250-
'strict': OFF,
248+
strict: OFF,
251249

252250
// Variables <http://eslint.org/docs/rules/#variables>
253251
// we don't do this/care about this
@@ -269,7 +267,7 @@ function getBaseConfig() {
269267
// using undefined is safe because we enforce no-shadow-restricted-names
270268
'no-undefined': OFF,
271269
// equivalent to jshint unused
272-
'no-unused-vars': [WARNING, {args: 'none'}],
270+
'no-unused-vars': [WARNING, { args: 'none' }],
273271
// too noisy
274272
'no-use-before-define': OFF,
275273

@@ -290,10 +288,10 @@ function getBaseConfig() {
290288
'array-bracket-spacing': WARNING,
291289
// TODO: enable this with consensus on single line blocks
292290
'block-spacing': OFF,
293-
'brace-style': [WARNING, '1tbs', {allowSingleLine: true}],
291+
'brace-style': [WARNING, '1tbs', { allowSingleLine: true }],
294292
// too noisy at the moment, and jshint didn't check it
295-
'camelcase': [OFF, {properties: 'always'}],
296-
'comma-spacing': [WARNING, {before: false, after: true}],
293+
camelcase: [OFF, { properties: 'always' }],
294+
'comma-spacing': [WARNING, { before: false, after: true }],
297295
// jshint had laxcomma, but that was against our style guide
298296
'comma-style': [WARNING, 'last'],
299297
'computed-property-spacing': [WARNING, 'never'],
@@ -308,19 +306,17 @@ function getBaseConfig() {
308306
'id-length': OFF,
309307
'id-match': OFF,
310308
// we weren't enforcing this with jshint, so erroring would be too noisy
311-
'indent': [WARNING, 2, {SwitchCase: 1}],
309+
indent: [WARNING, 2, { SwitchCase: 1 }],
312310
// we use single quotes for JS literals, double quotes for JSX literals
313311
'jsx-quotes': [WARNING, 'prefer-double'],
314312
// we may use extra spaces for alignment
315-
'key-spacing': [OFF, {beforeColon: false, afterColon: true}],
313+
'key-spacing': [OFF, { beforeColon: false, afterColon: true }],
316314
'keyword-spacing': [WARNING],
317315
'lines-around-comment': OFF,
318316
// should be handled by a generic TXT linter instead
319317
'linebreak-style': [OFF, 'unix'],
320318
'max-depth': OFF,
321-
'max-len': [WARNING, 120, 2,
322-
{'ignorePattern': maxLenIgnorePattern},
323-
],
319+
'max-len': [WARNING, 120, 2, { ignorePattern: maxLenIgnorePattern }],
324320
'max-nested-callbacks': OFF,
325321
'max-params': OFF,
326322
'max-statements': OFF,
@@ -357,43 +353,39 @@ function getBaseConfig() {
357353
// too noisy ATM
358354
'object-curly-spacing': OFF,
359355
// makes indentation warnings clearer
360-
'one-var': [WARNING, {initialized: 'never'}],
356+
'one-var': [WARNING, { initialized: 'never' }],
361357
// prefer `x += 4` over `x = x + 4`
362358
'operator-assignment': [WARNING, 'always'],
363359
// equivalent to jshint laxbreak
364360
'operator-linebreak': OFF,
365361
'padded-blocks': OFF,
366362
// probably too noisy on pre-ES5 code
367363
'quote-props': [OFF, 'as-needed'],
368-
'quotes': [WARNING, 'single', 'avoid-escape'],
364+
quotes: [WARNING, 'single', 'avoid-escape'],
369365
'require-jsdoc': OFF,
370-
'semi-spacing': [WARNING, {before: false, after: true}],
366+
'semi-spacing': [WARNING, { before: false, after: true }],
371367
// equivalent to jshint asi/W032
372-
'semi': [WARNING, 'always'],
368+
semi: [WARNING, 'always'],
373369
'sort-vars': OFF,
374370
// require `if () {` instead of `if (){`
375371
'space-before-blocks': [WARNING, 'always'],
376372
// require `function foo()` instead of `function foo ()`
377-
'space-before-function-paren': [
378-
WARNING,
379-
{anonymous: 'never', named: 'never'},
380-
],
373+
'space-before-function-paren': [WARNING, { anonymous: 'never', named: 'never' }],
381374
// incompatible with our legacy inline type annotations
382375
'space-in-parens': [OFF, 'never'],
383-
'space-infix-ops': [WARNING, {int32Hint: true}],
384-
'space-unary-ops': [WARNING, {words: true, nonwords: false}],
376+
'space-infix-ops': [WARNING, { int32Hint: true }],
377+
'space-unary-ops': [WARNING, { words: true, nonwords: false }],
385378
// TODO: Figure out a way to do this that doesn't break typechecks
386379
// or wait for https://github.com/eslint/eslint/issues/2897
387-
'spaced-comment':
388-
[OFF, 'always', {exceptions: ['jshint', 'jslint', 'eslint', 'global']}],
380+
'spaced-comment': [OFF, 'always', { exceptions: ['jshint', 'jslint', 'eslint', 'global'] }],
389381
'wrap-regex': OFF,
390382

391383
// ECMAScript 6 <http://eslint.org/docs/rules/#ecmascript-6>
392384
'arrow-body-style': OFF,
393385
// Forked to fb-www/arrow-parens to fix issues with flow and add fixer
394386
'arrow-parens': OFF,
395387
// tbgs finds *very few* places where we don't put spaces around =>
396-
'arrow-spacing': [WARNING, {before: true, after: true}],
388+
'arrow-spacing': [WARNING, { before: true, after: true }],
397389
// violation of the ES6 spec, won't transform
398390
'constructor-super': ERROR,
399391
// https://github.com/babel/babel-eslint#known-issues
@@ -416,15 +408,7 @@ function getBaseConfig() {
416408
// there are legitimate use-cases for an empty generator
417409
'require-yield': OFF,
418410

419-
// eslint-plugin-babel <https://github.com/babel/eslint-plugin-babel>
420-
'babel/generator-star-spacing': OFF,
421-
'babel/new-cap': OFF,
422-
'babel/array-bracket-spacing': OFF,
423-
'babel/object-curly-spacing': OFF,
424-
'babel/object-shorthand': OFF,
425-
'babel/arrow-parens': OFF,
426-
'babel/no-await-in-loop': OFF,
427-
'babel/flow-object-type': [WARNING, 'comma'],
411+
'no-await-in-loop': OFF,
428412

429413
// eslint-plugin-react <https://github.com/yannickcr/eslint-plugin-react>
430414
// TODO: We're being extremely conservative here as we roll out eslint on
@@ -485,12 +469,14 @@ function getBaseConfig() {
485469
// annotations.
486470
'flowtype/define-flow-type': WARNING,
487471
'flowtype/use-flow-type': WARNING,
472+
'flowtype/object-type-delimiter': [WARNING, 'comma'],
488473
},
489474

490475
// Defines a basic set of globals
491476
env: {
492477
browser: true,
493478
es6: true,
479+
node: true
494480
},
495481

496482
// The jshint code had more globals, which may have had something to do with
@@ -499,9 +485,7 @@ function getBaseConfig() {
499485
// Values of true mean the global may be modified. Values of false represent
500486
// constants.
501487
globals: {
502-
__DEV__: true,
503-
module: false,
504-
require: false
488+
__DEV__: true
505489
},
506490
};
507491
}
@@ -522,7 +506,7 @@ var extendedConfig = {
522506
},
523507
};
524508

525-
Object.keys(extendedConfig).forEach((key) => {
509+
Object.keys(extendedConfig).forEach(key => {
526510
config[key] = Object.assign(config[key], extendedConfig[key]);
527511
});
528512

.flowconfig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
[ignore]
2-
2+
**/node_modules/**
33
[include]
4-
./src/app.js
4+
55
[libs]
66

77
[options]
8+
module.name_mapper='\$utils' -> '<PROJECT_ROOT>/src/utils'
9+
module.name_mapper='\$flow-typed' -> '<PROJECT_ROOT>/flow-typed'
10+
module.name_mapper='\$components' -> '<PROJECT_ROOT>/src/components'
11+
module.name_mapper='\$styles' -> '<PROJECT_ROOT>/src/styles'
12+
module.name_mapper='\$containers' -> '<PROJECT_ROOT>/src/containers'
13+
module.name_mapper='\$reducers' -> '<PROJECT_ROOT>/src/reducers'
14+
module.name_mapper='\$layouts' -> '<PROJECT_ROOT>/src/layouts'

bin/compile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ const startCompile = () => {
1010
debug(`Start compile with env '${chalk.green(process.env.NODE_ENV)}'`);
1111
return Promise.resolve()
1212
.then(() => compiler(webpackConfig))
13-
.then((stats) => {
13+
.then(stats => {
1414
if (stats.hasWarnings() && env.isProd) {
1515
throw new Error('Production not allow warnig, exit .');
1616
}
1717
debug('Copying static assets to dist folder.');
1818
fs.copySync(paths.public(), paths.dist());
1919
return stats;
2020
})
21-
.then((stats) => {
21+
.then(stats => {
2222
debug(stats.toString(env.config.stats));
2323
debug('Success compile !!');
2424
})
25-
.catch((error) => {
25+
.catch(error => {
2626
debug('Compile with Error.', error);
2727
process.exit();
2828
});

bin/www.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1+
// @flow
12
const debug = require('debug')('app:bin:www');
23
const ip = require('internal-ip');
34
const detect = require('detect-port');
45

56
let port = process.env.PORT || 3000;
67
const host = ip.v4();
78

8-
detect(port)
9-
.then((_port) => {
10-
if (port !== _port) {
11-
debug(`Port: ${port} was occupied, try port: ${_port}`);
12-
port = _port;
13-
}
14-
debug(`Server will running at :
9+
detect(port).then(_port => {
10+
if (port !== _port) {
11+
debug(`Port: ${port} was occupied, try port: ${_port}`);
12+
port = _port;
13+
}
14+
debug(
15+
`Server will running at :
1516
=====================================
1617
Local: http://${host}:${port}.
1718
External: http://localhost:${port}.
18-
=====================================`);
19-
const server = require('../build/server');
20-
server.listen(port, (err) => {
21-
if (err) throw err;
22-
});
19+
=====================================`
20+
);
21+
const server = require('../build/server');
22+
server.listen(port, err => {
23+
if (err) {throw err;}
2324
});
25+
});

build/base-config/configs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
vendors: [
3030
'react',
3131
'react-redux',
32-
'react-router',
32+
'react-router-dom',
3333
'redux',
3434
'react-dom'
3535
],

build/base-config/environment.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ module.exports = {
88
* http://stackoverflow.com/questions/30030031
99
*/
1010
'process.env': {
11-
NODE_ENV: JSON.stringify(NODE_ENV)
11+
NODE_ENV: JSON.stringify(NODE_ENV),
1212
},
1313
env: NODE_ENV,
1414
__DEV__: NODE_ENV === 'development',
1515
__PRO__: NODE_ENV === 'production',
16-
__TEST__: NODE_ENV === 'test',
17-
config: Object.assign(envConfigs.defaults, envConfigs[NODE_ENV] || {})
16+
config: Object.assign(envConfigs.defaults, envConfigs[NODE_ENV] || {}),
1817
};

build/base-config/path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ module.exports = {
1212
src: base.bind(null, 'src'),
1313
dist: base.bind(null, 'dist'),
1414
server: base.bind(null, 'server'),
15-
public: base.bind(null, 'src', 'static')
15+
public: base.bind(null, 'src', 'static'),
1616
};

build/webpack-config/alias.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ module.exports = paths => ({
88
'$containers': paths.src('containers'),
99
'$styles': paths.src('styles'),
1010
'$reducers': paths.src('reducers'),
11-
'$layouts': paths.src('layouts')
11+
'$layouts': paths.src('layouts'),
12+
'$flow-typed': paths.root('flow-typed'),
1213
});

build/webpack-config/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const envConfig = env.config;
77
const pkg = require('../../package.json');
88

99
module.exports = paths => {
10-
const App = [paths.src('app.js')];
10+
const App = [paths.src('main.js')];
1111
const Vendors = envConfig.vendors.filter(dep => {
1212
if (pkg.dependencies[dep]) {
1313
return true;
@@ -27,7 +27,7 @@ module.exports = paths => {
2727
app: App,
2828
vendors: Vendors,
2929
},
30-
devtool: isDev ? 'eval' : false,
30+
devtool: isDev ? 'source-map' : false,
3131
output: {
3232
filename: '[name].[hash:8].js',
3333
path: paths.dist(),

0 commit comments

Comments
 (0)