Commit d8809093 authored by wincent's avatar wincent

Tighten up Flow annotations in a bunch of places

Includes a bug fix discovered while doing the pass (misuse of
`makeNotFound` helper), and inserting `noflow` annotations in the files
I don't want to deal with yet, so I have an easy-to-grep-for marker that
I can find again later.
parent 92c7548e
/**
* @flow
* @flow strict
*/
opaque type Token = number;
......@@ -13,7 +13,7 @@ let pendingClaim: ?Token = null;
* listener to be notified.
*/
export function getRefetchToken(): Token {
if (pendingClaim) {
if (pendingClaim != null) {
throw new Error('Only one refetch token may be outstanding at any time');
}
pendingClaim = tokenCounter++;
......
......@@ -13,7 +13,7 @@ const StatusCodesToMessages = {
};
type Props = {
children: $ReadOnlyArray<ChildrenArray<ReactNode>>,
children?: $ReadOnlyArray<ChildrenArray<ReactNode>>,
code: 404 | 500,
};
......
/**
* @flow
* @flow strict
*/
import React from 'react';
......
/**
* @flow
* @flow strict
*/
import React from 'react';
......
/**
* @flow
* @flow strict
*/
import React from 'react';
......
/**
* @flow
* @flow strict
*/
export type TimeInfo = {
......
/**
* @flow strict-local
* @flow strict
*/
import * as React from 'react';
......
/**
* @flow
* @flow strict
*/
export default function extractTypeAndId(typeAndId: string): [string, string] {
......
/**
* @flow
* @flow strict
*/
export default function formatTitle(title: ?string): string {
// flowlint-next-line sketchy-null:off
return [...(title ? [title] : []), 'wincent.com'].join(' · ');
}
/**
* @flow
* @flow strict
*/
import stableStringify from './stableStringify';
......
/**
* @flow strict-local
*/
import Router from 'universal-router';
import routeConfig from './routeConfig';
......@@ -25,7 +29,7 @@ function getRouteMap() {
/**
* Matches paths only.
*/
export default function matchRoute(path) {
export default function matchRoute(path: string) {
for (let [regexp, route] of getRouteMap()) {
if (regexp.test(path)) {
return route;
......
/**
* @flow
*/
import React from 'react';
import HTTPError from '../client/components/HTTPError';
......
/**
* @noflow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @noflow
*/
import React from 'react';
import {graphql} from 'react-relay';
......@@ -27,7 +31,7 @@ export default buildRoute(
if (node) {
return <Page data={node} />;
} else {
throw makeNotFoundError(
throw makeNotFound(
`No page found with id: ${id}`,
<p>
Try inspecting <Link to="/tags/pages">the pages index</Link> and{' '}
......
/**
* @noflow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @noflow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @noflow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @noflow
*/
import React from 'react';
import {graphql} from 'react-relay';
import Link from '../../client/components/Link';
import Snippet from '../../client/components/Snippet';
import makeNotFound from '../NotFoundError';
import {makeNotFound} from '../NotFoundError';
import buildRoute from '../buildRoute';
export default buildRoute(
......
/**
* @flow
*/
import React from 'react';
import {graphql} from 'react-relay';
......@@ -34,15 +38,11 @@ export default buildRoute(
`,
{
variables: ({format, id}) => {
format = FORMAT_TO_MARKUP_TYPE.get(format.toLowerCase());
if (format !== 'TXT') {
return {format, id};
} else {
return {
format: null,
id,
};
}
const markupType = FORMAT_TO_MARKUP_TYPE.get(format.toLowerCase());
return {
format: markupType !== 'TXT' ? markupType : null,
id,
};
},
render: ({node}, {format, id}) => {
if (node && node.source !== null) {
......
/**
* @flow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @flow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @flow
*/
import React from 'react';
import {graphql} from 'react-relay';
......
/**
* @flow
* @flow strict
*/
export default function stripTrailingSlash(path: string): string {
......
/**
* @flow
* @flow strict
*/
import inBrowser from './inBrowser';
......
/**
* @flow
*/
import inBrowser from './inBrowser';
if (!inBrowser) {
......
/**
* @noflow
*/
import PropTypes from 'prop-types';
import React from 'react';
......
/**
* @flow
* @flow strict
*/
import Memcached from 'memcached';
......@@ -30,8 +30,8 @@ function getCacheBreaker(): string {
// TODO: degrade more gracefully if memcached goes down (currently we just wait
// forever(?))
const Cache = {
set(key: string, value: mixed): Promise<mixed> {
key = key + getCacheBreaker();
set(inKey: string, value: mixed): Promise<mixed> {
const key = inKey + getCacheBreaker();
return new Promise((resolve, reject) => {
memcached.set(key, value, 0, error => {
......@@ -44,8 +44,8 @@ const Cache = {
});
},
get(key: string, missCallback: () => Promise<mixed>): Promise<mixed> {
key = key + getCacheBreaker();
get(inKey: string, missCallback: () => Promise<mixed>): Promise<mixed> {
const key = inKey + getCacheBreaker();
return new Promise((resolve, reject) => {
memcached.get(key, (error, data) => {
......
/**
* @flow
* @flow strict
*/
export const Extensions = {
......
/**
* @flow
* @flow strict
*/
import getIndexNameForContentType from './getIndexNameForContentType';
......
/**
* @flow
* @flow strict
*/
export default function delay(ms: number): Promise<void> {
......
/**
* @flow
* @flow strict
*/
// Prepared regular expressions to eek out a couple % more perf; see:
......
/**
* @flow
* @flow strict
*/
type RouteConfig = Array<{
type RouteConfig = $ReadOnlyArray<{
path: string,
}>;
......@@ -10,7 +10,7 @@ type RouteConfig = Array<{
* Parses a RouteConfig object and returns a list of Express-style path
* patterns ("/", "/blog", "/blog/*" etc).
*/
export default function gatherPaths(config: RouteConfig): Array<string> {
export default function gatherPaths(config: RouteConfig): $ReadOnlyArray<string> {
const paths = [];
config.forEach(route => {
if (route.path === '*') {
......
/**
* @flow
* @flow strict
*/
import hashString from './hashString';
......
/**
* @flow
* @flow strict
*/
import getURLForContentPath from './getURLForContentPath';
......
/**
* @flow
* @flow strict
*/
import getURLForContentPath from './getURLForContentPath';
......
/**
* @flow
* @flow strict
*/
export default function getURLForContentPath(
......
/**
* @flow
* @flow strict-local
*/
import path from 'path';
......
/**
* @flow
* @flow strict
*/
/**
......
'use strict'; // eslint-disable-line
/**
* @noflow
*/
import '../common/unhandledRejection';
import '../server/configureNpm';
......
/**
* @flow
* @flow strict
*/
import {spawn} from 'child_process';
......
/**
* @flow
* @flow strict
*/
export default function raw(string: string): {|__safe: string|} {
......
/**
* @flow
* @flow strict
*/
import pipe from './pipe';
......
/**
* @noflow
*/
import {
GraphQLNonNull,
GraphQLObjectType,
......
/**
* @flow
* @flow strict
*/
/**
......
......@@ -101,7 +101,7 @@ export default function template(
} else {
// User passed 0, false, NaN, or something truthy
// that didn't get caught by duck-typing checks; coerce to string.
const string = '' + (item: any);
const string = String('');
if (!this.push(string)) {
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment