fix: re-enable flow type checking for the project (#1197)

Flow wasn't working anymore. This fixes flow type checking and it to the git precommit hook.
This commit is contained in:
Igor Gassmann 2018-04-25 17:20:59 -04:00 committed by GitHub
parent eb06c9261d
commit 232c1d8109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 168 deletions

1
.gitignore vendored
View file

@ -3,4 +3,3 @@
/static/daemon/lbrynet*
/static/locales
yarn-error.log
/build/daemon*

View file

@ -6,6 +6,7 @@
],
"src/**/*.{js,jsx}": [
"eslint --fix",
"flow focus-check --color always",
"git add"
]
}

View file

@ -15,13 +15,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
* Add Danger JS to automate code reviews ([#1289](https://github.com/lbryio/lbry-app/pull/1289))
### Changed
* Add flair to snackbar ([#1313](https://github.com/lbryio/lbry-app/pull/1313))
* Add flair to snackbar ([#1313](https://github.com/lbryio/lbry-app/pull/1313))
### Fixed
* Black screen on macOS after maximizing LBRY and then closing ([#1235](https://github.com/lbryio/lbry-app/pull/1235))
* Fix content-type not shown correctly in file description ([#863](https://github.com/lbryio/lbry-app/pull/863))
### Fixed
* Fix [Flow](https://flow.org/) ([#1197](https://github.com/lbryio/lbry-app/pull/1197))
* Black screen on macOS after maximizing LBRY and then closing ([#1235](https://github.com/lbryio/lbry-app/pull/1235))
* Fix dark theme ([#1034](https://github.com/lbryio/lbry-app/issues/1034))
* Fix download percentage indicator overlay ([#1271](https://github.com/lbryio/lbry-app/issues/1271))

View file

@ -36,8 +36,8 @@ To make contributing as easy and rewarding of possible, we have instituted the f
[Help Wanted](https://github.com/lbryio/lbry-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+no%3Aassignee)
issue is ranked on a scale from zero to four.
| Level | Description |
| --------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| Level | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- |
| [**level 0**](https://github.com/lbryio/lbry-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3A%22level%3A+0%22+no%3Aassignee) | Typos and text edits -- a tech-savvy non-programmer can fix these |
| [**level 1**](https://github.com/lbryio/lbry-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3A%22level%3A+1%22+no%3Aassignee) | Programming issues that require little knowledge of how the LBRY app works |
| [**level 2**](https://github.com/lbryio/lbry-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3A%22level%3A+2%22+no%3Aassignee) | Issues of average difficulty that require the developer to dig into how the app works a little bit |
@ -60,24 +60,45 @@ better code quality. It's recommended to make use of them thoroughly during ongo
We follow the well-known [Airbnb JavaScript Style Guide](http://airbnb.io/javascript/) for defining
our styling rules and code best practices.
### Flow
[Flow](https://flow.org/) is a static type checker for JavaScript. Flow checks your code for
errors through static type annotations. For using Flow, you need to add the following
annotation to the beginning of the file you're editing:
`// @flow`
After adding this, you can start adding [type annotations](https://flow.org/en/docs/types/) to
the code.
If you add a project dependency and you want to use it with Flow, you need to import its type
definitions in the project by running:
`$ yarn flow-defs`
### Run
LBRY app can be run for development by using the command:
`yarn dev`
`$ yarn dev`
This will launch the app and provide HMR (Hot Module Replacement). Any change made to the sources
will automatically reload the app without losing its state.
### Lint
Code linting is ensured by [ESLint](https://eslint.org/).
Code linting is ensured by [ESLint](https://eslint.org/) and [Flow CLI](https://flow.org/en/docs/cli/).
You can lint all the project's sources at any time by running:
`yarn lint`
`$ yarn lint`
If you desire to lint a specific file or directory you can use `yarn eslint 'glob/pattern'`.
If you desire to lint a specific file or directory you can use:
```
$ yarn eslint 'glob/pattern'
$ yarn flow focus-check 'glob/pattern'
```
In addition to those commands, staged files are automatically linted before commit. Please take the
time to fix all staged files' linting problems before committing or suppress them if necessary.
@ -93,10 +114,12 @@ Staged files are automatically formatted before commit.
You can also use the following command:
`yarn format`
`$ yarn format`
for applying formatting rules to all project's code sources. For formatting a specific file or
directory use `yarn prettier 'glob/pattern'`.
directory use:
`$ yarn prettier 'glob/pattern'`
Editor integrations are available [here](https://prettier.io/docs/en/editors.html).

View file

@ -38,12 +38,12 @@ development and testing purposes.
* [Yarn](https://yarnpkg.com/en/docs/install)
* [C++ Build Tools](https://github.com/felixrieseberg/windows-build-tools) (Only needed on Windows)
### One-time Setup
### Setup
1. Clone this repository
2. Run `$ yarn`
### Running
### Run
The app can be run from the sources using the following command:
@ -51,7 +51,7 @@ The app can be run from the sources using the following command:
### Build
Run `$ yarn build`.
Run `$ yarn build`
We use [electron-builder](https://github.com/electron-userland/electron-builder) to create
distributable packages.

View file

@ -1,116 +0,0 @@
var spawnSync = require('child_process').spawnSync;
var flow = require('flow-bin');
var merge = require('lodash.merge');
var store = {
error: null,
flowOptions: [
'check',
'--color=always',
],
options: {
warn: false,
formatter: function (errorCode, errorDetails) {
return 'Flow: ' + errorCode + '\n\n' + errorDetails;
},
},
};
function flowErrorCode(status) {
var error;
switch (status) {
/*
case 0:
error = null;
break;
*/
case 1:
error = 'Server Initializing';
break;
case 2:
error = 'Type Error';
break;
case 3:
error = 'Out of Time';
break;
case 4:
error = 'Kill Error';
break;
case 6:
error = 'No Server Running';
break;
case 7:
error = 'Out of Retries';
break;
case 8:
error = 'Invalid Flowconfig';
break;
case 9:
error = 'Build Id Mismatch';
break;
case 10:
error = 'Input Error';
break;
case 11:
error = 'Lock Stolen';
break;
case 12:
error = 'Could Not Find Flowconfig';
break;
case 13:
error = 'Server Out of Date';
break;
case 14:
error = 'Server Client Directory Mismatch';
break;
case 15:
error = 'Out of Shared Memory';
break;
}
return error;
}
function checkFlowStatus(compiler, next) {
var res = spawnSync(flow, store.flowOptions);
var status = res.status;
if (status !== 0) {
var errorCode = flowErrorCode(status);
var errorDetails = res.stdout.toString() + res.stderr.toString();
store.error = new Error(store.options.formatter(errorCode, errorDetails));
}
next();
}
function pushError(compilation) {
if (store.error) {
if (store.options.warn) {
compilation.warnings.push(store.error);
} else {
compilation.errors.push(store.error);
}
store.error = null;
}
}
function FlowFlowPlugin(options) {
store.options = merge(store.options, options);
}
FlowFlowPlugin.prototype.apply = function(compiler) {
compiler.plugin('run', checkFlowStatus);
compiler.plugin('watch-run', checkFlowStatus);
compiler.plugin('compilation', pushError);
};
module.exports = FlowFlowPlugin;

View file

@ -21,18 +21,19 @@
"main": "src/main/index.js",
"scripts": {
"extract-langs": "node build/extractLocals.js",
"dev": "electron-webpack dev",
"compile": "electron-webpack && yarn extract-langs",
"compile": "electron-webpack & yarn extract-langs",
"build": "yarn compile && electron-builder build",
"build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null",
"dev": "electron-webpack dev",
"lint": "eslint 'src/**/*.{js,jsx}' --fix && flow",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write",
"flow-defs": "flow-typed install",
"release": "yarn compile && electron-builder build",
"precommit": "lint-staged",
"postmerge": "yarnhook",
"postcheckout": "yarnhook",
"postrewrite": "yarnhook",
"postinstall": "electron-builder install-app-deps && node build/downloadDaemon.js",
"lint": "eslint 'src/**/*.{js,jsx}' --fix",
"format": "prettier 'src/**/*.{js,jsx,scss,json}' --write",
"postinstall": "electron-builder install-app-deps & node build/downloadDaemon.js",
"clean": "rm -r node_modules && yarn cache clean lbry-redux && yarn"
},
"dependencies": {
@ -105,7 +106,6 @@
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"flow-babel-webpack-plugin": "^1.1.1",
"flow-bin": "^0.69.0",
"flow-typed": "^2.3.0",
"fs-path": "^0.0.24",

View file

@ -1,6 +1,4 @@
const path = require('path');
const FlowFlowPlugin = require('./flowtype-plugin');
const isDev = require('electron-is-dev');
const ELECTRON_RENDERER_PROCESS_ROOT = path.resolve(__dirname, 'src/renderer/');
@ -23,11 +21,3 @@ module.exports = {
extensions: ['.js', '.jsx', '.scss'],
},
};
if (isDev) {
module.exports.plugins = [
new FlowFlowPlugin({
warn: true,
}),
];
}

View file

@ -805,7 +805,7 @@ babel-plugin-syntax-exponentiation-operator@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de"
babel-plugin-syntax-flow@^6.18.0, babel-plugin-syntax-flow@^6.8.0:
babel-plugin-syntax-flow@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d"
@ -1032,13 +1032,6 @@ babel-plugin-transform-exponentiation-operator@^6.22.0, babel-plugin-transform-e
babel-plugin-syntax-exponentiation-operator "^6.8.0"
babel-runtime "^6.22.0"
babel-plugin-transform-flow-comments@^6.17.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-comments/-/babel-plugin-transform-flow-comments-6.22.0.tgz#8d9491132f2b48abd0656f96c20f3bbd6fc17529"
dependencies:
babel-plugin-syntax-flow "^6.8.0"
babel-runtime "^6.22.0"
babel-plugin-transform-flow-strip-types@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf"
@ -4024,18 +4017,6 @@ flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
flow-babel-webpack-plugin@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/flow-babel-webpack-plugin/-/flow-babel-webpack-plugin-1.1.1.tgz#7dd41110b96045eab8d8af6df48883310de54e91"
dependencies:
babel-plugin-transform-flow-comments "^6.17.0"
flow-bin ">=0.44.2 <1"
lodash.merge "^4.6.0"
"flow-bin@>=0.44.2 <1":
version "0.70.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.70.0.tgz#080ae83a997f2b4ddb3dc2649bf13336825292b5"
flow-bin@^0.69.0:
version "0.69.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.69.0.tgz#053159a684a6051fcbf0b71a2eb19a9679082da6"
@ -6000,7 +5981,7 @@ lodash.memoize@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
lodash.merge@^4.4.0, lodash.merge@^4.6.0:
lodash.merge@^4.4.0:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"