Skip to content

Commit

Permalink
chore(lint): fix all lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Nov 8, 2017
1 parent 5285144 commit 5d9d823
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 76 deletions.
34 changes: 18 additions & 16 deletions packages/flow-execa/src/index.js
Expand Up @@ -2,30 +2,21 @@
import path from 'path'
import execa from 'execa'

export type FlowVersionInfo = {
semver: string,
binary: string,
build_id: string,
}
type TypeInfo = ?{ type: string }

const noop = () => null

export function getFlowBin(cwd: string) {
const bin = process.platform === 'win32' ? 'flow.exe' : 'flow'
const flowBinPath = path.join('node_modules', '.bin', bin)

return path.resolve(cwd, flowBinPath)
}
// eslint-disable-next-line flowtype/no-weak-types
type JsonType = Object

async function execFlow(
cwd: string,
params: $ReadOnlyArray<string>
): Promise<Object> {
): Promise<JsonType> {
const output = await execa.stdout(getFlowBin(cwd), params).catch(noop)
return JSON.parse(output)
}

function execFlowSync(cwd: string, params: $ReadOnlyArray<string>): Object {
function execFlowSync(cwd: string, params: $ReadOnlyArray<string>): JsonType {
try {
const output = execa.sync(getFlowBin(cwd), params).stdout
return JSON.parse(output)
Expand All @@ -34,13 +25,24 @@ function execFlowSync(cwd: string, params: $ReadOnlyArray<string>): Object {
}
}

export function getFlowBin(cwd: string) {
const bin = process.platform === 'win32' ? 'flow.exe' : 'flow'
const flowBinPath = path.join('node_modules', '.bin', bin)

return path.resolve(cwd, flowBinPath)
}

export type FlowVersionInfo = {
semver: string,
binary: string,
build_id: string,
}

export async function versionInfo(cwd: string): Promise<?FlowVersionInfo> {
const json = await execFlow(cwd, ['version', '--json']).catch(noop)
return json
}

type TypeInfo = ?{ type: string }

export async function typeAtPos(
cwd: string,
filePath: string,
Expand Down
112 changes: 56 additions & 56 deletions packages/flow-faker/src/index.js
Expand Up @@ -10,24 +10,6 @@ type Opts = {
cwd?: string,
}

export default flowFaker

async function flowFaker(
filePath: string,
{ row, column, cwd = process.cwd() }: Opts
) {
const ast = await getTypeFromFile(cwd, filePath, row, column)
return _flowFaker(ast)
}

export function flowFakerSync(
filePath: string,
{ row, column, cwd = process.cwd() }: Opts
) {
const ast = getTypeFromFileSync(cwd, filePath, row, column)
return _flowFaker(ast)
}

function _flowFaker(ast) {
if (!ast) {
return {}
Expand All @@ -51,44 +33,6 @@ function typeToValue(typeInfo: string | null) {
}
}

export function createInitialStateFromTypeInfo(
info: Object | $ReadOnlyArray<*> | string | null
) {
if (!info || typeof info === 'string') {
return typeToValue(info)
}

if (Array.isArray(info)) {
return []
}

return Object.keys(info).reduce((acc, key) => {
// $FlowFixMe
return { ...acc, [key]: createInitialStateFromTypeInfo(info[key]) }
}, {})
}

export function getTypeAst(input: string) {
const typeString = `type X = ${input}`

const ast = parse(typeString, {
plugins: ['flow'],
sourceType: 'module',
})

let typeAST = {}

traverse(ast, {
TypeAlias(nodePath) {
// if (nodePath.get('id').isIdentifier({ name: 'X' })) { }
// nodeのidは`X`が必ず保証されてる
typeAST = nodePath.get('right')
},
})

return typeAST
}

function getType(node) {
const nodeType = node.type

Expand Down Expand Up @@ -144,10 +88,66 @@ function isPathLike(obj) {
return isNodeLike(obj) && {}.hasOwnProperty.call(obj, 'node')
}

// eslint-disable-next-line import/exports-last
export function astToObj(input: *) {
if (isPathLike(input)) {
input = input.node
}

return getType(input)
}

// eslint-disable-next-line flowtype/no-weak-types
type Info = Object | $ReadOnlyArray<*> | string | null

export function createInitialStateFromTypeInfo(info: Info) {
if (!info || typeof info === 'string') {
return typeToValue(info)
}

if (Array.isArray(info)) {
return []
}

return Object.keys(info).reduce((acc, key) => {
// $FlowFixMe
return { ...acc, [key]: createInitialStateFromTypeInfo(info[key]) }
}, {})
}

export function getTypeAst(input: string) {
const typeString = `type X = ${input}`

const ast = parse(typeString, {
plugins: ['flow'],
sourceType: 'module',
})

let typeAST = {}

traverse(ast, {
TypeAlias(nodePath) {
// if (nodePath.get('id').isIdentifier({ name: 'X' })) { }
// nodeのidは`X`が必ず保証されてる
typeAST = nodePath.get('right')
},
})

return typeAST
}

export default async function flowFaker(
filePath: string,
{ row, column, cwd = process.cwd() }: Opts
) {
const ast = await getTypeFromFile(cwd, filePath, row, column)
return _flowFaker(ast)
}

export function flowFakerSync(
filePath: string,
{ row, column, cwd = process.cwd() }: Opts
) {
const ast = getTypeFromFileSync(cwd, filePath, row, column)
return _flowFaker(ast)
}
4 changes: 2 additions & 2 deletions packages/s2s-cli/src/handlers/plugins.js
Expand Up @@ -14,6 +14,8 @@ import {
import runHooks from '../hooks'
import { formatText } from '../reporters/'

const lock = new KeyLocker()

type Opts = {
eventPath: Path,
plugin: Plugin,
Expand Down Expand Up @@ -46,8 +48,6 @@ export function handlePlugin(
console.log(formatText('S2S', relativeFromCwd(eventPath), outputPath))
}

const lock = new KeyLocker()

export default function handlePlugins(
eventPath: Path,
eventType: EventType,
Expand Down
2 changes: 0 additions & 2 deletions packages/s2s-helper-get-reducer-case/src/index.js
Expand Up @@ -21,8 +21,6 @@ export default function getReducerCase(code /* : Code */) {
return
}

// TODO 他ファイルのアクションも受け入れる
// が、とりあえずs2s stackのみの動作を目指す
if (testPath.get('object').node.name !== 'Actions') {
return
}
Expand Down

0 comments on commit 5d9d823

Please sign in to comment.