mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #15950 from grafana/typescript-any-part2
Fixed more typescript no implicit any issues
This commit is contained in:
commit
54f92514d5
@ -123,6 +123,7 @@ export function ServiceTestContext(this: any) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.createService = name => {
|
this.createService = name => {
|
||||||
|
// @ts-ignore
|
||||||
return angularMocks.inject(($q, $rootScope, $httpBackend, $injector, $location, $timeout) => {
|
return angularMocks.inject(($q, $rootScope, $httpBackend, $injector, $location, $timeout) => {
|
||||||
self.$q = $q;
|
self.$q = $q;
|
||||||
self.$rootScope = $rootScope;
|
self.$rootScope = $rootScope;
|
||||||
@ -145,7 +146,7 @@ export function DashboardViewStateStub(this: any) {
|
|||||||
export function TimeSrvStub(this: any) {
|
export function TimeSrvStub(this: any) {
|
||||||
this.init = () => {};
|
this.init = () => {};
|
||||||
this.time = { from: 'now-1h', to: 'now' };
|
this.time = { from: 'now-1h', to: 'now' };
|
||||||
this.timeRange = function(parse) {
|
this.timeRange = function(parse: boolean) {
|
||||||
if (parse === false) {
|
if (parse === false) {
|
||||||
return this.time;
|
return this.time;
|
||||||
}
|
}
|
||||||
@ -155,11 +156,7 @@ export function TimeSrvStub(this: any) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.replace = target => {
|
this.setTime = function(time: any) {
|
||||||
return target;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.setTime = function(time) {
|
|
||||||
this.time = time;
|
this.time = time;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -174,11 +171,11 @@ export function TemplateSrvStub(this: any) {
|
|||||||
this.variables = [];
|
this.variables = [];
|
||||||
this.templateSettings = { interpolate: /\[\[([\s\S]+?)\]\]/g };
|
this.templateSettings = { interpolate: /\[\[([\s\S]+?)\]\]/g };
|
||||||
this.data = {};
|
this.data = {};
|
||||||
this.replace = function(text) {
|
this.replace = function(text: string) {
|
||||||
return _.template(text, this.templateSettings)(this.data);
|
return _.template(text, this.templateSettings)(this.data);
|
||||||
};
|
};
|
||||||
this.init = () => {};
|
this.init = () => {};
|
||||||
this.getAdhocFilters = () => {
|
this.getAdhocFilters = (): any => {
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
this.fillVariableValuesForUrl = () => {};
|
this.fillVariableValuesForUrl = () => {};
|
||||||
@ -187,10 +184,10 @@ export function TemplateSrvStub(this: any) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
this.variableInitialized = () => {};
|
this.variableInitialized = () => {};
|
||||||
this.highlightVariablesAsHtml = str => {
|
this.highlightVariablesAsHtml = (str: string) => {
|
||||||
return str;
|
return str;
|
||||||
};
|
};
|
||||||
this.setGrafanaVariable = function(name, value) {
|
this.setGrafanaVariable = function(name: string, value: string) {
|
||||||
this.data[name] = value;
|
this.data[name] = value;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
52
public/vendor/ansicolor/ansicolor.ts
vendored
52
public/vendor/ansicolor/ansicolor.ts
vendored
@ -48,7 +48,7 @@ const colorCodes = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan'
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
const clean = obj => {
|
const clean = (obj: any) => {
|
||||||
for (const k in obj) {
|
for (const k in obj) {
|
||||||
if (!obj[k]) {
|
if (!obj[k]) {
|
||||||
delete obj[k];
|
delete obj[k];
|
||||||
@ -60,11 +60,11 @@ const clean = obj => {
|
|||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
class Color {
|
class Color {
|
||||||
background: string;
|
background: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
brightness: number;
|
brightness: number;
|
||||||
|
|
||||||
constructor(background?, name?, brightness?) {
|
constructor(background?: boolean, name?: string, brightness?: number) {
|
||||||
this.background = background;
|
this.background = background;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.brightness = brightness;
|
this.brightness = brightness;
|
||||||
@ -82,18 +82,21 @@ class Color {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultBrightness(value) {
|
defaultBrightness(value: number) {
|
||||||
return new Color(this.background, this.name, this.brightness || value);
|
return new Color(this.background, this.name, this.brightness || value);
|
||||||
}
|
}
|
||||||
|
|
||||||
css(inverted) {
|
css(inverted: boolean) {
|
||||||
const color = inverted ? this.inverse : this;
|
const color = inverted ? this.inverse : this;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const rgbName = (color.brightness === Code.bright && asBright[color.name]) || color.name;
|
const rgbName = (color.brightness === Code.bright && asBright[color.name]) || color.name;
|
||||||
|
|
||||||
const prop = color.background ? 'background:' : 'color:',
|
const prop = color.background ? 'background:' : 'color:';
|
||||||
rgb = Colors.rgb[rgbName],
|
|
||||||
alpha = this.brightness === Code.dim ? 0.5 : 1;
|
// @ts-ignore
|
||||||
|
const rgb = Colors.rgb[rgbName];
|
||||||
|
const alpha = this.brightness === Code.dim ? 0.5 : 1;
|
||||||
|
|
||||||
return rgb
|
return rgb
|
||||||
? prop + 'rgba(' + [...rgb, alpha].join(',') + ');'
|
? prop + 'rgba(' + [...rgb, alpha].join(',') + ');'
|
||||||
@ -117,17 +120,19 @@ class Code {
|
|||||||
|
|
||||||
value: number;
|
value: number;
|
||||||
|
|
||||||
constructor(n?) {
|
constructor(n?: string | number) {
|
||||||
if (n !== undefined) {
|
if (n !== undefined) {
|
||||||
this.value = Number(n);
|
this.value = Number(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get type() {
|
get type() {
|
||||||
|
// @ts-ignore
|
||||||
return types[Math.floor(this.value / 10)];
|
return types[Math.floor(this.value / 10)];
|
||||||
}
|
}
|
||||||
|
|
||||||
get subtype() {
|
get subtype() {
|
||||||
|
// @ts-ignore
|
||||||
return subtypes[this.type][this.value % 10];
|
return subtypes[this.type][this.value % 10];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +140,7 @@ class Code {
|
|||||||
return this.value ? '\u001b[' + this.value + 'm' : '';
|
return this.value ? '\u001b[' + this.value + 'm' : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
static str(x) {
|
static str(x: string | number) {
|
||||||
return new Code(x).str;
|
return new Code(x).str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,16 +151,17 @@ class Code {
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
const replaceAll = (str, a, b) => str.split(a).join(b);
|
const replaceAll = (str: string, a: string, b: string) => str.split(a).join(b);
|
||||||
|
|
||||||
/* ANSI brightness codes do not overlap, e.g. "{bright}{dim}foo" will be rendered bright (not dim).
|
/* ANSI brightness codes do not overlap, e.g. "{bright}{dim}foo" will be rendered bright (not dim).
|
||||||
So we fix it by adding brightness canceling before each brightness code, so the former example gets
|
So we fix it by adding brightness canceling before each brightness code, so the former example gets
|
||||||
converted to "{noBrightness}{bright}{noBrightness}{dim}foo" – this way it gets rendered as expected.
|
converted to "{noBrightness}{bright}{noBrightness}{dim}foo" – this way it gets rendered as expected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const denormalizeBrightness = s => s.replace(/(\u001b\[(1|2)m)/g, '\u001b[22m$1');
|
const denormalizeBrightness = (s: string) => s.replace(/(\u001b\[(1|2)m)/g, '\u001b[22m$1');
|
||||||
const normalizeBrightness = s => s.replace(/\u001b\[22m(\u001b\[(1|2)m)/g, '$1');
|
const normalizeBrightness = (s: string) => s.replace(/\u001b\[22m(\u001b\[(1|2)m)/g, '$1');
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const wrap = (x, openCode, closeCode) => {
|
const wrap = (x, openCode, closeCode) => {
|
||||||
const open = Code.str(openCode),
|
const open = Code.str(openCode),
|
||||||
close = Code.str(closeCode);
|
close = Code.str(closeCode);
|
||||||
@ -168,7 +174,7 @@ const wrap = (x, openCode, closeCode) => {
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
const camel = (a, b) => a + b.charAt(0).toUpperCase() + b.slice(1);
|
const camel = (a: string, b: string) => a + b.charAt(0).toUpperCase() + b.slice(1);
|
||||||
|
|
||||||
const stringWrappingMethods = (() =>
|
const stringWrappingMethods = (() =>
|
||||||
[
|
[
|
||||||
@ -216,10 +222,12 @@ const stringWrappingMethods = (() =>
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const assignStringWrappingAPI = (target, wrapBefore = target) =>
|
const assignStringWrappingAPI = (target, wrapBefore = target) =>
|
||||||
stringWrappingMethods.reduce(
|
stringWrappingMethods.reduce(
|
||||||
(memo, [k, open, close]) =>
|
(memo, [k, open, close]) =>
|
||||||
O.defineProperty(memo, k, {
|
O.defineProperty(memo, k, {
|
||||||
|
// @ts-ignore
|
||||||
get: () => assignStringWrappingAPI(str => wrapBefore(wrap(str, open, close))),
|
get: () => assignStringWrappingAPI(str => wrapBefore(wrap(str, open, close))),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -232,7 +240,7 @@ const TEXT = 0,
|
|||||||
BRACKET = 1,
|
BRACKET = 1,
|
||||||
CODE = 2;
|
CODE = 2;
|
||||||
|
|
||||||
function rawParse(s) {
|
function rawParse(s: string) {
|
||||||
let state = TEXT,
|
let state = TEXT,
|
||||||
buffer = '',
|
buffer = '',
|
||||||
text = '',
|
text = '',
|
||||||
@ -333,7 +341,7 @@ export default class Colors {
|
|||||||
/**
|
/**
|
||||||
* @param {string} s a string containing ANSI escape codes.
|
* @param {string} s a string containing ANSI escape codes.
|
||||||
*/
|
*/
|
||||||
constructor(s?) {
|
constructor(s?: string) {
|
||||||
this.spans = s ? rawParse(s) : [];
|
this.spans = s ? rawParse(s) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +350,10 @@ export default class Colors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get parsed() {
|
get parsed() {
|
||||||
let color, bgColor, brightness, styles;
|
let styles: Set<string>;
|
||||||
|
let brightness: number;
|
||||||
|
let color: Color;
|
||||||
|
let bgColor: Color;
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
(color = new Color()),
|
(color = new Color()),
|
||||||
@ -431,6 +442,7 @@ export default class Colors {
|
|||||||
if (!(k in String.prototype)) {
|
if (!(k in String.prototype)) {
|
||||||
O.defineProperty(String.prototype, k, {
|
O.defineProperty(String.prototype, k, {
|
||||||
get: function() {
|
get: function() {
|
||||||
|
// @ts-ignore
|
||||||
return Colors[k](this);
|
return Colors[k](this);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -444,7 +456,7 @@ export default class Colors {
|
|||||||
* @desc parses a string containing ANSI escape codes
|
* @desc parses a string containing ANSI escape codes
|
||||||
* @return {Colors} parsed representation.
|
* @return {Colors} parsed representation.
|
||||||
*/
|
*/
|
||||||
static parse(s) {
|
static parse(s: string) {
|
||||||
return new Colors(s).parsed;
|
return new Colors(s).parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +465,7 @@ export default class Colors {
|
|||||||
* @param {string} s a string containing ANSI escape codes.
|
* @param {string} s a string containing ANSI escape codes.
|
||||||
* @return {string} clean string.
|
* @return {string} clean string.
|
||||||
*/
|
*/
|
||||||
static strip(s) {
|
static strip(s: string) {
|
||||||
return s.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]/g, ''); // hope V8 caches the regexp
|
return s.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-PRZcf-nqry=><]/g, ''); // hope V8 caches the regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,4 +480,4 @@ export default class Colors {
|
|||||||
|
|
||||||
/* ------------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------------ */
|
||||||
|
|
||||||
assignStringWrappingAPI(Colors, str => str);
|
assignStringWrappingAPI(Colors, (str: string) => str);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
"noImplicitThis": true,
|
"noImplicitThis": true,
|
||||||
"noImplicitUseStrict": false,
|
"noImplicitUseStrict": false,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
|
"downlevelIteration": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"baseUrl": "public",
|
"baseUrl": "public",
|
||||||
"pretty": true,
|
"pretty": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user