Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flowtype (WIP) #530

Merged
merged 4 commits into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion node_package/.babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"presets": ["es2015", "stage-0", "react"],
"plugins": ["transform-runtime"]
"plugins": [
"transform-flow-strip-types",
"transform-runtime"
]
}
3 changes: 3 additions & 0 deletions node_package/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ignore]
.*/lib/.*
.*/node_modules/.*
6 changes: 4 additions & 2 deletions node_package/src/Authenticity.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// @flow

export default {

authenticityToken() {
const token = document.querySelector('meta[name="csrf-token"]');
const token: {content?: string} = document.querySelector('meta[name="csrf-token"]');
return token ? token.content : null;
},

authenticityHeaders(otherHeaders = {}) {
authenticityHeaders(otherHeaders: {[id:string]: string} = {}) {
return Object.assign(otherHeaders, {
'X-CSRF-Token': this.authenticityToken(),
'X-Requested-With': 'XMLHttpRequest',
Expand Down
7 changes: 4 additions & 3 deletions node_package/src/buildConsoleReplay.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// @flow

import RenderUtils from './RenderUtils';
import scriptSanitizedVal from './scriptSanitizedVal';

export function consoleReplay() {
// console.history is a global polyfill used in server rendering.
const history = console.history;
if (!history || history.length === 0) {
if (!(console.history instanceof Array)) {
return '';
}

const lines = history.map(msg => {
const lines = console.history.map(msg => {
const stringifiedList = msg.arguments.map(arg => {
let val;
try {
Expand Down
2 changes: 2 additions & 0 deletions node_package/src/context.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @flow

/**
* Get the context, be it window or global
* @returns {boolean|Window|*|context}
Expand Down
7 changes: 4 additions & 3 deletions node_package/src/generatorFunction.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @flow

// See discussion:
// https://discuss.reactjs.org/t/how-to-determine-if-js-object-is-react-component/2825/2

Expand All @@ -7,12 +9,11 @@
* @param component
* @returns {boolean}
*/
export default function generatorFunction(component) {
export default function generatorFunction(component: any) {
if (!component.prototype) {
return false;
}

// es5 or es6 React Component
const es5OrEs6ReactComponent = component.prototype.isReactComponent;
return !es5OrEs6ReactComponent;
return !component.prototype.isReactComponent;
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-flow-strip-types": "^6.8.0",
"babel-plugin-transform-runtime": "^6.6.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
Expand All @@ -25,6 +26,7 @@
"eslint-plugin-import": "^1.13.0",
"eslint-plugin-jsx-a11y": "^2.1.0",
"eslint-plugin-react": "^6.1.2",
"flow-bin": "^0.30.0",
"jscs": "^2.11.0",
"jsdom": "^8.2.0",
"react": "^15.0.0",
Expand Down Expand Up @@ -52,7 +54,8 @@
"build-watch": "babel --watch --out-dir node_package/lib node_package/src",
"eslint": "eslint .",
"jscs": "jscs -e -v .",
"lint": "npm run eslint && npm run jscs",
"flow": "flow check node_package",
"lint": "npm run eslint && npm run jscs && npm run flow",
"lint:fix": "node_package/scripts/lint-fix",
"check": "npm run lint && npm run test",
"prerelease": "npm run check && npm run clean && npm run build",
Expand Down
9 changes: 7 additions & 2 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ namespace :lint do
sh_in_dir(gem_root, "npm run jscs")
end

desc "Run all eslint, jscs, rubocop linters. Skip ruby-lint and scss"
task lint: [:eslint, :jscs, :rubocop] do
desc "Run flow from shell"
task :flow do
sh_in_dir(gem_root, "npm run flow")
end

desc "Run all eslint, jscs, flow, rubocop linters. Skip ruby-lint and scss"
task lint: [:eslint, :jscs, :flow, :rubocop] do
puts "Completed all linting"
end
end
Expand Down