Browse Source

Make linting green again

- disable some rules (put as warning)
- refactor some stuff
- fix some bugs introduced in 404e362 🐛
- fix some original bugs (paramater, argument)
pull/62/head
Adriean Khisbe 7 years ago
parent
commit
0dbab0c916
17 changed files with 143 additions and 140 deletions
  1. +6
    -15
      .eslintrc
  2. +6
    -5
      lib/api/comment.js
  3. +4
    -1
      lib/api/downtime.js
  4. +4
    -1
      lib/api/embed.js
  5. +5
    -2
      lib/api/event.js
  6. +4
    -1
      lib/api/graph.js
  7. +1
    -1
      lib/api/host.js
  8. +1
    -1
      lib/api/index.js
  9. +65
    -63
      lib/api/metric.js
  10. +8
    -12
      lib/api/monitor.js
  11. +4
    -1
      lib/api/screenboard.js
  12. +6
    -3
      lib/api/search.js
  13. +6
    -5
      lib/api/service-check.js
  14. +1
    -3
      lib/api/tag.js
  15. +8
    -11
      lib/api/timeboard.js
  16. +7
    -10
      lib/client.js
  17. +7
    -5
      lib/index.js

+ 6
- 15
.eslintrc View File

@ -20,20 +20,11 @@
],
"rules": {
"promise/no-native": "off",
"strict": "off"
"strict": "off",
"fp/no-arguments": "warn",
"no-param-reassign": "warn",
"prefer-rest-params": "warn",
"fp/no-loops": "warn"
},
"overrides": [
{
"files": [ "scripts/migrate*.js", "lib/*.js" ],
"env": {
"mongo": true
}
},
{
"files": ["**/test/**"],
"rules": {
"unicorn/filename-case": "off"
}
}
]
"overrides": []
}

+ 6
- 5
lib/api/comment.js View File

@ -75,12 +75,10 @@ module.exports = function(client) {
const params = {
body: {
message
message,
handle: handle || undefined
}
};
if (handle) {
params.body.handle = properties.handle;
}
client.request('PUT', util.format('/comments/%s', commentId), params, callback);
}
@ -150,7 +148,10 @@ module.exports = function(client) {
const commentId = args._[4];
remove(commentId, callback);
} else {
callback('unknown subcommand or arguments try `dogapi comment --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi comment --help` for help',
false
);
}
}
};


+ 4
- 1
lib/api/downtime.js View File

@ -235,7 +235,10 @@ module.exports = function(client) {
}
update(downtimeId, properties, callback);
} else {
callback('unknown subcommand or arguments try `dogapi downtime --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi downtime --help` for help',
false
);
}
}
};


+ 4
- 1
lib/api/embed.js View File

@ -162,7 +162,10 @@ module.exports = function(client) {
} else if (subcommand === 'getall') {
getAll(callback);
} else {
callback('unknown subcommand or arguments try `dogapi embed --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi embed --help` for help',
false
);
}
}
};


+ 5
- 2
lib/api/event.js View File

