Commit 25f13bd3 by Patrick O'Carroll Committed by Torkel Ödegaard

added only-arrow-functions rule and changed files to follow new rule (#13154)

parent 275f6130
...@@ -55,7 +55,7 @@ export function sqlPartEditorDirective($compile, templateSrv) { ...@@ -55,7 +55,7 @@ export function sqlPartEditorDirective($compile, templateSrv) {
} }
function inputBlur($input, paramIndex) { function inputBlur($input, paramIndex) {
cancelBlur = setTimeout(function() { cancelBlur = setTimeout(() => {
switchToLink($input, paramIndex); switchToLink($input, paramIndex);
}, 200); }, 200);
} }
...@@ -95,20 +95,20 @@ export function sqlPartEditorDirective($compile, templateSrv) { ...@@ -95,20 +95,20 @@ export function sqlPartEditorDirective($compile, templateSrv) {
return; return;
} }
const typeaheadSource = function(query, callback) { const typeaheadSource = (query, callback) => {
if (param.options) { if (param.options) {
let options = param.options; let options = param.options;
if (param.type === 'int') { if (param.type === 'int') {
options = _.map(options, function(val) { options = _.map(options, val => {
return val.toString(); return val.toString();
}); });
} }
return options; return options;
} }
$scope.$apply(function() { $scope.$apply(() => {
$scope.handleEvent({ $event: { name: 'get-param-options', param: param } }).then(function(result) { $scope.handleEvent({ $event: { name: 'get-param-options', param: param } }).then(result => {
const dynamicOptions = _.map(result, function(op) { const dynamicOptions = _.map(result, op => {
return op.value; return op.value;
}); });
...@@ -128,7 +128,7 @@ export function sqlPartEditorDirective($compile, templateSrv) { ...@@ -128,7 +128,7 @@ export function sqlPartEditorDirective($compile, templateSrv) {
source: typeaheadSource, source: typeaheadSource,
minLength: 0, minLength: 0,
items: 1000, items: 1000,
updater: function(value) { updater: value => {
if (value === part.params[paramIndex]) { if (value === part.params[paramIndex]) {
clearTimeout(cancelBlur); clearTimeout(cancelBlur);
$input.focus(); $input.focus();
...@@ -150,18 +150,18 @@ export function sqlPartEditorDirective($compile, templateSrv) { ...@@ -150,18 +150,18 @@ export function sqlPartEditorDirective($compile, templateSrv) {
} }
} }
$scope.showActionsMenu = function() { $scope.showActionsMenu = () => {
$scope.handleEvent({ $event: { name: 'get-part-actions' } }).then(res => { $scope.handleEvent({ $event: { name: 'get-part-actions' } }).then(res => {
$scope.partActions = res; $scope.partActions = res;
}); });
}; };
$scope.triggerPartAction = function(action) { $scope.triggerPartAction = action => {
$scope.handleEvent({ $event: { name: 'action', action: action } }); $scope.handleEvent({ $event: { name: 'action', action: action } });
}; };
function addElementsAndCompile() { function addElementsAndCompile() {
_.each(partDef.params, function(param, index) { _.each(partDef.params, (param, index) => {
if (param.optional && part.params.length <= index) { if (param.optional && part.params.length <= index) {
return; return;
} }
......
...@@ -14,8 +14,8 @@ export class Analytics { ...@@ -14,8 +14,8 @@ export class Analytics {
}); });
const ga = ((window as any).ga = const ga = ((window as any).ga =
(window as any).ga || (window as any).ga ||
//tslint:disable-next-line:only-arrow-functions
function() { function() {
//tslint:disable-line:only-arrow-functions
(ga.q = ga.q || []).push(arguments); (ga.q = ga.q || []).push(arguments);
}); });
ga.l = +new Date(); ga.l = +new Date();
......
...@@ -52,8 +52,8 @@ function applied(fn, scope) { ...@@ -52,8 +52,8 @@ function applied(fn, scope) {
if (fn.wrappedInApply) { if (fn.wrappedInApply) {
return fn; return fn;
} }
//tslint:disable-next-line:only-arrow-functions
const wrapped: any = function() { const wrapped: any = function() {
//tslint:disable-line:only-arrow-functions
const args = arguments; const args = arguments;
const phase = scope.$root.$$phase; const phase = scope.$root.$$phase;
if (phase === '$apply' || phase === '$digest') { if (phase === '$apply' || phase === '$digest') {
......
...@@ -96,7 +96,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -96,7 +96,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
} }
updateProjection() { updateProjection() {
this.selectParts = _.map(this.target.select, function(parts: any) { this.selectParts = _.map(this.target.select, (parts: any) => {
return _.map(parts, sqlPart.create).filter(n => n); return _.map(parts, sqlPart.create).filter(n => n);
}); });
this.whereParts = _.map(this.target.where, sqlPart.create).filter(n => n); this.whereParts = _.map(this.target.where, sqlPart.create).filter(n => n);
...@@ -104,15 +104,15 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -104,15 +104,15 @@ export class PostgresQueryCtrl extends QueryCtrl {
} }
updatePersistedParts() { updatePersistedParts() {
this.target.select = _.map(this.selectParts, function(selectParts) { this.target.select = _.map(this.selectParts, selectParts => {
return _.map(selectParts, function(part: any) { return _.map(selectParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, params: part.params }; return { type: part.def.type, datatype: part.datatype, params: part.params };
}); });
}); });
this.target.where = _.map(this.whereParts, function(part: any) { this.target.where = _.map(this.whereParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params }; return { type: part.def.type, datatype: part.datatype, name: part.name, params: part.params };
}); });
this.target.group = _.map(this.groupParts, function(part: any) { this.target.group = _.map(this.groupParts, (part: any) => {
return { type: part.def.type, datatype: part.datatype, params: part.params }; return { type: part.def.type, datatype: part.datatype, params: part.params };
}); });
} }
...@@ -355,7 +355,7 @@ export class PostgresQueryCtrl extends QueryCtrl { ...@@ -355,7 +355,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
switch (partType) { switch (partType) {
case 'column': case 'column':
const parts = _.map(selectParts, function(part: any) { const parts = _.map(selectParts, (part: any) => {
return sqlPart.create({ type: part.def.type, params: _.clone(part.params) }); return sqlPart.create({ type: part.def.type, params: _.clone(part.params) });
}); });
this.selectParts.push(parts); this.selectParts.push(parts);
......
import PostgresQuery from '../postgres_query'; import PostgresQuery from '../postgres_query';
describe('PostgresQuery', function() { describe('PostgresQuery', () => {
const templateSrv = { const templateSrv = {
replace: jest.fn(text => text), replace: jest.fn(text => text),
}; };
describe('When initializing', function() { describe('When initializing', () => {
it('should not be in SQL mode', function() { it('should not be in SQL mode', () => {
const query = new PostgresQuery({}, templateSrv); const query = new PostgresQuery({}, templateSrv);
expect(query.target.rawQuery).toBe(false); expect(query.target.rawQuery).toBe(false);
}); });
it('should be in SQL mode for pre query builder queries', function() { it('should be in SQL mode for pre query builder queries', () => {
const query = new PostgresQuery({ rawSql: 'SELECT 1' }, templateSrv); const query = new PostgresQuery({ rawSql: 'SELECT 1' }, templateSrv);
expect(query.target.rawQuery).toBe(true); expect(query.target.rawQuery).toBe(true);
}); });
}); });
describe('When generating time column SQL', function() { describe('When generating time column SQL', () => {
const query = new PostgresQuery({}, templateSrv); const query = new PostgresQuery({}, templateSrv);
query.target.timeColumn = 'time'; query.target.timeColumn = 'time';
...@@ -25,7 +25,7 @@ describe('PostgresQuery', function() { ...@@ -25,7 +25,7 @@ describe('PostgresQuery', function() {
expect(query.buildTimeColumn()).toBe('"time" AS "time"'); expect(query.buildTimeColumn()).toBe('"time" AS "time"');
}); });
describe('When generating time column SQL with group by time', function() { describe('When generating time column SQL with group by time', () => {
let query = new PostgresQuery( let query = new PostgresQuery(
{ timeColumn: 'time', group: [{ type: 'time', params: ['5m', 'none'] }] }, { timeColumn: 'time', group: [{ type: 'time', params: ['5m', 'none'] }] },
templateSrv templateSrv
...@@ -44,7 +44,7 @@ describe('PostgresQuery', function() { ...@@ -44,7 +44,7 @@ describe('PostgresQuery', function() {
expect(query.buildTimeColumn(false)).toBe('$__unixEpochGroup(time,5m)'); expect(query.buildTimeColumn(false)).toBe('$__unixEpochGroup(time,5m)');
}); });
describe('When generating metric column SQL', function() { describe('When generating metric column SQL', () => {
const query = new PostgresQuery({}, templateSrv); const query = new PostgresQuery({}, templateSrv);
query.target.metricColumn = 'host'; query.target.metricColumn = 'host';
...@@ -53,7 +53,7 @@ describe('PostgresQuery', function() { ...@@ -53,7 +53,7 @@ describe('PostgresQuery', function() {
expect(query.buildMetricColumn()).toBe('"host" AS metric'); expect(query.buildMetricColumn()).toBe('"host" AS metric');
}); });
describe('When generating value column SQL', function() { describe('When generating value column SQL', () => {
const query = new PostgresQuery({}, templateSrv); const query = new PostgresQuery({}, templateSrv);
let column = [{ type: 'column', params: ['value'] }]; let column = [{ type: 'column', params: ['value'] }];
...@@ -76,7 +76,7 @@ describe('PostgresQuery', function() { ...@@ -76,7 +76,7 @@ describe('PostgresQuery', function() {
); );
}); });
describe('When generating value column SQL with metric column', function() { describe('When generating value column SQL with metric column', () => {
const query = new PostgresQuery({}, templateSrv); const query = new PostgresQuery({}, templateSrv);
query.target.metricColumn = 'host'; query.target.metricColumn = 'host';
...@@ -110,7 +110,7 @@ describe('PostgresQuery', function() { ...@@ -110,7 +110,7 @@ describe('PostgresQuery', function() {
); );
}); });
describe('When generating WHERE clause', function() { describe('When generating WHERE clause', () => {
const query = new PostgresQuery({ where: [] }, templateSrv); const query = new PostgresQuery({ where: [] }, templateSrv);
expect(query.buildWhereClause()).toBe(''); expect(query.buildWhereClause()).toBe('');
...@@ -126,7 +126,7 @@ describe('PostgresQuery', function() { ...@@ -126,7 +126,7 @@ describe('PostgresQuery', function() {
expect(query.buildWhereClause()).toBe('\nWHERE\n $__timeFilter(t) AND\n v = 1'); expect(query.buildWhereClause()).toBe('\nWHERE\n $__timeFilter(t) AND\n v = 1');
}); });
describe('When generating GROUP BY clause', function() { describe('When generating GROUP BY clause', () => {
const query = new PostgresQuery({ group: [], metricColumn: 'none' }, templateSrv); const query = new PostgresQuery({ group: [], metricColumn: 'none' }, templateSrv);
expect(query.buildGroupClause()).toBe(''); expect(query.buildGroupClause()).toBe('');
...@@ -136,7 +136,7 @@ describe('PostgresQuery', function() { ...@@ -136,7 +136,7 @@ describe('PostgresQuery', function() {
expect(query.buildGroupClause()).toBe('\nGROUP BY 1,2'); expect(query.buildGroupClause()).toBe('\nGROUP BY 1,2');
}); });
describe('When generating complete statement', function() { describe('When generating complete statement', () => {
const target = { const target = {
timeColumn: 't', timeColumn: 't',
table: 'table', table: 'table',
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
"no-var-keyword": true, "no-var-keyword": true,
"object-literal-sort-keys": false, "object-literal-sort-keys": false,
"one-line": [true, "check-open-brace", "check-catch", "check-else"], "one-line": [true, "check-open-brace", "check-catch", "check-else"],
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"],
"prefer-const": true, "prefer-const": true,
"radix": false, "radix": false,
"typedef-whitespace": [ "typedef-whitespace": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment