Skip to content

Commit

Permalink
Merge pull request #96 from duyoji/fix/lint-errors#95
Browse files Browse the repository at this point in the history
Fix lint errors
  • Loading branch information
duyoji authored Dec 27, 2017
2 parents e7d0619 + d919ae3 commit d77c405
Show file tree
Hide file tree
Showing 47 changed files with 103 additions and 99 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"jest:server": "jest server",
"eject": "react-scripts eject",
"eslint": "./node_modules/.bin/eslint src server",
"postinstall": "yarn jest:server && yarn build"
"postinstall": "yarn eslint && yarn jest && yarn build"
},
"devDependencies": {
"eslint": "^4.13.1",
Expand Down
4 changes: 1 addition & 3 deletions server/__tests__/socketHandlers/closeGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ describe('server/socketHandlers/closeGame.js', () => {
});

it('should emit data when error happens.', () => {
let receivedEventTypeFromOn = '';
const callbackForOn = (eventType, callback) => {
receivedEventTypeFromOn = eventType;
const callbackForOn = (eventType, callback) => { // eslint-disable-line no-unused-vars
callback();
};

Expand Down
6 changes: 2 additions & 4 deletions server/__tests__/socketHandlers/getRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ describe('server/socketHandlers/getRooms.js', () => {
});

it('should include error if there is error', () => {
let receivedEventTypeFromOn = '';
const callbackForOn = (eventType, callback) => {
receivedEventTypeFromOn = eventType;
const callbackForOn = (eventType, callback) => { // eslint-disable-line no-unused-vars
callback();
};

let receivedEventTypeFromEmit = '';
let receivedEventTypeFromEmit = ''; // eslint-disable-line no-unused-vars
let receivedDataFromEmit = null;
const callbackForEmit = (eventType, data) => {
receivedEventTypeFromEmit = eventType;
Expand Down
10 changes: 3 additions & 7 deletions server/__tests__/socketHandlers/updateLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('server/socketHandlers/updateLocation.js', () => {
longitude: 9999
};
const DUMMY_NAME = 'USER_NAME';
const DUMMY_ICON_URL = 'https://oni-on-cheese.heroku.com/icon.png'
const DUMMY_ICON_URL = 'https://oni-on-cheese.heroku.com/icon.png';

beforeAll((done) => {
// Wait for connecting to redis
Expand Down Expand Up @@ -73,9 +73,7 @@ describe('server/socketHandlers/updateLocation.js', () => {
});

it('should includes error in emitted data when `roomId` is not passed.', () => {
let receivedEventTypeFromOn = '';
const callbackForOn = (eventType, callback) => {
receivedEventTypeFromOn = eventType;
const callbackForOn = (eventType, callback) => { // eslint-disable-line no-unused-vars
callback({
location: DUMMY_LOCATION
});
Expand Down Expand Up @@ -104,9 +102,7 @@ describe('server/socketHandlers/updateLocation.js', () => {
});

it('should includes error in emitted data when `location` is not passed.', () => {
let receivedEventTypeFromOn = '';
const callbackForOn = (eventType, callback) => {
receivedEventTypeFromOn = eventType;
const callbackForOn = (eventType, callback) => { // eslint-disable-line no-unused-vars
callback({
roomId: DUMMY_ROOM_ID,
});
Expand Down
2 changes: 1 addition & 1 deletion server/socketHandlers/joinRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const joinRoom = (socket, socketNamespace) => {
}

// For user joining this room.
socket.emit(EVENT_TYPES.EMIT, formatOutput({data: `Join succeeded.`}));
socket.emit(EVENT_TYPES.EMIT, formatOutput({data: 'Join succeeded.'}));

// For users already joined this room.
socket.to(roomId).emit(EVENT_TYPES.EMIT, formatOutput({data: `${socket.id} has joined this room.`}));
Expand Down
4 changes: 2 additions & 2 deletions server/socketHandlers/updateLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const updateLocation = (socket, socketNamespace) => {
})
.then(user => {
socketNamespace.in(roomId).emit(EVENT_TYPES.EMIT, formatOutput({data: user.serialize()}));
console.log(`Emitted to ${roomId} from ${id} of user, location: ${location}`);
console.log(`Emitted to ${roomId} from ${id} of user, location: ${location}`); // eslint-disable-line no-console
})
.catch(error => {
socket.emit(EVENT_TYPES.EMIT, formatOutput({error}));
console.error(`Error: Tried to emit to ${roomId} from ${id} of user, the reason of error is ${error}`);
console.error(`Error: Tried to emit to ${roomId} from ${id} of user, the reason of error is ${error}`); // eslint-disable-line no-console
});
});
};
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/actions/clearUsers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { clearUsers } from '../../actions/clearUsers';
import { getDefaultState } from '../../reducers/index';

describe('src/actions/clearUsers.js', () => {
it('return expected action.', () => {
const userName = 'DUMMY_USER_NAME';
expect(clearUsers()).toEqual({
type: 'CLEAR_USERS'
});
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/actions/connectedToSocket.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { connectedToSocket } from '../../actions/connectedToSocket';
import { getDefaultState } from '../../reducers/index';

describe('src/actions/connectedToSocket.js', () => {
it('return expected action.', () => {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/actions/helpers/joinRoomHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { joinRoomPromise } from '../../../actions/helpers/joinRoomHelper';
import socket from '../../socketHandlers/index';
import { expectation } from 'sinon';

describe('src/__tests__/actions/helpers/joinRoomHelper.js', () => {
afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/actions/joinRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('src/__tests__/actions/joinRoom.js', () => {
});

return store.dispatch( joinRoom(roomId) )
.then((data) => {
.then((data) => { // eslint-disable-line no-unused-vars
const expectedActions = store.getActions();
expect(expectedActions[0]).toEqual({
type: 'JOIN_ROOM',
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/actions/leaveRoom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { leaveRoom } from '../../actions/leaveRoom';
import { getDefaultState } from '../../reducers/index';

describe('src/actions/leaveRoom.js', () => {
it('return expected action.', () => {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/actions/setUserName.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { setUserName } from '../../actions/setUserName';
import { getDefaultState } from '../../reducers/index';

describe('src/actions/setUserName.js', () => {
it('return expected action.', () => {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/actions/updateLocation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { updateLocation } from '../../actions/updateLocation';
import { getDefaultState } from '../../reducers/index';

describe('src//actions/updateLocation.js', () => {
it('return expected action.', () => {
Expand Down
7 changes: 3 additions & 4 deletions src/__tests__/components/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import React from 'react'; // eslint-disable-line no-unused-vars
import { MemoryRouter } from 'react-router-dom'; // eslint-disable-line no-unused-vars
import App from '../../components/App'; // eslint-disable-line no-unused-vars
import { Provider } from 'react-redux'; // eslint-disable-line no-unused-vars
import { createStore } from 'redux';
import { mount } from '../helpers/configuredEnzymeWithAdapter';
import { getDefaultState } from '../../reducers/index';
import configureMockStore from 'redux-mock-store';
Expand All @@ -22,7 +21,7 @@ describe('src/components/App.jsx', () => {
it('redirect to login page.', () => {
const wrapper = createWrapper('/');
expect(wrapper.find('.topPage').length).toBe(1);
})
});
});

describe('When access to `/game-list`', () => {
Expand All @@ -44,7 +43,7 @@ describe('src/components/App.jsx', () => {
});

const createWrapper = (path) => {
const store = mockStore(getDefaultState());
const store = mockStore(getDefaultState());

return mount(
<Provider store={store}>
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/components/GameListPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import GameListPage from '../../components/GameListPage';
import React from 'react'; // eslint-disable-line no-unused-vars
import GameListPage from '../../components/GameListPage'; // eslint-disable-line no-unused-vars
import { ListGroup, ListGroupItem } from 'reactstrap';
import { Redirect } from 'react-router-dom';
import { shallow } from '../helpers/configuredEnzymeWithAdapter';
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Header from '../../components/Header';
import React from 'react'; // eslint-disable-line no-unused-vars
import Header from '../../components/Header'; // eslint-disable-line no-unused-vars
import { Navbar, NavbarBrand } from 'reactstrap';
import { shallow } from '../helpers/configuredEnzymeWithAdapter';

Expand Down
7 changes: 3 additions & 4 deletions src/__tests__/components/MapPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import MapPage from '../../components/MapPage';
import React from 'react'; // eslint-disable-line no-unused-vars
import MapPage from '../../components/MapPage'; // eslint-disable-line no-unused-vars
import { shallow } from '../helpers/configuredEnzymeWithAdapter';
import * as utilLocation from '../../utils/location';
import sinon from 'sinon';
Expand Down Expand Up @@ -43,7 +42,7 @@ describe('src/components/MapPage.jsx', () => {
expect(typeof error).toEqual('function');
expect(options).toEqual(undefined);

success(createMockLocation())
success(createMockLocation());
});
sinon.stub(utilLocation, 'watchPosition').callsFake(({success, error, options}) => {
expect(typeof success).toEqual('function');
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/components/loaders/MapLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React from 'react'; // eslint-disable-line no-unused-vars
import { shallow } from '../../helpers/configuredEnzymeWithAdapter';
import MapLoader from '../../../components/loaders/MapLoader';
import MapLoader from '../../../components/loaders/MapLoader'; // eslint-disable-line no-unused-vars
import { BeatLoader } from 'react-spinners';

describe('src/components/loaders/MapLoader.jsx', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/components/modals/InputUserNameModal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React from 'react'; // eslint-disable-line no-unused-vars
import { shallow } from '../../helpers/configuredEnzymeWithAdapter';
import InputUserNameModal from '../../../components/modals/InputUserNameModal';
import InputUserNameModal from '../../../components/modals/InputUserNameModal'; // eslint-disable-line no-unused-vars
import { Modal } from 'reactstrap';
import '../../helpers/mockLocalStorage';

Expand All @@ -25,4 +25,4 @@ describe('src/components/modals/InputUserNameModal.jsx', () => {
});
});

const craeteMockFunctionOfSetUserName = (userName) => {};
const craeteMockFunctionOfSetUserName = (userName) => {}; // eslint-disable-line no-unused-vars
6 changes: 5 additions & 1 deletion src/__tests__/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import AppContainer from '../../containers/App';
import AppComponent from '../../components/App';

import socket from '../../socketHandlers/index';

describe('src/containers/App', () => {
afterAll(() => {
socket.disconnect();
});

it('should includes App component as a wrapped component.', () => {
expect(AppContainer.WrappedComponent).toEqual(AppComponent);
});
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/containers/GameListPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import GameListPageContainer from '../../containers/GameListPage';
import GameListPageComponent from '../../components/GameListPage';
import socket from '../../socketHandlers/index';

describe('src/containers/App', () => {
afterAll(() => {
socket.disconnect();
});

it('should includes GameListPage component as a wrapped component.', () => {
expect(GameListPageContainer.WrappedComponent).toEqual(GameListPageComponent);
});
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/containers/MapPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import MapPageContainer from '../../containers/MapPage';
import MapPageComponent from '../../components/MapPage';
import socket from '../../socketHandlers/index';

describe('src/containers/MapPage.js', () => {
afterAll(() => {
socket.disconnect();
});

it('should includes MapPage component as a wrapped component.', () => {
expect(MapPageContainer.WrappedComponent).toEqual(MapPageComponent);
});
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/helpers/mockLocalStorage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is for tests that use window.localStorage.
// Thanks to this file, we can avoid errors such as `TypeError: Cannot read property 'getItem' of undefined`
window.localStorage = window.localStorage || {};
window.localStorage.setItem = window.localStorage.setItem || ((key, value) => {});
window.localStorage.getItem = window.localStorage.getItem || ((key) => {});
window.localStorage.setItem = window.localStorage.setItem || ((key, value) => {}); // eslint-disable-line no-unused-vars
window.localStorage.getItem = window.localStorage.getItem || ((key) => {}); // eslint-disable-line no-unused-vars
2 changes: 1 addition & 1 deletion src/__tests__/socketHandlers/connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {addHandlerListener} from '../../socketHandlers/connect';
import socket from '../../socketHandlers/index';
import sinon, { expectation } from 'sinon';
import sinon from 'sinon';

describe('src/socketHandlers/connect.js', () => {
afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/socketHandlers/leaveRoom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addHandlerListener } from '../../socketHandlers/leaveRoom';
import socket from '../../socketHandlers/index';
import sinon, { expectation } from 'sinon';
import sinon from 'sinon';

describe('src/socketHandlers/updateLocation.js', () => {
afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/socketHandlers/reconnect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {addHandlerListener} from '../../socketHandlers/reconnect';
import socket from '../../socketHandlers/index';
import sinon, { expectation } from 'sinon';
import sinon from 'sinon';

describe('src/socketHandlers/reconnect.js', () => {
afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/socketHandlers/updateLocation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {emit, addHandlerListener} from '../../socketHandlers/updateLocation';
import socket from '../../socketHandlers/index';
import sinon, { expectation } from 'sinon';
import sinon from 'sinon';

describe('src/socketHandlers/updateLocation.js', () => {
const LATITUDE = 12345;
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/utils/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const mockLocalStorage = {};
describe('src/utils/localStorage.js', () => {
beforeAll(() => {
window.localStorage = window.localStorage || {};
window.localStorage.setItem = window.localStorage.setItem || ((key, value) => {});
window.localStorage.getItem = window.localStorage.getItem || ((key) => {});
window.localStorage.setItem = window.localStorage.setItem || ((key, value) => {}); // eslint-disable-line no-unused-vars
window.localStorage.getItem = window.localStorage.getItem || ((key) => {}); // eslint-disable-line no-unused-vars
});

describe('The setUserName function', () => {
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/utils/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ describe('src/utils/location.js', () => {
code: 1234,
message: 'This is dummy error.'
};
let callbackForSuccess = ({latitude, longitude}) => {};
let callbackForError = (err) => {};
let callbackForSuccess = ({latitude, longitude}) => {}; // eslint-disable-line no-unused-vars
let callbackForError = (err) => {}; // eslint-disable-line no-unused-vars

describe('The getCurrentPosition function', () => {
let isSuccess = true;

beforeAll(() => {
navigator.geolocation = navigator.geolocation || {};
navigator.geolocation.getCurrentPosition
= navigator.geolocation.getCurrentPosition || function(success, error, options) {
= navigator.geolocation.getCurrentPosition || function(success, error, options) { // eslint-disable-line no-unused-vars
if(isSuccess) {
const position = {
latitude: DUMMY_LATITUDE,
Expand All @@ -26,7 +26,7 @@ describe('src/utils/location.js', () => {
} else {
callbackForError(DUMMY_ERROR);
}
};
};
});

afterAll(() => {
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('src/utils/location.js', () => {
beforeAll(() => {
navigator.geolocation = navigator.geolocation || {};
navigator.geolocation.watchPosition
= navigator.geolocation.watchPosition || function(success, error, options) {
= navigator.geolocation.watchPosition || function(success, error, options) { // eslint-disable-line no-unused-vars
if(isSuccess) {
const position = {
latitude: DUMMY_LATITUDE,
Expand All @@ -77,7 +77,7 @@ describe('src/utils/location.js', () => {
} else {
callbackForError(DUMMY_ERROR);
}
};
};
});

afterAll(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/connectedToSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const connectedToSocket = (socketId) => {
return {
type: 'CONNECTED_TO_SOCKET',
socketId
}
};
};

export { connectedToSocket };
4 changes: 2 additions & 2 deletions src/actions/getRooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const getRooms = () => {
dispatch(getRoomsSuccess(roomIds));
} catch(err) {
// TODO: We have to decide a specification when error happen.
console.error(err);
console.error(err); // eslint-disable-line no-console
}
}
};
};

const getRoomsSuccess = (roomIds) => ({
Expand Down
Loading

0 comments on commit d77c405

Please sign in to comment.