@ -118,7 +118,7 @@ module.exports = function(client) {
* ```
*/
function query(start, end, parameters, callback) {
if (arguments.length < 4 && typeof argument[2] === 'function') {
if (arguments.length < 4 && typeof arguments[2] === 'function') {
callback = parameters;
parameters = {};
}
@ -203,7 +203,10 @@ module.exports = function(client) {
}
create(title, text, properties, callback);
} else {
callback('unknown subcommand or arguments try `dogapi event --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi event --help` for help',
false
);
}
}
};


+ 4
- 1
lib/api/graph.js View File

@ -69,7 +69,10 @@ module.exports = function(client) {
const eventQuery = args.events;
snapshot(query, from, to, eventQuery, callback);
} else {
callback('unknown subcommand or arguments try `dogapi graph --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi graph --help` for help',
false
);
}
}
};


+ 1
- 1
lib/api/host.js View File

@ -102,7 +102,7 @@ module.exports = function(client) {
const hostname = args._[4];
unmute(hostname, callback);
} else {
callback('unknown subcommand or arguments try `dogapi host --help` for help', false);
return callback('unknown subcommand or arguments try `dogapi host --help` for help', false);
}
}
};


+ 1
- 1
lib/api/index.js View File

@ -10,7 +10,7 @@ module.exports = {
monitor: require('./monitor'),
screenboard: require('./screenboard'),
search: require('./search'),
serviceCheck: require('./serviceCheck'),
serviceCheck: require('./service-check'),
tag: require('./tag'),
timeboard: require('./timeboard'),
user: require('./user')


+ 65
- 63
lib/api/metric.js View File

@ -1,62 +1,4 @@
module.exports = function(client) {
/* section: metric
*comment: |
* submit a new metric
*params:
* metric: the metric name
* points: |
* a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`)
* or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`)
* extra: |
* optional, object which can contain the following keys
* * host: the host source of the metric
* * tags: array of "tag:value"'s to use for the metric
* * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge]
* callback: |
* function(err, res)
*example: |
* ```javascript
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.metric.send("my.metric", 1000, function(err, results){
* console.dir(results);
* });
* dogapi.metric.send("my.metric", [500, 1000], function(err, results){
* console.dir(results);
* });
* const now = parseInt(new Date().getTime() / 1000);
* dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){
* console.dir(results);
* });
* dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){
* console.dir(results);
* });
* ```
*/
function send(metric, points, extra, callback) {
if (arguments.length < 4 && typeof arguments[2] === 'function') {
callback = extra;
extra = {};
}
extra = extra || {};
const series = [
{
metric,
points,
host: extra.host,
tags: extra.tags,
// DEV: For backwards compatibility, allow `metric_type`
type: extra.type || extra.metric_type
}
];
send_all(series, callback);
}
/* section: metric
*comment: |
* send a list of metrics
@ -117,7 +59,6 @@ module.exports = function(client) {
// 500 => [<timestamp>, 500]
// [<timestamp>, 500] => unchanged
if (!Array.isArray(point)) {
const now = parseInt(new Date().getTime() / 1000);
point = [now, point];
}
return point;
@ -140,13 +81,71 @@ module.exports = function(client) {
client.request('POST', '/series', params, callback);
}
/* section: metric
*comment: |
* submit a new metric
*params:
* metric: the metric name
* points: |
* a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`)
* or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`)
* extra: |
* optional, object which can contain the following keys
* * host: the host source of the metric
* * tags: array of "tag:value"'s to use for the metric
* * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge]
* callback: |
* function(err, res)
*example: |
* ```javascript
* const dogapi = require("dogapi");
* const options = {
* api_key: "api_key",
* app_key: "app_key"
* };
* dogapi.initialize(options);
* dogapi.metric.send("my.metric", 1000, function(err, results){
* console.dir(results);
* });
* dogapi.metric.send("my.metric", [500, 1000], function(err, results){
* console.dir(results);
* });
* const now = parseInt(new Date().getTime() / 1000);
* dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){
* console.dir(results);
* });
* dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){
* console.dir(results);
* });
* ```
*/
function send(metric, points, extra, callback) {
if (arguments.length < 4 && typeof arguments[2] === 'function') {
callback = extra;
extra = {};
}
extra = extra || {};
const series = [
{
metric,
points,
host: extra.host,
tags: extra.tags,
// DEV: For backwards compatibility, allow `metric_type`
type: extra.type || extra.metric_type
}
];
send_all(series, callback);
}
/* section: metric
*comment: |
* make a metric query
*params:
* from: POSIX timestamp for start of query
* to: POSIX timestamp for end of query
* query: the string query to perform (e.g. "system.cpu.idle{*}by{host}")
* q: the string query to perform (e.g. "system.cpu.idle{*}by{host}")
* callback: function(err, res)
*example: |
* ```javascript
@ -164,12 +163,12 @@ module.exports = function(client) {
* });
* ```
*/
function query(from, to, query, callback) {
function query(from, to, q, callback) {
const params = {
query: {
from,
to,
query
query: q
}
};
client.request('GET', '/query', params, callback);
@ -213,7 +212,10 @@ module.exports = function(client) {
const q = args._[6];
query(from, to, q, callback);
} else {
callback('unknown subcommand or arguments try `dogapi metric --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi metric --help` for help',
false
);
}
}
};


+ 8
- 12
lib/api/monitor.js View File

@ -379,15 +379,8 @@ module.exports = function(client) {
];
},
handleCli(subcommand, args, callback) {
const states = [];
if (args.states) {
states = args.states.split(',');
}
const tags = [];
if (args.tags) {
tags = args.tags.split(',');
}
const states = args.states ? args.states.split(',') : [];
const tags = args.tags ? args.tags.split(',') : [];
const name = args.name;
const message = args.message;
@ -397,10 +390,10 @@ module.exports = function(client) {
get(monitorId, states, callback);
} else if (subcommand === 'getall') {
const options = {};
if (states.length) {
if (states.length > 0) {
options.group_states = states;
}
if (tags.length) {
if (tags.length > 0) {
options.tags = tags;
}
getAll(options, callback);
@ -448,7 +441,10 @@ module.exports = function(client) {
}
update(monitorId, query, properties, callback);
} else {
callback('unknown subcommand or arguments try `dogapi monitor --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi monitor --help` for help',
false
);
}
}
};


+ 4
- 1
lib/api/screenboard.js View File

@ -343,7 +343,10 @@ module.exports = function(client) {
create(boardTitle, widgets, options, callback);
} else {
callback('unknown subcommand or arguments try `dogapi screenboard --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi screenboard --help` for help',
false
);
}
}
};


+ 6
- 3
lib/api/search.js View File

@ -19,10 +19,10 @@ module.exports = function(client) {
* });
* ```
*/
function query(query, callback) {
function query(q, callback) {
const params = {
query: {
q: query
q
}
};
client.request('GET', '/search', params, callback);
@ -44,7 +44,10 @@ module.exports = function(client) {
if (subcommand === 'query' && args._.length > 4) {
query(args._[4], callback);
} else {
callback('unknown subcommand or arguments try `dogapi search --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi search --help` for help',
false
);
}
}
};


lib/api/serviceCheck.js → lib/api/service-check.js View File


+ 1
- 3
lib/api/tag.js View File

@ -1,5 +1,3 @@
const util = require('util');
module.exports = function(client) {
/* section: tag
*comment: |
@ -254,7 +252,7 @@ module.exports = function(client) {
} else if (subcommand === 'delete') {
remove(host, source, callback);
} else {
callback('unknown subcommand or arguments try `dogapi tag --help` for help', false);
return callback('unknown subcommand or arguments try `dogapi tag --help` for help', false);
}
}
};


+ 8
- 11
lib/api/timeboard.js View File

@ -67,7 +67,7 @@ module.exports = function(client) {
graphs
}
};
if (Array.isArray(templateVariables) && templateVariables.length) {
if (Array.isArray(templateVariables) && templateVariables.length > 0) {
params.body.template_variables = templateVariables;
}
@ -140,7 +140,7 @@ module.exports = function(client) {
graphs
}
};
if (Array.isArray(templateVariables) && templateVariables.length) {
if (Array.isArray(templateVariables) && templateVariables.length > 0) {
params.body.template_variables = templateVariables;
}
@ -251,10 +251,7 @@ module.exports = function(client) {
const title = args._[4];
const description = args._[5];
const graphs = json.parse(args._[6]);
const templateVariables = [];
if (args.tmpvars) {
templateVariables = json.parse(args.tmpvars);
}
const templateVariables = args.tmpvars ? json.parse(args.tmpvars) : [];
create(title, description, graphs, templateVariables, callback);
} else if (subcommand === 'update') {
@ -262,14 +259,14 @@ module.exports = function(client) {
const title = args._[5];
const description = args._[6];
const graphs = json.parse(args._[7]);
const templateVariables = [];
if (args.tmpvars) {
templateVariables = json.parse(args.tmpvars);
}
const templateVariables = args.tmpvars ? json.parse(args.tmpvars) : [];
update(dashId, title, description, graphs, templateVariables, callback);
} else {
callback('unknown subcommand or arguments try `dogapi timeboard --help` for help', false);
return callback(
'unknown subcommand or arguments try `dogapi timeboard --help` for help',
false
);
}
}
};


+ 7
- 10
lib/client.js View File

@ -2,7 +2,7 @@ const https = require('https');
const url = require('url');
const util = require('util');
const extend = require('extend');
const _ = require('lodash');
const _ = require('lodash/fp');
const json = require('./json');
/* section: client
@ -67,15 +67,12 @@ DatadogMetricClient.prototype.request = function(method, path, params, callback)
query
});
const http_options = _.assign(
{
hostname: this.api_host,
port: 443,
method: method.toUpperCase(),
path
},
this.http_options
);
const http_options = _.assign(this.http_options, {
hostname: this.api_host,
port: 443,
method: method.toUpperCase(),
path
});
if (this.proxy_agent) {
http_options.agent = this.proxy_agent;


+ 7
- 5
lib/index.js View File

@ -1,7 +1,9 @@
const _ = require('lodash');
const _ = require('lodash/fp');
const api = require('./api');
const Client = require('./client');
const forEach = _.forEach.convert({cap: false});
const initialClient = new Client({});
/* section: dogapi
*comment: configure the dogapi client with your app/api keys
@ -50,15 +52,15 @@ function initialize(options) {
function DogApi(options) {
const client = new Client(options || {});
_.forEach(api, (value, key) => {
forEach((value, key) => {
this[key] = value(client);
});
}, api);
}
DogApi.initialize = initialize;
_.forEach(api, (value, key) => {
forEach((value, key) => {
DogApi[key] = value(initialClient);
});
}, api);
/* section: dogapi
*comment: get the current POSIX timestamp


Loading…
Cancel
Save