changed functions to arrowfunctions for only-arrow-functions rule (#13127)

This commit is contained in:
Patrick O'Carroll
2018-09-04 15:55:41 +02:00
committed by Torkel Ödegaard
parent 826dfceac0
commit 0f326f18dc
50 changed files with 816 additions and 820 deletions

View File

@@ -12,12 +12,12 @@ describe('graphiteDatasource', () => {
instanceSettings: { url: 'url', name: 'graphiteProd', jsonData: {} },
};
beforeEach(function() {
beforeEach(() => {
ctx.instanceSettings.url = '/api/datasources/proxy/1';
ctx.ds = new GraphiteDatasource(ctx.instanceSettings, ctx.$q, ctx.backendSrv, ctx.templateSrv);
});
describe('When querying graphite with one target using query editor target spec', function() {
describe('When querying graphite with one target using query editor target spec', () => {
const query = {
panelId: 3,
dashboardId: 5,
@@ -30,14 +30,14 @@ describe('graphiteDatasource', () => {
let requestOptions;
beforeEach(async () => {
ctx.backendSrv.datasourceRequest = function(options) {
ctx.backendSrv.datasourceRequest = options => {
requestOptions = options;
return ctx.$q.when({
data: [{ target: 'prod1.count', datapoints: [[10, 1], [12, 1]] }],
});
};
await ctx.ds.query(query).then(function(data) {
await ctx.ds.query(query).then(data => {
results = data;
});
});
@@ -47,15 +47,15 @@ describe('graphiteDatasource', () => {
expect(requestOptions.headers['X-Panel-Id']).toBe(3);
});
it('should generate the correct query', function() {
it('should generate the correct query', () => {
expect(requestOptions.url).toBe('/api/datasources/proxy/1/render');
});
it('should set unique requestId', function() {
it('should set unique requestId', () => {
expect(requestOptions.requestId).toBe('graphiteProd.panelId.3');
});
it('should query correctly', function() {
it('should query correctly', () => {
const params = requestOptions.data.split('&');
expect(params).toContain('target=prod1.count');
expect(params).toContain('target=prod2.count');
@@ -63,17 +63,17 @@ describe('graphiteDatasource', () => {
expect(params).toContain('until=now');
});
it('should exclude undefined params', function() {
it('should exclude undefined params', () => {
const params = requestOptions.data.split('&');
expect(params).not.toContain('cacheTimeout=undefined');
});
it('should return series list', function() {
it('should return series list', () => {
expect(results.data.length).toBe(1);
expect(results.data[0].target).toBe('prod1.count');
});
it('should convert to millisecond resolution', function() {
it('should convert to millisecond resolution', () => {
expect(results.data[0].datapoints[0][0]).toBe(10);
});
});
@@ -106,11 +106,11 @@ describe('graphiteDatasource', () => {
};
beforeEach(async () => {
ctx.backendSrv.datasourceRequest = function(options) {
ctx.backendSrv.datasourceRequest = options => {
return ctx.$q.when(response);
};
await ctx.ds.annotationQuery(options).then(function(data) {
await ctx.ds.annotationQuery(options).then(data => {
results = data;
});
});
@@ -136,11 +136,11 @@ describe('graphiteDatasource', () => {
],
};
beforeEach(() => {
ctx.backendSrv.datasourceRequest = function(options) {
ctx.backendSrv.datasourceRequest = options => {
return ctx.$q.when(response);
};
ctx.ds.annotationQuery(options).then(function(data) {
ctx.ds.annotationQuery(options).then(data => {
results = data;
});
// ctx.$rootScope.$apply();
@@ -155,29 +155,29 @@ describe('graphiteDatasource', () => {
});
});
describe('building graphite params', function() {
it('should return empty array if no targets', function() {
describe('building graphite params', () => {
it('should return empty array if no targets', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{}],
});
expect(results.length).toBe(0);
});
it('should uri escape targets', function() {
it('should uri escape targets', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{ target: 'prod1.{test,test2}' }, { target: 'prod2.count' }],
});
expect(results).toContain('target=prod1.%7Btest%2Ctest2%7D');
});
it('should replace target placeholder', function() {
it('should replace target placeholder', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{ target: 'series1' }, { target: 'series2' }, { target: 'asPercent(#A,#B)' }],
});
expect(results[2]).toBe('target=asPercent(series1%2Cseries2)');
});
it('should replace target placeholder for hidden series', function() {
it('should replace target placeholder for hidden series', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [
{ target: 'series1', hide: true },
@@ -188,28 +188,28 @@ describe('graphiteDatasource', () => {
expect(results[0]).toBe('target=' + encodeURIComponent('asPercent(series1,sumSeries(series1))'));
});
it('should replace target placeholder when nesting query references', function() {
it('should replace target placeholder when nesting query references', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{ target: 'series1' }, { target: 'sumSeries(#A)' }, { target: 'asPercent(#A,#B)' }],
});
expect(results[2]).toBe('target=' + encodeURIComponent('asPercent(series1,sumSeries(series1))'));
});
it('should fix wrong minute interval parameters', function() {
it('should fix wrong minute interval parameters', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{ target: "summarize(prod.25m.count, '25m', 'sum')" }],
});
expect(results[0]).toBe('target=' + encodeURIComponent("summarize(prod.25m.count, '25min', 'sum')"));
});
it('should fix wrong month interval parameters', function() {
it('should fix wrong month interval parameters', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{ target: "summarize(prod.5M.count, '5M', 'sum')" }],
});
expect(results[0]).toBe('target=' + encodeURIComponent("summarize(prod.5M.count, '5mon', 'sum')"));
});
it('should ignore empty targets', function() {
it('should ignore empty targets', () => {
const results = ctx.ds.buildGraphiteParams({
targets: [{ target: 'series1' }, { target: '' }],
});
@@ -222,7 +222,7 @@ describe('graphiteDatasource', () => {
let requestOptions;
beforeEach(() => {
ctx.backendSrv.datasourceRequest = function(options) {
ctx.backendSrv.datasourceRequest = options => {
requestOptions = options;
return ctx.$q.when({
data: ['backend_01', 'backend_02'],
@@ -307,7 +307,7 @@ describe('graphiteDatasource', () => {
});
function accessScenario(name, url, fn) {
describe('access scenario ' + name, function() {
describe('access scenario ' + name, () => {
const ctx: any = {
backendSrv: {},
$q: $q,
@@ -332,12 +332,12 @@ function accessScenario(name, url, fn) {
});
}
accessScenario('with proxy access', '/api/datasources/proxy/1', function(httpOptions) {
accessScenario('with proxy access', '/api/datasources/proxy/1', httpOptions => {
expect(httpOptions.headers['X-Dashboard-Id']).toBe(1);
expect(httpOptions.headers['X-Panel-Id']).toBe(2);
});
accessScenario('with direct access', 'http://localhost:8080', function(httpOptions) {
accessScenario('with direct access', 'http://localhost:8080', httpOptions => {
expect(httpOptions.headers['X-Dashboard-Id']).toBe(undefined);
expect(httpOptions.headers['X-Panel-Id']).toBe(undefined);
});

View File

@@ -1,7 +1,7 @@
import gfunc from '../gfunc';
describe('when creating func instance from func names', function() {
it('should return func instance', function() {
describe('when creating func instance from func names', () => {
it('should return func instance', () => {
const func = gfunc.createFuncInstance('sumSeries');
expect(func).toBeTruthy();
expect(func.def.name).toEqual('sumSeries');
@@ -10,18 +10,18 @@ describe('when creating func instance from func names', function() {
expect(func.def.defaultParams.length).toEqual(1);
});
it('should return func instance with shortName', function() {
it('should return func instance with shortName', () => {
const func = gfunc.createFuncInstance('sum');
expect(func).toBeTruthy();
});
it('should return func instance from funcDef', function() {
it('should return func instance from funcDef', () => {
const func = gfunc.createFuncInstance('sum');
const func2 = gfunc.createFuncInstance(func.def);
expect(func2).toBeTruthy();
});
it('func instance should have text representation', function() {
it('func instance should have text representation', () => {
const func = gfunc.createFuncInstance('groupByNode');
func.params[0] = 5;
func.params[1] = 'avg';
@@ -30,78 +30,78 @@ describe('when creating func instance from func names', function() {
});
});
describe('when rendering func instance', function() {
it('should handle single metric param', function() {
describe('when rendering func instance', () => {
it('should handle single metric param', () => {
const func = gfunc.createFuncInstance('sumSeries');
expect(func.render('hello.metric')).toEqual('sumSeries(hello.metric)');
});
it('should include default params if options enable it', function() {
it('should include default params if options enable it', () => {
const func = gfunc.createFuncInstance('scaleToSeconds', {
withDefaultParams: true,
});
expect(func.render('hello')).toEqual('scaleToSeconds(hello, 1)');
});
it('should handle int or interval params with number', function() {
it('should handle int or interval params with number', () => {
const func = gfunc.createFuncInstance('movingMedian');
func.params[0] = '5';
expect(func.render('hello')).toEqual('movingMedian(hello, 5)');
});
it('should handle int or interval params with interval string', function() {
it('should handle int or interval params with interval string', () => {
const func = gfunc.createFuncInstance('movingMedian');
func.params[0] = '5min';
expect(func.render('hello')).toEqual("movingMedian(hello, '5min')");
});
it('should never quote boolean paramater', function() {
it('should never quote boolean paramater', () => {
const func = gfunc.createFuncInstance('sortByName');
func.params[0] = '$natural';
expect(func.render('hello')).toEqual('sortByName(hello, $natural)');
});
it('should never quote int paramater', function() {
it('should never quote int paramater', () => {
const func = gfunc.createFuncInstance('maximumAbove');
func.params[0] = '$value';
expect(func.render('hello')).toEqual('maximumAbove(hello, $value)');
});
it('should never quote node paramater', function() {
it('should never quote node paramater', () => {
const func = gfunc.createFuncInstance('aliasByNode');
func.params[0] = '$node';
expect(func.render('hello')).toEqual('aliasByNode(hello, $node)');
});
it('should handle metric param and int param and string param', function() {
it('should handle metric param and int param and string param', () => {
const func = gfunc.createFuncInstance('groupByNode');
func.params[0] = 5;
func.params[1] = 'avg';
expect(func.render('hello.metric')).toEqual("groupByNode(hello.metric, 5, 'avg')");
});
it('should handle function with no metric param', function() {
it('should handle function with no metric param', () => {
const func = gfunc.createFuncInstance('randomWalk');
func.params[0] = 'test';
expect(func.render(undefined)).toEqual("randomWalk('test')");
});
it('should handle function multiple series params', function() {
it('should handle function multiple series params', () => {
const func = gfunc.createFuncInstance('asPercent');
func.params[0] = '#B';
expect(func.render('#A')).toEqual('asPercent(#A, #B)');
});
});
describe('when requesting function definitions', function() {
it('should return function definitions', function() {
describe('when requesting function definitions', () => {
it('should return function definitions', () => {
const funcIndex = gfunc.getFuncDefs('1.0');
expect(Object.keys(funcIndex).length).toBeGreaterThan(8);
});
});
describe('when updating func param', function() {
it('should update param value and update text representation', function() {
describe('when updating func param', () => {
it('should update param value and update text representation', () => {
const func = gfunc.createFuncInstance('summarize', {
withDefaultParams: true,
});
@@ -110,21 +110,21 @@ describe('when updating func param', function() {
expect(func.text).toBe('summarize(1h, sum, false)');
});
it('should parse numbers as float', function() {
it('should parse numbers as float', () => {
const func = gfunc.createFuncInstance('scale');
func.updateParam('0.001', 0);
expect(func.params[0]).toBe('0.001');
});
});
describe('when updating func param with optional second parameter', function() {
it('should update value and text', function() {
describe('when updating func param with optional second parameter', () => {
it('should update value and text', () => {
const func = gfunc.createFuncInstance('aliasByNode');
func.updateParam('1', 0);
expect(func.params[0]).toBe('1');
});
it('should slit text and put value in second param', function() {
it('should slit text and put value in second param', () => {
const func = gfunc.createFuncInstance('aliasByNode');
func.updateParam('4,-5', 0);
expect(func.params[0]).toBe('4');
@@ -132,7 +132,7 @@ describe('when updating func param with optional second parameter', function() {
expect(func.text).toBe('aliasByNode(4, -5)');
});
it('should remove second param when empty string is set', function() {
it('should remove second param when empty string is set', () => {
const func = gfunc.createFuncInstance('aliasByNode');
func.updateParam('4,-5', 0);
func.updateParam('', 1);

View File

@@ -1,7 +1,7 @@
import { Lexer } from '../lexer';
describe('when lexing graphite expression', function() {
it('should tokenize metric expression', function() {
describe('when lexing graphite expression', () => {
it('should tokenize metric expression', () => {
const lexer = new Lexer('metric.test.*.asd.count');
const tokens = lexer.tokenize();
expect(tokens[0].value).toBe('metric');
@@ -11,27 +11,27 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].pos).toBe(13);
});
it('should tokenize metric expression with dash', function() {
it('should tokenize metric expression with dash', () => {
const lexer = new Lexer('metric.test.se1-server-*.asd.count');
const tokens = lexer.tokenize();
expect(tokens[4].type).toBe('identifier');
expect(tokens[4].value).toBe('se1-server-*');
});
it('should tokenize metric expression with dash2', function() {
it('should tokenize metric expression with dash2', () => {
const lexer = new Lexer('net.192-168-1-1.192-168-1-9.ping_value.*');
const tokens = lexer.tokenize();
expect(tokens[0].value).toBe('net');
expect(tokens[2].value).toBe('192-168-1-1');
});
it('should tokenize metric expression with equal sign', function() {
it('should tokenize metric expression with equal sign', () => {
const lexer = new Lexer('apps=test');
const tokens = lexer.tokenize();
expect(tokens[0].value).toBe('apps=test');
});
it('simple function2', function() {
it('simple function2', () => {
const lexer = new Lexer('offset(test.metric, -100)');
const tokens = lexer.tokenize();
expect(tokens[2].type).toBe('identifier');
@@ -39,7 +39,7 @@ describe('when lexing graphite expression', function() {
expect(tokens[6].type).toBe('number');
});
it('should tokenize metric expression with curly braces', function() {
it('should tokenize metric expression with curly braces', () => {
const lexer = new Lexer('metric.se1-{first, second}.count');
const tokens = lexer.tokenize();
expect(tokens.length).toBe(10);
@@ -49,7 +49,7 @@ describe('when lexing graphite expression', function() {
expect(tokens[6].value).toBe('second');
});
it('should tokenize metric expression with number segments', function() {
it('should tokenize metric expression with number segments', () => {
const lexer = new Lexer('metric.10.12_10.test');
const tokens = lexer.tokenize();
expect(tokens[0].type).toBe('identifier');
@@ -59,7 +59,7 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].type).toBe('identifier');
});
it('should tokenize metric expression with segment that start with number', function() {
it('should tokenize metric expression with segment that start with number', () => {
const lexer = new Lexer('metric.001-server');
const tokens = lexer.tokenize();
expect(tokens[0].type).toBe('identifier');
@@ -67,7 +67,7 @@ describe('when lexing graphite expression', function() {
expect(tokens.length).toBe(3);
});
it('should tokenize func call with numbered metric and number arg', function() {
it('should tokenize func call with numbered metric and number arg', () => {
const lexer = new Lexer('scale(metric.10, 15)');
const tokens = lexer.tokenize();
expect(tokens[0].type).toBe('identifier');
@@ -78,7 +78,7 @@ describe('when lexing graphite expression', function() {
expect(tokens[6].type).toBe('number');
});
it('should tokenize metric with template parameter', function() {
it('should tokenize metric with template parameter', () => {
const lexer = new Lexer('metric.[[server]].test');
const tokens = lexer.tokenize();
expect(tokens[2].type).toBe('identifier');
@@ -86,7 +86,7 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].type).toBe('identifier');
});
it('should tokenize metric with question mark', function() {
it('should tokenize metric with question mark', () => {
const lexer = new Lexer('metric.server_??.test');
const tokens = lexer.tokenize();
expect(tokens[2].type).toBe('identifier');
@@ -94,7 +94,7 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].type).toBe('identifier');
});
it('should handle error with unterminated string', function() {
it('should handle error with unterminated string', () => {
const lexer = new Lexer("alias(metric, 'asd)");
const tokens = lexer.tokenize();
expect(tokens[0].value).toBe('alias');
@@ -106,14 +106,14 @@ describe('when lexing graphite expression', function() {
expect(tokens[4].pos).toBe(20);
});
it('should handle float parameters', function() {
it('should handle float parameters', () => {
const lexer = new Lexer('alias(metric, 0.002)');
const tokens = lexer.tokenize();
expect(tokens[4].type).toBe('number');
expect(tokens[4].value).toBe('0.002');
});
it('should handle bool parameters', function() {
it('should handle bool parameters', () => {
const lexer = new Lexer('alias(metric, true, false)');
const tokens = lexer.tokenize();
expect(tokens[4].type).toBe('bool');

View File

@@ -1,7 +1,7 @@
import { Parser } from '../parser';
describe('when parsing', function() {
it('simple metric expression', function() {
describe('when parsing', () => {
it('simple metric expression', () => {
const parser = new Parser('metric.test.*.asd.count');
const rootNode = parser.getAst();
@@ -10,7 +10,7 @@ describe('when parsing', function() {
expect(rootNode.segments[0].value).toBe('metric');
});
it('simple metric expression with numbers in segments', function() {
it('simple metric expression with numbers in segments', () => {
const parser = new Parser('metric.10.15_20.5');
const rootNode = parser.getAst();
@@ -21,7 +21,7 @@ describe('when parsing', function() {
expect(rootNode.segments[3].value).toBe('5');
});
it('simple metric expression with curly braces', function() {
it('simple metric expression with curly braces', () => {
const parser = new Parser('metric.se1-{count, max}');
const rootNode = parser.getAst();
@@ -30,7 +30,7 @@ describe('when parsing', function() {
expect(rootNode.segments[1].value).toBe('se1-{count,max}');
});
it('simple metric expression with curly braces at start of segment and with post chars', function() {
it('simple metric expression with curly braces at start of segment and with post chars', () => {
const parser = new Parser('metric.{count, max}-something.count');
const rootNode = parser.getAst();
@@ -39,14 +39,14 @@ describe('when parsing', function() {
expect(rootNode.segments[1].value).toBe('{count,max}-something');
});
it('simple function', function() {
it('simple function', () => {
const parser = new Parser('sum(test)');
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
expect(rootNode.params.length).toBe(1);
});
it('simple function2', function() {
it('simple function2', () => {
const parser = new Parser('offset(test.metric, -100)');
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
@@ -54,7 +54,7 @@ describe('when parsing', function() {
expect(rootNode.params[1].type).toBe('number');
});
it('simple function with string arg', function() {
it('simple function with string arg', () => {
const parser = new Parser("randomWalk('test')");
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
@@ -62,7 +62,7 @@ describe('when parsing', function() {
expect(rootNode.params[0].type).toBe('string');
});
it('function with multiple args', function() {
it('function with multiple args', () => {
const parser = new Parser("sum(test, 1, 'test')");
const rootNode = parser.getAst();
@@ -73,7 +73,7 @@ describe('when parsing', function() {
expect(rootNode.params[2].type).toBe('string');
});
it('function with nested function', function() {
it('function with nested function', () => {
const parser = new Parser('sum(scaleToSeconds(test, 1))');
const rootNode = parser.getAst();
@@ -86,7 +86,7 @@ describe('when parsing', function() {
expect(rootNode.params[0].params[1].type).toBe('number');
});
it('function with multiple series', function() {
it('function with multiple series', () => {
const parser = new Parser('sum(test.test.*.count, test.timers.*.count)');
const rootNode = parser.getAst();
@@ -96,7 +96,7 @@ describe('when parsing', function() {
expect(rootNode.params[1].type).toBe('metric');
});
it('function with templated series', function() {
it('function with templated series', () => {
const parser = new Parser('sum(test.[[server]].count)');
const rootNode = parser.getAst();
@@ -106,7 +106,7 @@ describe('when parsing', function() {
expect(rootNode.params[0].segments[1].value).toBe('[[server]]');
});
it('invalid metric expression', function() {
it('invalid metric expression', () => {
const parser = new Parser('metric.test.*.asd.');
const rootNode = parser.getAst();
@@ -114,7 +114,7 @@ describe('when parsing', function() {
expect(rootNode.pos).toBe(19);
});
it('invalid function expression missing closing parenthesis', function() {
it('invalid function expression missing closing parenthesis', () => {
const parser = new Parser('sum(test');
const rootNode = parser.getAst();
@@ -122,7 +122,7 @@ describe('when parsing', function() {
expect(rootNode.pos).toBe(9);
});
it('unclosed string in function', function() {
it('unclosed string in function', () => {
const parser = new Parser("sum('test)");
const rootNode = parser.getAst();
@@ -130,13 +130,13 @@ describe('when parsing', function() {
expect(rootNode.pos).toBe(11);
});
it('handle issue #69', function() {
it('handle issue #69', () => {
const parser = new Parser('cactiStyle(offset(scale(net.192-168-1-1.192-168-1-9.ping_value.*,0.001),-100))');
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
});
it('handle float function arguments', function() {
it('handle float function arguments', () => {
const parser = new Parser('scale(test, 0.002)');
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
@@ -144,7 +144,7 @@ describe('when parsing', function() {
expect(rootNode.params[1].value).toBe(0.002);
});
it('handle curly brace pattern at start', function() {
it('handle curly brace pattern at start', () => {
const parser = new Parser('{apps}.test');
const rootNode = parser.getAst();
expect(rootNode.type).toBe('metric');
@@ -152,7 +152,7 @@ describe('when parsing', function() {
expect(rootNode.segments[1].value).toBe('test');
});
it('series parameters', function() {
it('series parameters', () => {
const parser = new Parser('asPercent(#A, #B)');
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
@@ -161,7 +161,7 @@ describe('when parsing', function() {
expect(rootNode.params[1].value).toBe('#B');
});
it('series parameters, issue 2788', function() {
it('series parameters, issue 2788', () => {
const parser = new Parser("summarize(diffSeries(#A, #B), '10m', 'sum', false)");
const rootNode = parser.getAst();
expect(rootNode.type).toBe('function');
@@ -170,7 +170,7 @@ describe('when parsing', function() {
expect(rootNode.params[3].type).toBe('bool');
});
it('should parse metric expression with ip number segments', function() {
it('should parse metric expression with ip number segments', () => {
const parser = new Parser('5.10.123.5');
const rootNode = parser.getAst();
expect(rootNode.segments[0].value).toBe('5');

View File

@@ -137,7 +137,7 @@ describe('GraphiteQueryCtrl', () => {
ctx.ctrl.target.target = 'test.count';
ctx.ctrl.datasource.metricFindQuery = () => Promise.resolve([]);
ctx.ctrl.parseTarget();
ctx.ctrl.getAltSegments(1).then(function(results) {
ctx.ctrl.getAltSegments(1).then(results => {
ctx.altSegments = results;
});
});