Skip to content

Commit

Permalink
Eslint 규칙 적용
Browse files Browse the repository at this point in the history
- travis script에 eslint 추가
  • Loading branch information
kyungmi.k authored and kyungmi committed Aug 21, 2017
1 parent dcc2719 commit 055e4aa
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 444 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
Expand Up @@ -3,7 +3,10 @@
"rules": {
// 테스트 또는 개발환경을 구성하는 파일에서는 devDependency 사용을 허용
"import/no-extraneous-dependencies": ["error", {
"devDependencies": ["webpack.*.config.js", "*-dev-server.js", "**/*.test.js", "**/*.spec.js", "gulpfile.js"]}
]
"devDependencies": ["webpack.*.config.js", "*-dev-server.js", "**/*.test.js", "**/*.spec.js", "gulpfile.js", "**/index.js"]}
],
"import/first": 1,
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"no-param-reassign": ["error", { "props": false }]
}
}
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,9 @@ node_js: '6'
cache: yarn
before_install: yarn global add greenkeeper-lockfile@1
before_script: greenkeeper-lockfile-update
script: yarn test
script:
- yarn test
- yarn run lint
after_script: greenkeeper-lockfile-upload
services: mongodb
branches:
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -14,7 +14,8 @@
"start:dev": "gulp dev-start",
"webpack:prod": "NODE_ENV=production webpack --config=./webpack.config.js",
"webpack:dev": "NODE_ENV=development webpack --config=./webpack.config.js",
"test": "jest --forceExit"
"test": "jest --forceExit",
"lint": "eslint ./src"
},
"jest": {
"verbose": true,
Expand Down Expand Up @@ -71,7 +72,7 @@
"winston": "^2.3.0"
},
"devDependencies": {
"@ridi/eslint-config": "^3.0.0",
"@ridi/eslint-config": "*",
"babel-core": "^6.21.0",
"babel-jest": "^20.0.3",
"babel-preset-env": "^1.3.3",
Expand Down
76 changes: 46 additions & 30 deletions src/common/api.js
Expand Up @@ -19,14 +19,16 @@ axios.defaults.headers.put['Content-Type'] = 'application/json';
/**
* Try to login
* @param {Object} data
* - {string} username
* - {string} password
* @param {string} data.username
* @param {string} data.password
* @returns {Promise}
*/
exports.login = data => axios.post('/login', data);

/**
*
* @param data
* Change user password
* @param {object} data
* @returns {Promise}
*/
exports.changePassword = data => axios.put('/passwords', data);

Expand All @@ -35,110 +37,124 @@ exports.changePassword = data => axios.put('/passwords', data);
* @param {string} filter - filter name: 'current' or 'expired'
* @param {number} skip - numbers of records to be skipped
* @param {number} limit - numbers of records to be returned
* @returns {Promise}
*/
exports.getStatus = (filter, skip, limit) => axios.get('/status', { params: { filter, skip, limit } });

/**
* Add a status
* @param {Object} data
* - {string} type
* - {Array} deviceTypes
* - {string} startTime (ISO 8601 format)
* - {string} endTime (ISO 8601 format)
* - {string} contents
* - {boolean} isActivated
* - {string} deviceSemVersion
* - {string} appSemVersion
* @param {string} data.type
* @param {Array} data.deviceTypes
* @param {string} data.startTime (ISO 8601 format)
* @param {string} data.endTime (ISO 8601 format)
* @param {string} data.contents
* @param {boolean} data.isActivated
* @param {string} data.deviceSemVersion
* @param {string} data.appSemVersion
* @returns {Promise}
*/
exports.addStatus = data => axios.post('/status', data);

/**
* Update a status
* @param {string} statusId
* @param {Object} data
* - {string} type
* - {Array} deviceTypes
* - {string} startTime (ISO 8601 format)
* - {string} endTime (ISO 8601 format)
* - {string} contents
* - {boolean} isActivated
* - {string} deviceSemVersion
* - {string} appSemVersion
* @param {string} data.type
* @param {Array} data.deviceTypes
* @param {string} data.startTime (ISO 8601 format)
* @param {string} data.endTime (ISO 8601 format)
* @param {string} data.contents
* @param {boolean} data.isActivated
* @param {string} data.deviceSemVersion
* @param {string} data.appSemVersion
* @returns {Promise}
*/
exports.updateStatus = (statusId, data) => axios.put(`/status/${statusId}`, data);

/**
* Remove a status
* @param {string} statusId
* @returns {Promise}
*/
exports.removeStatus = statusId => axios.delete(`/status/${statusId}`);

/**
* Activate a status
* @param {string} statusId
* @returns {Promise}
*/
exports.activateStatus = statusId => axios.put(`/status/${statusId}/activate`);

/**
* Deactivate a status
* @param {string} statusId
* @returns {Promise}
*/
exports.deactivateStatus = statusId => axios.put(`/status/${statusId}/deactivate`);

/**
* Get status type list
* @returns {Promise}
*/
exports.getStatusTypes = () => axios.get('/status-types');

/**
* Add a status type
* @param {Object} data
* - {string} label
* - {string} value
* - {string} template
* @param {string} data.label
* @param {string} data.value
* @param {string} data.template
* @returns {Promise}
*/
exports.addStatusType = data => axios.post('/status-types', data);

/**
* Update a status type
* @param {string} statusTypeId
* @param {Object} data
* - {string} label
* - {string} value
* - {string} template
* @param {string} data.label
* @param {string} data.value
* @param {string} data.template
* @returns {Promise}
*/
exports.updateStatusType = (statusTypeId, data) => axios.put(`/status-types/${statusTypeId}`, data);

/**
* Remove a status type
* @param {string} statusTypeId
* @returns {Promise}
*/
exports.removeStatusType = statusTypeId => axios.delete(`/status-types/${statusTypeId}`);

/**
* Get device type list
* @returns {Promise}
*/
exports.getDeviceTypes = () => axios.get('/device-types');

/**
* Add a device type
* @param {Object} data
* - {string} label
* - {string} value
* @param {string} data.label
* @param {string} data.value
* @returns {Promise}
*/
exports.addDeviceType = data => axios.post('/device-types', data);

/**
* Update a device type
* @param {string} deviceTypeId
* @param {Object} data
* - {string} label
* - {string} value
* @param {string} data.label
* @param {string} data.value
* @returns {Promise}
*/
exports.updateDeviceType = (deviceTypeId, data) => axios.put(`/device-types/${deviceTypeId}`, data);

/**
* Remove a device type
* @param {string} deviceTypeId
* @returns {Promise}
*/
exports.removeDeviceType = deviceTypeId => axios.delete(`/device-types/${deviceTypeId}`);
8 changes: 4 additions & 4 deletions src/common/common-util.js
Expand Up @@ -10,7 +10,7 @@
* Will return 127.0.0.1 when testing locally
* Useful when you need the user ip for geolocation or serving localized content
*
* @param request
* @param {Object} request
* @returns {string} ip
*/
exports.getClientIp = (request) => {
Expand Down Expand Up @@ -117,12 +117,12 @@ const stringifier = {

exports.parseSemVersion = (semVerString) => {
if (!semVerString) {
return [{ comparator: '*' }]; // default
return [{ comparator: '*' }]; // default
}
const conditions = semVerString.split('||').map(cond => cond.trim()); // OR 연산을 기준으로 분리
const conditions = semVerString.split('||').map(cond => cond.trim()); // OR 연산을 기준으로 분리
const result = [];
conditions.forEach((cond) => {
regex.lastIndex = 0; // reset find index
regex.lastIndex = 0; // reset find index
const comparator = getComparator(cond);
const parsedObj = parsers[comparator](cond);
if (parsedObj) {
Expand Down
1 change: 1 addition & 0 deletions src/common/date-util.js
Expand Up @@ -10,6 +10,7 @@ const moment = require('moment');
* Format all dates in the received model
* @param {Array|Date|Object} model
* @param {string} [formatString]
* @param {number} [utcOffset]
* @returns {*}
*/
exports.formatDates = (model, formatString, utcOffset) => {
Expand Down
2 changes: 1 addition & 1 deletion src/config/server.config.js
Expand Up @@ -18,7 +18,7 @@ const configs = {
},
auth: {
secretKey: 'secretKey',
tokenTTL: 24 * 60 * 60 * 1000, // in millisecond
tokenTTL: 24 * 60 * 60 * 1000, // in millisecond
},
directory: {
component: 'component',
Expand Down
3 changes: 1 addition & 2 deletions src/repository/Model.js
Expand Up @@ -19,7 +19,6 @@ const logger = require('winston');
* @classdesc basic interactions with selected collection
*/
class Model {

constructor(collection, indexes) {
if (new.target === Model) {
throw new TypeError('Cannot construct Model instances directly');
Expand All @@ -36,7 +35,7 @@ class Model {

runQuery(fn) {
const self = this;
return co(function* () {
return co(function* run() {
const db = yield MongoClient.connect(url);
const collection = db.collection(self.collection);
const result = yield fn.call(self, collection);
Expand Down
2 changes: 1 addition & 1 deletion src/repository/Status.js
@@ -1,4 +1,4 @@
/**
/**
* Status model
*
* @since 1.0.0
Expand Down
1 change: 0 additions & 1 deletion src/router/device-type-api-router.js
Expand Up @@ -9,7 +9,6 @@ const DeviceType = require('./../repository/DeviceType');
const config = require('../config/server.config').url;
const dateUtil = require('../common/date-util');
const SSSError = require('../common/Error');
const logger = require('winston');

module.exports = [
{
Expand Down
6 changes: 5 additions & 1 deletion src/router/status-api-router.js
Expand Up @@ -49,7 +49,11 @@ module.exports = [
method: 'GET',
path: `${config.statusApiPrefix}/check`,
handler: (request, reply) => {
Status.findWithComparators(request.query.deviceType || '*', request.query.deviceVersion || '*', request.query.appVersion || '*', { startTime: 1 })
Status.findWithComparators(
request.query.deviceType
|| '*', request.query.deviceVersion
|| '*', request.query.appVersion
|| '*', { startTime: 1 })
.then(result => dateUtil.formatDates(result))
.then(result => reply({ data: result }))
.catch(err => reply(err));
Expand Down
24 changes: 12 additions & 12 deletions src/server.js
Expand Up @@ -133,15 +133,15 @@ exports.addPlugin = (pluginSetting) => {
};

exports.start = extraRoutes => server.register(plugins)
.then(() => {
_setAuthStrategy();
_setViewEngine();
_setRoutes(extraRoutes);
})
.then(() => _setInitalData())
.then(() => server.start())
.then(() => {
logger.log('Server running at:', server.info.uri);
return server;
})
.catch((error) => { throw error; });
.then(() => {
_setAuthStrategy();
_setViewEngine();
_setRoutes(extraRoutes);
})
.then(() => _setInitalData())
.then(() => server.start())
.then(() => {
logger.log('Server running at:', server.info.uri);
return server;
})
.catch((error) => { throw error; });

0 comments on commit 055e4aa

Please sign in to comment.