Skip to content

Commit

Permalink
chore(all): include more eslint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcui committed May 24, 2018
1 parent 251184a commit d582821
Show file tree
Hide file tree
Showing 108 changed files with 2,229 additions and 2,062 deletions.
32 changes: 31 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@
{
"args": "none"
}
],
"no-mixed-requires": [
"error",
true
],
"block-spacing": [
"error",
"always"
],
"brace-style": [
"error",
"1tbs"
],
"comma-spacing": [
"error"
],
"space-before-blocks": [
"error",
"always"
]
}
},
"overrides": [
{
"files": ["bin/tsw/wwwroot/*.js"],
"env": {
"browser": true
},
"globals": {
"define": true
}
}
]
}
6 changes: 3 additions & 3 deletions bin/lib/api/cmdb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const Deferred = require('util/Deferred');


this.GetDeviceThisServer = function(){
this.GetDeviceThisServer = function() {
var defer = Deferred.create();

return defer.resolve(null);
Expand All @@ -19,13 +19,13 @@ this.GetDeviceThisServer = function(){
/**
* 查询父业务树信息
*/
this.GetAllParentBusiness = function(opt){
this.GetAllParentBusiness = function(opt) {
var defer = Deferred.create();

return defer.resolve(null);
};

this.GetDeviceByIp = function(opt){
this.GetDeviceByIp = function(opt) {
var defer = Deferred.create();

return defer.resolve(null);
Expand Down
2 changes: 1 addition & 1 deletion bin/lib/api/code/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
'use strict';

this.watch = function(){
this.watch = function() {


};
56 changes: 28 additions & 28 deletions bin/lib/api/keyman/alphaMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ var cache = {
dataFile: {}
};

if(global[__filename]){
if(global[__filename]) {
cache = global[__filename];
}else{
global[__filename] = cache;
isFirstLoad = true;
}


if(isFirstLoad){
if(config.alphaFile){
if(isFirstLoad) {
if(config.alphaFile) {

(function(){
(function() {
//导入alphaFile
var text = '';

try{
text = fs.readFileSync(config.alphaFile,'UTF-8');
}catch(e){
text = fs.readFileSync(config.alphaFile, 'UTF-8');
}catch(e) {
logger.warn(e.stack);
}

if(!text){
if(!text) {
return;
}

if(text.length >= 2 * 1024 * 1024){
if(text.length >= 2 * 1024 * 1024) {
logger.error('alpha file limit <=2M');
return;
}
Expand All @@ -61,68 +61,68 @@ if(isFirstLoad){
}


function getMap(text){
function getMap(text) {

var map = {};

text = text || '';

text.replace(/^([0-9a-zA-Z_-]+).*$/gm,function($0,key){
text.replace(/^([0-9a-zA-Z_-]+).*$/gm, function($0, key) {
map[key] = 1;
});

return map;
}

function updateMap(text){
function updateMap(text) {

var map = getMap(text);

//copy
Object.assign(map,cache.dataFile);
Object.assign(map, cache.dataFile);

cache.data = map;

logger.debug('update ok');
}


this.getSync = function(){
this.getSync = function() {
this.get();

return cache.data;
};

this.get = function(){
this.get = function() {

var defer = Deferred.create();
var delay = (process.serverInfo && process.serverInfo.cpu * 1000) || 0;
var l5api = config.tswL5api['alphaFileUrl'];

if(Date.now() - cache.timeUpdate < 60000 + delay){
if(Date.now() - cache.timeUpdate < 60000 + delay) {
return defer.resolve(cache.data);
}

cache.timeUpdate = Date.now();

if(!fileUrl){
if(!fileUrl) {
return defer.resolve(cache.data);
}

fileCache.getAsync(fileUrl).done(function(d){
fileCache.getAsync(fileUrl).done(function(d) {

var lastModifyTime = 0;
var text = '';

if(d && d.stats){
if(d && d.stats) {
lastModifyTime = d.stats.mtime.getTime();
}

if(d && d.data){
if(d && d.data) {
text = d.data.toString('utf-8');
}

if(Date.now() - lastModifyTime < 60000){
if(Date.now() - lastModifyTime < 60000) {
logger.debug('使用本地文件');

updateMap(text);
Expand All @@ -143,26 +143,26 @@ this.get = function(){
key: 'EVENT_TSW_ALPHA_FILE_URL'
},
dataType: 'text'
}).fail(function(d){
}).fail(function(d) {
defer.resolve(cache.data);
}).done(function(d){
}).done(function(d) {

var text = '';

if(d && d.result && typeof d.result === 'string'){
if(d && d.result && typeof d.result === 'string') {

text = d.result;
}

if(text.length >= 2 * 1024 * 1024){
if(text.length >= 2 * 1024 * 1024) {
logger.error('alpha file limit <=2M');
return defer.resolve(cache.data);
}

updateMap(text);

//保存在本地
fileCache.set(fileUrl,Buffer.from(text,'UTF-8'));
fileCache.set(fileUrl, Buffer.from(text, 'UTF-8'));

defer.resolve(cache.data);
});
Expand All @@ -173,16 +173,16 @@ this.get = function(){
};


function init(){
function init() {

var buffer = null;
var text = '';

if(fileUrl){
if(fileUrl) {
buffer = fileCache.getSync(fileUrl).data;
}

if(buffer){
if(buffer) {
text = buffer.toString('utf-8');
updateMap(text);
}
Expand Down
Loading

0 comments on commit d582821

Please sign in to comment.