Skip to content

Commit 658e17b

Browse files
committed
fix(apps): resolve the lint errors that autofix leaves in the test apps
- no-var on exported and early-referenced declarations (ESLint never autofixes these): var -> let, then prefer-const autofix. References that precede a declaration are all inside test functions or callbacks that cannot run before it. - application-tests.ios.ts: declare the observer before the if-block it was assigned in. - xml-parser-tests.ts: give the two case clauses that declared variables their own block. - repeater-tests.ts: the date converter read month before declaring it when padding the day; pad on day, as the list-view copy does. - file-system-tests.ts and globals.d.ts keep var, with a reason. - prefer-const on `let x; ... x = v;`: declare at the assignment. - prefer-as-const: apply the rule's suggestion. - no-constant-binary-expression, no-unused-expressions, prefer-spread: assert(true), drop a bare ModuleNameResolver statement, spread instead of Array.apply.
1 parent 3b5ddc8 commit 658e17b

41 files changed

Lines changed: 447 additions & 479 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/automated/src/application-settings/application-settings-tests.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const noStringKey: string = 'noStringKey';
88
const noBoolKey: string = 'noBoolKey';
99
const noNumberKey: string = 'noNumberKey';
1010

11-
export var testBoolean = function () {
11+
export const testBoolean = function () {
1212
appSettings.setBoolean(boolKey, false);
1313
const boolValueBefore = appSettings.getBoolean(boolKey);
1414
TKUnit.assert(false === boolValueBefore, 'Cannot set boolean to false, currently it is: ' + appSettings.getBoolean(boolKey));
@@ -21,21 +21,21 @@ export var testBoolean = function () {
2121
TKUnit.assert(true === appSettings.getBoolean(boolKey), 'Cannot set boolean to true (no default)');
2222
};
2323

24-
export var testString = function () {
24+
export const testString = function () {
2525
appSettings.setString('stringKey', 'String value');
2626
const stringValue = appSettings.getString('stringKey');
2727

2828
TKUnit.assert('String value' === stringValue, 'Cannot set string value');
2929
};
3030

31-
export var testNumber = function () {
31+
export const testNumber = function () {
3232
appSettings.setNumber('numberKey', 54.321);
3333
const value = parseFloat(appSettings.getNumber('numberKey').toFixed(3));
3434

3535
TKUnit.assert(54.321 === value, 'Cannot set number value 54.321 != ' + value);
3636
};
3737

38-
export var testDefaults = function () {
38+
export const testDefaults = function () {
3939
const defaultValue = appSettings.getString('noStringKey', 'No string value');
4040
// will return "No string value" if there is no value for "noStringKey"
4141

@@ -44,7 +44,7 @@ export var testDefaults = function () {
4444
TKUnit.assert(123.45 === appSettings.getNumber(noNumberKey, 123.45), 'Bad default number value');
4545
};
4646

47-
export var testDefaultsWithNoDefaultValueProvided = function () {
47+
export const testDefaultsWithNoDefaultValueProvided = function () {
4848
const defaultValue = appSettings.getString('noStringKey');
4949
// will return undefined if there is no value for "noStringKey"
5050

@@ -54,7 +54,7 @@ export var testDefaultsWithNoDefaultValueProvided = function () {
5454
TKUnit.assertEqual(appSettings.getNumber(noNumberKey), undefined, 'Default number value is not undefined');
5555
};
5656

57-
export var testHasKey = function () {
57+
export const testHasKey = function () {
5858
const hasKey = appSettings.hasKey('noBoolKey');
5959
// will return false if there is no value for "noBoolKey"
6060

@@ -67,7 +67,7 @@ export var testHasKey = function () {
6767
TKUnit.assert(!appSettings.hasKey(numberKey), 'There is no key: ' + numberKey);
6868
};
6969

70-
export var testRemove = function () {
70+
export const testRemove = function () {
7171
appSettings.remove('boolKey');
7272

7373
TKUnit.assert(!appSettings.hasKey(boolKey), 'Failed to remove key: ' + boolKey);
@@ -79,15 +79,15 @@ export var testRemove = function () {
7979
TKUnit.assert(!appSettings.hasKey(numberKey), 'Failed to remove key: ' + numberKey);
8080
};
8181

82-
export var testClear = function () {
82+
export const testClear = function () {
8383
appSettings.clear();
8484

8585
TKUnit.assert(!appSettings.hasKey(boolKey), 'Failed to remove key: ' + boolKey);
8686
TKUnit.assert(!appSettings.hasKey(stringKey), 'Failed to remove key: ' + stringKey);
8787
TKUnit.assert(!appSettings.hasKey(numberKey), 'Failed to remove key: ' + numberKey);
8888
};
8989

90-
export var testFlush = function () {
90+
export const testFlush = function () {
9191
appSettings.setString(stringKey, 'String value');
9292

9393
const flushed = appSettings.flush();
@@ -97,7 +97,7 @@ export var testFlush = function () {
9797
TKUnit.assert(appSettings.hasKey(stringKey), 'There is no key: ' + stringKey);
9898
};
9999

100-
export var testAllKeys = function () {
100+
export const testAllKeys = function () {
101101
appSettings.setString(stringKey, 'String value');
102102
appSettings.setBoolean(boolKey, true);
103103
appSettings.setNumber(numberKey, 22);
@@ -108,7 +108,7 @@ export var testAllKeys = function () {
108108
TKUnit.assert(allKeys.indexOf(numberKey) !== -1, `${numberKey} is missing from .allKeys()`);
109109
};
110110

111-
export var testInvalidKey = function () {
111+
export const testInvalidKey = function () {
112112
try {
113113
appSettings.hasKey(undefined);
114114
TKUnit.assert(false, 'There is a key undefined');
@@ -134,7 +134,7 @@ export var testInvalidKey = function () {
134134
appSettings.hasKey('string');
135135
};
136136

137-
export var testInvalidValue = function () {
137+
export const testInvalidValue = function () {
138138
try {
139139
// @ts-ignore
140140
appSettings.setBoolean(boolKey, 'str');

‎apps/automated/src/application/application-tests.ios.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ export * from './application-tests-common';
55

66
// >> application-ios-observer
77
//// Add the notification observer
8+
let observer;
89
if (Application.ios) {
9-
var observer = Application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, function onReceiveCallback(notification: NSNotification) {
10+
observer = Application.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification, function onReceiveCallback(notification: NSNotification) {
1011
const percent = UIDevice.currentDevice.batteryLevel * 100;
1112
const message = 'Battery: ' + percent + '%';
1213
////console.log(message);

‎apps/automated/src/color/color-tests-common.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Color = colorModule.Color;
44
// << color-require
55
import * as TKUnit from '../tk-unit';
66

7-
export var test_Hex_Color = function () {
7+
export const test_Hex_Color = function () {
88
// >> color-hex
99
// Creates the red color
1010
const color = new Color('#FF0000');
@@ -17,7 +17,7 @@ export var test_Hex_Color = function () {
1717
TKUnit.assertEqual(color.argb, 0xffff0000, 'Color.argb not properly parsed');
1818
};
1919

20-
export var test_Hex_rgba_Color = function () {
20+
export const test_Hex_rgba_Color = function () {
2121
// >> color-hex-rgba
2222
// Creates the red color
2323
const color = new Color('#FF0000FF');
@@ -30,7 +30,7 @@ export var test_Hex_rgba_Color = function () {
3030
TKUnit.assertEqual(color.argb, 0xffff0000, 'Color.argb not properly parsed');
3131
};
3232

33-
export var test_ShortHex_Color = function () {
33+
export const test_ShortHex_Color = function () {
3434
// >> color-hex-short
3535
// Creates the color #FF8800
3636
const color = new Color('#F80');
@@ -43,7 +43,7 @@ export var test_ShortHex_Color = function () {
4343
TKUnit.assertEqual(color.argb, 0xffff8800, 'Color.argb not properly parsed');
4444
};
4545

46-
export var test_ShortHex_rgba_Color = function () {
46+
export const test_ShortHex_rgba_Color = function () {
4747
// >> color-hex-short-rgba
4848
// Creates the color #FF8800
4949
const color = new Color('#F80F');
@@ -56,7 +56,7 @@ export var test_ShortHex_rgba_Color = function () {
5656
TKUnit.assertEqual(color.argb, 0xffff8800, 'Color.argb not properly parsed');
5757
};
5858

59-
export var test_Argb_Color = function () {
59+
export const test_Argb_Color = function () {
6060
// >> color-rgb
6161
// Creates the color with 100 alpha, 255 red, 100 green, 100 blue
6262
const color = new Color(100, 255, 100, 100);
@@ -69,7 +69,7 @@ export var test_Argb_Color = function () {
6969
TKUnit.assertEqual(color.argb, 0x64ff6464, 'Color.argb not properly parsed');
7070
};
7171

72-
export var test_ArgbInt_Color = function () {
72+
export const test_ArgbInt_Color = function () {
7373
// >> color-rgb-single
7474
// Creates the color with 100 alpha, 100 red, 100 green, 100 blue
7575
const color = new Color(0x64646464);
@@ -82,7 +82,7 @@ export var test_ArgbInt_Color = function () {
8282
TKUnit.assertEqual(color.argb, 0x64646464, 'Color.argb not properly parsed');
8383
};
8484

85-
export var test_rgb_Color_CSS = function () {
85+
export const test_rgb_Color_CSS = function () {
8686
// <snippet module="color" title="color">
8787
// ### Creating a Color from four RGB values
8888
// ``` JavaScript
@@ -98,7 +98,7 @@ export var test_rgb_Color_CSS = function () {
9898
TKUnit.assertEqual(color.argb, 0xffff6464, 'Color.argb not properly parsed');
9999
};
100100

101-
export var test_rgb_Color_CSS_lvl4 = function () {
101+
export const test_rgb_Color_CSS_lvl4 = function () {
102102
const alpha = 0.5;
103103
const expected = 0x80;
104104
// <snippet module="color" title="color">
@@ -116,7 +116,7 @@ export var test_rgb_Color_CSS_lvl4 = function () {
116116
TKUnit.assertEqual(color.argb, 0x80ff6464, 'Color.argb not properly parsed');
117117
};
118118

119-
export var test_rgba_Color_CSS = function () {
119+
export const test_rgba_Color_CSS = function () {
120120
const alpha = 0.5;
121121
const expected = 0x80;
122122
// <snippet module="color" title="color">
@@ -134,7 +134,7 @@ export var test_rgba_Color_CSS = function () {
134134
TKUnit.assertEqual(color.argb, 0x80ff6464, 'Color.argb not properly parsed');
135135
};
136136

137-
export var test_Color_isValid = function () {
137+
export const test_Color_isValid = function () {
138138
const color = new Color('#FF0000');
139139

140140
TKUnit.assertEqual(Color.isValid(color), true, 'Failed to validate color instance');

‎apps/automated/src/connectivity/connectivity-tests.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as connectivity from '@nativescript/core/connectivity';
33
// << connectivity-require
44

5-
export var test_DummyTestForSnippetOnly0 = function () {
5+
export const test_DummyTestForSnippetOnly0 = function () {
66
// >> connectivity-type
77
const connectionType = connectivity.getConnectionType();
88
switch (connectionType) {
@@ -19,7 +19,7 @@ export var test_DummyTestForSnippetOnly0 = function () {
1919
// << connectivity-type
2020
};
2121

22-
export var test_DummyTestForSnippetOnly1 = function () {
22+
export const test_DummyTestForSnippetOnly1 = function () {
2323
// >> connectivity-monitoring
2424
connectivity.startMonitoring(function onConnectionTypeChanged(newConnectionType: number) {
2525
switch (newConnectionType) {

‎apps/automated/src/console/console-tests.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export var test_DummyTestForSnippetOnly0 = function () {
1+
export const test_DummyTestForSnippetOnly0 = function () {
22
// >> console-log
33
console.log('Hello, world!');
44
console.info('I am NativeScript');
@@ -7,7 +7,7 @@ export var test_DummyTestForSnippetOnly0 = function () {
77
// << console-log
88
};
99

10-
export var test_DummyTestForSnippetOnly1 = function () {
10+
export const test_DummyTestForSnippetOnly1 = function () {
1111
// >> console-time
1212
console.time('LoadTime');
1313
// << console-time
@@ -16,20 +16,20 @@ export var test_DummyTestForSnippetOnly1 = function () {
1616
// << console-timeend
1717
};
1818

19-
export var test_DummyTestForSnippetOnly2 = function () {
19+
export const test_DummyTestForSnippetOnly2 = function () {
2020
// >> console-assert
2121
console.assert(2 === 2, '2 equals 2');
2222
// << console-assert
2323
};
2424

25-
export var test_DummyTestForSnippetOnly3 = function () {
25+
export const test_DummyTestForSnippetOnly3 = function () {
2626
// >> console-dir
2727
const obj = { name: 'John', age: 34 };
2828
console.dir(obj);
2929
// << console-dir
3030
};
3131

32-
export var test_DummyTestForSnippetOnly5 = function () {
32+
export const test_DummyTestForSnippetOnly5 = function () {
3333
// >> console-trace
3434
console.trace();
3535
// << console-trace

0 commit comments

Comments
 (0)