From 80d6ef535de0cb2db02651b570bebad1b45a3152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 30 Aug 2018 08:53:13 +0200 Subject: [PATCH] tsconfig: started on setting noImplicitThis to true --- .../app/containers/Explore/utils/debounce.ts | 2 +- .../app/plugins/datasource/graphite/lexer.ts | 8 +-- .../app/plugins/datasource/graphite/parser.ts | 2 +- .../plugins/datasource/opentsdb/datasource.ts | 52 +++++++------------ .../app/plugins/panel/graph/graph_tooltip.ts | 2 +- .../plugins/panel/graph/jquery.flot.events.ts | 6 +-- public/app/stores/TeamsStore/TeamsStore.ts | 4 +- public/test/specs/helpers.ts | 12 ++--- tsconfig.json | 2 +- 9 files changed, 38 insertions(+), 52 deletions(-) diff --git a/public/app/containers/Explore/utils/debounce.ts b/public/app/containers/Explore/utils/debounce.ts index 9f2bd35e116a1..5fda5a05f5f16 100644 --- a/public/app/containers/Explore/utils/debounce.ts +++ b/public/app/containers/Explore/utils/debounce.ts @@ -1,7 +1,7 @@ // Based on underscore.js debounce() export default function debounce(func, wait) { let timeout; - return function() { + return function(this: any) { const context = this; const args = arguments; const later = function() { diff --git a/public/app/plugins/datasource/graphite/lexer.ts b/public/app/plugins/datasource/graphite/lexer.ts index 2ed85026bca91..df68e1166fd3c 100644 --- a/public/app/plugins/datasource/graphite/lexer.ts +++ b/public/app/plugins/datasource/graphite/lexer.ts @@ -922,7 +922,7 @@ for (var i = 0; i < 128; i++) { const identifierPartTable = identifierStartTable; -export function Lexer(expression) { +export function Lexer(this: any, expression) { this.input = expression; this.char = 1; this.from = 1; @@ -1037,7 +1037,7 @@ Lexer.prototype = { return /^[0-9a-fA-F]$/.test(str); } - const readUnicodeEscapeSequence = _.bind(function() { + const readUnicodeEscapeSequence = _.bind(function(this: any) { /*jshint validthis:true */ index += 1; @@ -1065,7 +1065,7 @@ Lexer.prototype = { return null; }, this); - const getIdentifierStart = _.bind(function() { + const getIdentifierStart = _.bind(function(this: any) { /*jshint validthis:true */ const chr = this.peek(index); const code = chr.charCodeAt(0); @@ -1096,7 +1096,7 @@ Lexer.prototype = { return null; }, this); - const getIdentifierPart = _.bind(function() { + const getIdentifierPart = _.bind(function(this: any) { /*jshint validthis:true */ const chr = this.peek(index); const code = chr.charCodeAt(0); diff --git a/public/app/plugins/datasource/graphite/parser.ts b/public/app/plugins/datasource/graphite/parser.ts index 158fa94b6a624..aeb5cb65ee82d 100644 --- a/public/app/plugins/datasource/graphite/parser.ts +++ b/public/app/plugins/datasource/graphite/parser.ts @@ -1,6 +1,6 @@ import { Lexer } from './lexer'; -export function Parser(expression) { +export function Parser(this: any, expression) { this.expression = expression; this.lexer = new Lexer(expression); this.tokens = this.lexer.tokenize(); diff --git a/public/app/plugins/datasource/opentsdb/datasource.ts b/public/app/plugins/datasource/opentsdb/datasource.ts index 699c5f4dad39b..d3e16daae7416 100644 --- a/public/app/plugins/datasource/opentsdb/datasource.ts +++ b/public/app/plugins/datasource/opentsdb/datasource.ts @@ -39,15 +39,12 @@ export default class OpenTsDatasource { const end = this.convertToTSDBTime(options.rangeRaw.to, true); const qs = []; - _.each( - options.targets, - function(target) { - if (!target.metric) { - return; - } - qs.push(this.convertTargetToQuery(target, options, this.tsdbVersion)); - }.bind(this) - ); + _.each(options.targets, target => { + if (!target.metric) { + return; + } + qs.push(this.convertTargetToQuery(target, options, this.tsdbVersion)); + }); const queries = _.compact(qs); @@ -75,30 +72,19 @@ export default class OpenTsDatasource { return query.hide !== true; }); - return this.performTimeSeriesQuery(queries, start, end).then( - function(response) { - const metricToTargetMapping = this.mapMetricsToTargets(response.data, options, this.tsdbVersion); - const result = _.map( - response.data, - function(metricData, index) { - index = metricToTargetMapping[index]; - if (index === -1) { - index = 0; - } - this._saveTagKeys(metricData); - - return this.transformMetricData( - metricData, - groupByTags, - options.targets[index], - options, - this.tsdbResolution - ); - }.bind(this) - ); - return { data: result }; - }.bind(this) - ); + return this.performTimeSeriesQuery(queries, start, end).then(response => { + const metricToTargetMapping = this.mapMetricsToTargets(response.data, options, this.tsdbVersion); + const result = _.map(response.data, (metricData, index) => { + index = metricToTargetMapping[index]; + if (index === -1) { + index = 0; + } + this._saveTagKeys(metricData); + + return this.transformMetricData(metricData, groupByTags, options.targets[index], options, this.tsdbResolution); + }); + return { data: result }; + }); } annotationQuery(options) { diff --git a/public/app/plugins/panel/graph/graph_tooltip.ts b/public/app/plugins/panel/graph/graph_tooltip.ts index da2d25b136618..1c4b0fbe24fb9 100644 --- a/public/app/plugins/panel/graph/graph_tooltip.ts +++ b/public/app/plugins/panel/graph/graph_tooltip.ts @@ -1,7 +1,7 @@ import $ from 'jquery'; import { appEvents } from 'app/core/core'; -export default function GraphTooltip(elem, dashboard, scope, getSeriesFn) { +export default function GraphTooltip(this: any, elem, dashboard, scope, getSeriesFn) { const self = this; const ctrl = scope.ctrl; const panel = ctrl.panel; diff --git a/public/app/plugins/panel/graph/jquery.flot.events.ts b/public/app/plugins/panel/graph/jquery.flot.events.ts index 41c1468e343e2..f0600bdcd4050 100644 --- a/public/app/plugins/panel/graph/jquery.flot.events.ts +++ b/public/app/plugins/panel/graph/jquery.flot.events.ts @@ -420,7 +420,7 @@ export class EventMarkers { event: event, }); - const mouseenter = function() { + const mouseenter = function(this: any) { createAnnotationToolip(marker, $(this).data('event'), that._plot); }; @@ -541,7 +541,7 @@ export class EventMarkers { event: event, }); - const mouseenter = function() { + const mouseenter = function(this: any) { createAnnotationToolip(region, $(this).data('event'), that._plot); }; @@ -596,7 +596,7 @@ export class EventMarkers { */ /** @ngInject */ -export function init(plot) { +export function init(this: any, plot) { /*jshint validthis:true */ const that = this; const eventMarkers = new EventMarkers(plot); diff --git a/public/app/stores/TeamsStore/TeamsStore.ts b/public/app/stores/TeamsStore/TeamsStore.ts index f8e101163a21a..bc8af218deffc 100644 --- a/public/app/stores/TeamsStore/TeamsStore.ts +++ b/public/app/stores/TeamsStore/TeamsStore.ts @@ -31,7 +31,7 @@ export const TeamModel = types groups: types.optional(types.map(TeamGroupModel), {}), }) .views(self => ({ - get filteredMembers() { + get filteredMembers(this: Team) { const members = this.members.values(); const regex = new RegExp(self.search, 'i'); return members.filter(member => { @@ -121,7 +121,7 @@ export const TeamsStore = types search: types.optional(types.string, ''), }) .views(self => ({ - get filteredTeams() { + get filteredTeams(this: any) { const teams = this.map.values(); const regex = new RegExp(self.search, 'i'); return teams.filter(team => { diff --git a/public/test/specs/helpers.ts b/public/test/specs/helpers.ts index 960ce84f494b7..f585498d24756 100644 --- a/public/test/specs/helpers.ts +++ b/public/test/specs/helpers.ts @@ -4,7 +4,7 @@ import * as dateMath from 'app/core/utils/datemath'; import { angularMocks, sinon } from '../lib/common'; import { PanelModel } from 'app/features/dashboard/panel_model'; -export function ControllerTestContext() { +export function ControllerTestContext(this: any) { const self = this; this.datasource = {}; @@ -106,7 +106,7 @@ export function ControllerTestContext() { }; } -export function ServiceTestContext() { +export function ServiceTestContext(this: any) { const self = this; self.templateSrv = new TemplateSrvStub(); self.timeSrv = new TimeSrvStub(); @@ -138,11 +138,11 @@ export function ServiceTestContext() { }; } -export function DashboardViewStateStub() { +export function DashboardViewStateStub(this: any) { this.registerPanel = function() {}; } -export function TimeSrvStub() { +export function TimeSrvStub(this: any) { this.init = sinon.spy(); this.time = { from: 'now-1h', to: 'now' }; this.timeRange = function(parse) { @@ -164,13 +164,13 @@ export function TimeSrvStub() { }; } -export function ContextSrvStub() { +export function ContextSrvStub(this: any) { this.hasRole = function() { return true; }; } -export function TemplateSrvStub() { +export function TemplateSrvStub(this: any) { this.variables = []; this.templateSettings = { interpolate: /\[\[([\s\S]+?)\]\]/g }; this.data = {}; diff --git a/tsconfig.json b/tsconfig.json index 7a0274b2d79f5..58b29ba428e9a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ "emitDecoratorMetadata": false, "experimentalDecorators": true, "noImplicitReturns": true, - "noImplicitThis": false, + "noImplicitThis": true, "noImplicitUseStrict": false, "noImplicitAny": false, "noUnusedLocals": true,