Skip to content

Commit

Permalink
test(lint): fix mastarm lint and resulting linting errors
Browse files Browse the repository at this point in the history
Fixes #424
  • Loading branch information
evansiroky committed Feb 19, 2019
1 parent 5c08d81 commit e3da05e
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 58 deletions.
1 change: 0 additions & 1 deletion __tests__/end-to-end.js
Expand Up @@ -587,7 +587,6 @@ describe('end-to-end', () => {
await wait(2000, 'for projects to load')
}, defaultTestTimeout, 'should load the page')


// ---------------------------------------------------------------------------
// Project tests
// ---------------------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions lib/gtfs/components/GtfsMap.js
Expand Up @@ -12,13 +12,7 @@ import PatternGeoJson from './PatternGeoJson'
import StopMarker from './StopMarker'

import type {Props as ContainerProps} from '../containers/ActiveGtfsMap'
import type {
Bounds,
Feed,
FeedVersion,
LatLng,
StopWithFeed
} from '../../types'
import type {Bounds, Feed, LatLng, StopWithFeed} from '../../types'
import type {DateTimeFilter, MapFilter} from '../../types/reducers'

type Props = ContainerProps & {
Expand Down
2 changes: 1 addition & 1 deletion lib/gtfs/util/index.js
Expand Up @@ -7,7 +7,7 @@ import {getGtfsSpec} from '../../common/util/config'
import {routeSearch, stopSearch} from '../util/graphql'
import {getHeaders} from '../../common/util/util'

import type {Feed, GtfsRoute, GtfsStop, User} from '../../types'
import type {GtfsRoute, GtfsStop, User} from '../../types'

export function getEntityIdField (type: string): string {
if (!type) return ''
Expand Down
34 changes: 16 additions & 18 deletions lib/gtfsplus/actions/gtfsplus.js
Expand Up @@ -5,22 +5,20 @@ import fetch from 'isomorphic-fetch'
import {createAction, type ActionType} from 'redux-actions'

import {createVoidPayloadAction, fetchGraphQL, secureFetch} from '../../common/actions'
import {getGtfsPlusSpec} from '../../common/util/config'
import {uploadFile} from '../../common/util/upload-file'
import {stopsAndRoutes, compose} from '../../gtfs/util/graphql'
import {stopsAndRoutes} from '../../gtfs/util/graphql'
import {getHeaders} from '../../common/util/util'
import {VISIBILITY} from '../components/GtfsPlusTable'
import {startJobMonitor} from '../../manager/actions/status'
import {fetchFeedVersions} from '../../manager/actions/versions'

import type {Feed, FeedVersion, GtfsRoute, GtfsStop} from '../../types'
import type {FeedVersion, GtfsRoute, GtfsStop} from '../../types'
import type {dispatchFn, getStateFn, GtfsPlusValidation, ValidationIssue} from '../../types/reducers'

type GTFSPlusEntity = {
rowIndex: number,
origRowIndex: number,
stop_id?: string,
route_id?: string,
rowIndex: number,
stop_id?: string,
[string]: ?(number | string)
}

Expand Down Expand Up @@ -199,18 +197,18 @@ export function loadGtfsEntities (
// these in the subsequent GraphQL query.
const filteredRows = tableIssues
? rows.filter(row => {
if (row.stop_id) {
const missingIdIssue = tableIssues.find(issue =>
issue.fieldName === 'stop_id' && issue.rowIndex === row.origRowIndex)
if (missingIdIssue) return null
}
if (row.route_id) {
const missingIdIssue = tableIssues.find(issue =>
issue.fieldName === 'route_id' && issue.rowIndex === row.origRowIndex)
if (missingIdIssue) return null
}
return row
})
if (row.stop_id) {
const missingIdIssue = tableIssues.find(issue =>
issue.fieldName === 'stop_id' && issue.rowIndex === row.origRowIndex)
if (missingIdIssue) return null
}
if (row.route_id) {
const missingIdIssue = tableIssues.find(issue =>
issue.fieldName === 'route_id' && issue.rowIndex === row.origRowIndex)
if (missingIdIssue) return null
}
return row
})
: rows
const {namespace} = feedVersion
const {routesToLoad, stopsToLoad} = lookupMissingEntities(filteredRows, getState().gtfsplus.gtfsEntityLookup)
Expand Down
2 changes: 1 addition & 1 deletion lib/gtfsplus/components/GtfsPlusEditor.js
Expand Up @@ -13,7 +13,7 @@ import {getGtfsPlusSpec} from '../../common/util/config'
import * as feedsActions from '../../manager/actions/feeds'

import type {Props as ContainerProps} from '../containers/ActiveGtfsPlusEditor'
import type {Feed, FeedVersion, Project, Entity} from '../../types'
import type {Feed, FeedVersion, Project} from '../../types'
import type {GtfsPlusValidation, ManagerUserState} from '../../types/reducers'

export type Props = ContainerProps & {
Expand Down
4 changes: 2 additions & 2 deletions lib/gtfsplus/components/GtfsPlusTable.js
Expand Up @@ -19,8 +19,8 @@ export type Props = GtfsPlusEditorProps & {
tableValidation: Array<any>
}

// The values here are used to filter the visibility of
// table rows to either all rows or just those with
// The values here are used to filter the visibility of
// table rows to either all rows or just those with
// validation issues.
export const VISIBILITY = Object.freeze({
ALL: 'all',
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/components/CreateFeedSource.js
Expand Up @@ -53,7 +53,7 @@ export default class CreateFeedSource extends Component<Props, State> {
}

_handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
switch( e.keyCode ) {
switch (e.keyCode) {
case 13: // ENTER
this._onSave()
break
Expand Down
1 change: 0 additions & 1 deletion lib/manager/components/UserHomePage.js
Expand Up @@ -3,7 +3,6 @@
import Icon from '@conveyal/woonerf/components/icon'
import React, {Component} from 'react'
import {Grid, Row, Col, Button, ButtonToolbar, Jumbotron} from 'react-bootstrap'
import {LinkContainer} from 'react-router-bootstrap'
import objectPath from 'object-path'

import * as feedsActions from '../actions/feeds'
Expand Down
1 change: 0 additions & 1 deletion lib/public/components/PublicHeader.js
Expand Up @@ -5,7 +5,6 @@ import React, {Component} from 'react'
import {Grid, Row, Col, Button, Glyphicon, ButtonToolbar} from 'react-bootstrap'
import {LinkContainer} from 'react-router-bootstrap'

import {isModuleEnabled} from '../../common/util/config'
import * as userActions from '../../manager/actions/user'

import type {Props as ContainerProps} from '../containers/ActivePublicHeader'
Expand Down
5 changes: 1 addition & 4 deletions lib/public/components/PublicLandingPage.js
Expand Up @@ -7,12 +7,9 @@ import {LinkContainer} from 'react-router-bootstrap'

import { DEFAULT_DESCRIPTION, DEFAULT_LOGO, DEFAULT_TITLE } from '../../common/constants'
import { getConfigProperty, isModuleEnabled } from '../../common/util/config'
import * as projectsActions from '../../manager/actions/projects'
import * as visibilityFilterActions from '../../manager/actions/visibilityFilter'
import PublicPage from './PublicPage'

import type {Props as ContainerProps} from '../containers/ActivePublicLandingPage'
import type {Coordinate, Feed, Project} from '../../types'
import type {ManagerUserState} from '../../types/reducers'

type Props = ContainerProps & {
Expand Down Expand Up @@ -50,7 +47,7 @@ export default class PublicLandingPage extends Component<Props> {
</p>
{!isModuleEnabled('enterprise') && <p>
Learn more about Conveyal Data Tools{' '}
<a href="https://conveyal.com/transit-data-tools">here</a>.
<a href='https://conveyal.com/transit-data-tools'>here</a>.
</p>}
<p>
{!this.props.user.profile
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -17,7 +17,7 @@
"cover-flow": "flow-coverage-report -t html -t text -i 'lib/**/*.js' -o coverage-flow",
"deploy": "mastarm deploy --minify --env production",
"flow": "mastarm flow",
"lint": "mastarm lint \"lib/**/*.js\"",
"lint": "mastarm lint __mocks__ __tests__ lib scripts --quiet",
"lint-messages": "node scripts/lint-messages.js",
"predeploy": "yarn",
"prestart": "yarn",
Expand Down
12 changes: 8 additions & 4 deletions scripts/lint-messages.js
Expand Up @@ -15,7 +15,7 @@ const issueTypes = {
undefinedComponentMessages: 'error',
undefinedMessage: 'error',
unneccessaryComponentMessageDefinition: 'error',
unusedMessageDefinition: 'warning',
unusedMessageDefinition: 'warning'
}
const error = []
const jsMessageCounts = {}
Expand All @@ -24,8 +24,11 @@ const warning = []

function addIssue (type, issue) {
const issueErrorLevel = issueTypes[type]
if (issueErrorLevel === 'error' || process.argv.indexOf('--no-warn') == -1)
console[issueErrorLevel === 'warning' ? 'warn' : 'error'](`${issueErrorLevel.toUpperCase()}: ${issue}`)
if (issueErrorLevel === 'error' || process.argv.indexOf('--no-warn') === -1) {
console[issueErrorLevel === 'warning' ? 'warn' : 'error'](
`${issueErrorLevel.toUpperCase()}: ${issue}`
)
}
if (issueErrorLevel === 'error') {
error.push({ issue, type })
} else {
Expand Down Expand Up @@ -70,11 +73,12 @@ function analyzeFile (filePath) {
let messagesInCurClass = 0

function checkForUnneccessaryComponentMessagesDefinition () {
if (curClass && foundComponetMessagesDefinition && messagesInCurClass === 0)
if (curClass && foundComponetMessagesDefinition && messagesInCurClass === 0) {
addIssue(
'unneccessaryComponentMessageDefinition',
`Unneccessary component definition found in class '${curClass}' in file '${filePath}'`
)
}
}

contents.forEach(line => {
Expand Down
32 changes: 16 additions & 16 deletions scripts/seedData.js
Expand Up @@ -42,17 +42,17 @@ async function createProject (data) {
headers,
body: JSON.stringify(data)
})
.then(res => res.json())
.catch(err => console.log(err))
.then(res => res.json())
.catch(err => console.log(err))
}

async function getFeedVersion (feedVersionId) {
return fetch(`${API_ENDPOINT}/feedversion/${feedVersionId}`, {
method: 'get',
headers
})
.then(res => res.json())
.catch(err => console.log(err))
.then(res => res.json())
.catch(err => console.log(err))
}

async function createFeedSource (data) {
Expand All @@ -61,26 +61,26 @@ async function createFeedSource (data) {
headers,
body: JSON.stringify(data)
})
.then(res => res.json())
.catch(err => console.log(err))
.then(res => res.json())
.catch(err => console.log(err))
}

async function uploadFeedVersion (feedSource, filePath) {
const file = fs.createReadStream(filePath)
const formData = {file}
const url = `${API_ENDPOINT}/feedversion?feedSourceId=${feedSource.id}`
return request.post({url, formData})
.then(jobId => {
// make sure to close read stream
file.destroy()
return jobId
})
.catch(err => {
console.log(err)
.then(jobId => {
// make sure to close read stream
file.destroy()
return jobId
})
.catch(err => {
console.log(err)

// // Exit script if upload fails
// process.exit(1)
})
// // Exit script if upload fails
// process.exit(1)
})
}

async function jobIsActive (jobId) {
Expand Down

0 comments on commit e3da05e

Please sign in to comment.