fix: sonar错误处理

This commit is contained in:
wenbo.dong 2017-09-08 11:18:30 +08:00
parent 6633b47800
commit 3ece0da95c
8 changed files with 48 additions and 40 deletions

View File

@ -1,5 +1,6 @@
import React from 'react'
import moment from 'moment'
import React from 'react';
import moment from 'moment';
import constants from './constants/variable';
exports.formatTime = (timestamp) => {
@ -86,7 +87,7 @@ exports.handlePath = (path) => {
return path;
}
// 名称限制 20 字符
// 名称限制 constants.NAME_LIMIT 字符
exports.nameLengthLimit = (type) => {
// 返回字符串长度汉字计数为2
const strLength = (str) => {
@ -101,10 +102,10 @@ exports.nameLengthLimit = (type) => {
required: true,
validator(rule, value, callback) {
const len = value ? strLength(value) : 0;
if (len > 20) {
callback('请输入' + type + '名称,长度不超过20字符(中文算作2字符)!');
if (len > constants.NAME_LIMIT) {
callback('请输入' + type + '名称,长度不超过' + constants.NAME_LIMIT + '字符(中文算作2字符)!');
} else if (len === 0) {
callback('请输入' + type + '名称,长度不超过20字符(中文算作2字符)!');
callback('请输入' + type + '名称,长度不超过' + constants.NAME_LIMIT + '字符(中文算作2字符)!');
} else {
return callback();
}

View File

@ -114,7 +114,10 @@ function run(options) {
rhymeCompleter = {
identifierRegexps: [/[@]/],
getCompletions: function (editor, session, pos, prefix, callback) {
if (prefix.length === 0) { callback(null, []); return }
if (prefix.length === 0) {
callback(null, []);
return;
}
callback(null, wordList.map(function (ea) {
return { name: ea.mock, value: ea.mock, score: ea.mock, meta: ea.name }
}));

View File

@ -23,9 +23,10 @@ class followController extends baseController {
*/
async list(ctx) {
let uid = this.getUid(),
page = ctx.request.query.page || 1,
limit = ctx.request.query.limit || 10;
let uid = this.getUid();
// 关注列表暂时不分页 page & limit 为分页配置
// page = ctx.request.query.page || 1,
// limit = ctx.request.query.limit || 10;
if (!uid) {
return ctx.body = yapi.commons.resReturn(null, 400, '用户id不能为空');

View File

@ -478,7 +478,8 @@ class interfaceController extends baseController {
try {
let id = parseInt(ctx.query.id, 10), result, userInst, userinfo, data;
if (!id) return ctx.websocket.send("id 参数有误");
result = await this.Model.get(id), userinfo;
await this.Model.get(id);
result = userinfo;
if (result.edit_uid !== 0 && result.edit_uid !== this.getUid()) {
userInst = yapi.getInst(userModel);
userinfo = await userInst.findById(result.edit_uid);
@ -603,7 +604,8 @@ class interfaceController extends baseController {
typeid: catData.project_id
});
let result = await this.catModel.del(id);
// no used variable 'result'
// let result = await this.catModel.del(id);
let r = await this.Model.delByCatid(id);
return ctx.body = yapi.commons.resReturn(r);
} catch (e) {

View File

@ -22,8 +22,9 @@ function matchApi(apiPath, apiRule) {
}
module.exports = async (ctx, next) => {
let hostname = ctx.hostname;
let config = yapi.WEBCONFIG;
// no used variable 'hostname' & 'config'
// let hostname = ctx.hostname;
// let config = yapi.WEBCONFIG;
let path = ctx.path;
@ -52,7 +53,7 @@ module.exports = async (ctx, next) => {
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
}
let interfaceData, newData, newpath;
let interfaceData, newpath;
let interfaceInst = yapi.getInst(interfaceModel);
try {

View File

@ -72,7 +72,7 @@ class interfaceModel extends baseModel {
getBaseinfo(id){
return this.model.findOne({
_id: id,
_id: id
}).select('path method uid title project_id cat_id status').exec()
}

View File

@ -50,7 +50,7 @@ module.exports = function(){
if(yapi.WEBCONFIG.plugins && Array.isArray(yapi.WEBCONFIG.plugins)){
yapi.WEBCONFIG.plugins.forEach(plugin=>{
if(!yapi.commons.fileExist(yapi.path.join(plugin_path, 'yapi-plugin-' + plugin + '/server.js'))){
throw new Error(`config.json配置了插件${plugin},但plugins目录没有找到此插件请安装此插件?`);
console.error(`config.json配置了插件${plugin},但plugins目录没有找到此插件请安装此插件?`);
process.exit();
}
let pluginModule = require(yapi.path.join(plugin_path, 'yapi-plugin-' + plugin + '/server.js'));

View File

@ -14,7 +14,7 @@ var compressPlugin = new CompressionPlugin({
algorithm: "gzip",
test: /\.(js|css)$/,
threshold: 10240,
minRatio: 0.8,
minRatio: 0.8
});
function fileExist (filePath){