Prefer const wherever possible
Summary: Non-final identifiers make code harder to understand. This is particularly true for JavaScript where even the *type* can change as a value gets reassigned later. This enforces to use `const` whereever possible, but doesn't "outlaw" `let`. Mixed destructuring is also still allowed. Used `eslint --fix` to change all existing cases. Reviewed By: jknoxville Differential Revision: D16131329 fbshipit-source-id: 2eceaca7c603b71b36e005be5d135e1849f2518d
This commit is contained in:
committed by
Facebook Github Bot
parent
662db20948
commit
c588b650ae
@@ -18,56 +18,56 @@ function getAndroidLog(
|
||||
|
||||
test('test shouldParseAndroidLog function for type error and tag is AndroidRuntime', () => {
|
||||
const referenceDate = new Date();
|
||||
let log: DeviceLogEntry = getAndroidLog(
|
||||
const log: DeviceLogEntry = getAndroidLog(
|
||||
new Date(referenceDate.getTime() + 10000), //This log arrives 10 secs after the refernce time
|
||||
'error',
|
||||
'AndroidRuntime',
|
||||
'Possible runtime crash',
|
||||
);
|
||||
let shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
const shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
expect(shouldParseTheLog).toEqual(true);
|
||||
});
|
||||
test('test shouldParseAndroidLog function for type non-error', () => {
|
||||
const referenceDate = new Date();
|
||||
let log: DeviceLogEntry = getAndroidLog(
|
||||
const log: DeviceLogEntry = getAndroidLog(
|
||||
new Date(referenceDate.getTime() + 10000), //This log arrives 10 secs after the refernce time
|
||||
'debug',
|
||||
'fb4a.activitymanager',
|
||||
'Possible debug info in activitymanager',
|
||||
);
|
||||
let shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
const shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
expect(shouldParseTheLog).toEqual(false);
|
||||
});
|
||||
test('test shouldParseAndroidLog function for the older android log', () => {
|
||||
const referenceDate = new Date();
|
||||
let log: DeviceLogEntry = getAndroidLog(
|
||||
const log: DeviceLogEntry = getAndroidLog(
|
||||
new Date(referenceDate.getTime() - 10000), //This log arrives 10 secs before the refernce time
|
||||
'error',
|
||||
'fb4a.activitymanager',
|
||||
'Possible error info in activitymanager',
|
||||
);
|
||||
let shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
const shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
expect(shouldParseTheLog).toEqual(false);
|
||||
});
|
||||
test('test shouldParseAndroidLog function for the fatal log', () => {
|
||||
const referenceDate = new Date();
|
||||
let log: DeviceLogEntry = getAndroidLog(
|
||||
const log: DeviceLogEntry = getAndroidLog(
|
||||
new Date(referenceDate.getTime() + 10000), //This log arrives 10 secs after the refernce time
|
||||
'fatal',
|
||||
'arbitrary tag',
|
||||
'Possible error info in activitymanager',
|
||||
);
|
||||
let shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
const shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
expect(shouldParseTheLog).toEqual(true);
|
||||
});
|
||||
test('test shouldParseAndroidLog function for the error log which does not staisfy our tags check', () => {
|
||||
const referenceDate = new Date();
|
||||
let log: DeviceLogEntry = getAndroidLog(
|
||||
const log: DeviceLogEntry = getAndroidLog(
|
||||
new Date(referenceDate.getTime() + 10000), //This log arrives 10 secs after the refernce time
|
||||
'error',
|
||||
'arbitrary tag',
|
||||
'Possible error info in fb4a',
|
||||
);
|
||||
let shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
const shouldParseTheLog = shouldParseAndroidLog(log, referenceDate);
|
||||
expect(shouldParseTheLog).toEqual(false);
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ function generateClientIdentifierWithSalt(
|
||||
identifier: string,
|
||||
salt: string,
|
||||
): string {
|
||||
let array = identifier.split('#');
|
||||
const array = identifier.split('#');
|
||||
const serial = array.pop();
|
||||
return array.join('#') + '#' + salt + '-' + serial;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ test('test processStore function for an iOS device connected with client plugin
|
||||
expect(json).toBeDefined();
|
||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||
const {pluginStates} = json.store;
|
||||
let expectedPluginState = {
|
||||
const expectedPluginState = {
|
||||
[generateClientIdentifierWithSalt(clientIdentifier, 'salt')]: {
|
||||
msg: 'Test plugin',
|
||||
},
|
||||
@@ -258,7 +258,7 @@ test('test processStore function to have only the client for the selected device
|
||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
|
||||
const {clients} = json;
|
||||
const {pluginStates} = json.store;
|
||||
let expectedPluginState = {
|
||||
const expectedPluginState = {
|
||||
[generateClientIdentifierWithSalt(selectedDeviceClientIdentifier, 'salt') +
|
||||
'#testapp']: {
|
||||
msg: 'Test plugin selected device',
|
||||
@@ -313,7 +313,7 @@ test('test processStore function to have multiple clients for the selected devic
|
||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already added
|
||||
const {clients} = json;
|
||||
const {pluginStates} = json.store;
|
||||
let expectedPluginState = {
|
||||
const expectedPluginState = {
|
||||
[generateClientIdentifierWithSalt(clientIdentifierApp1, 'salt') +
|
||||
'#testapp1']: {
|
||||
msg: 'Test plugin App1',
|
||||
@@ -355,7 +355,7 @@ test('test processStore function for device plugin state and no clients', async
|
||||
//$FlowFixMe Flow doesn't that its a test and the assertion for null is already done
|
||||
const {pluginStates} = json.store;
|
||||
const {clients} = json;
|
||||
let expectedPluginState = {
|
||||
const expectedPluginState = {
|
||||
'salt-serial#TestDevicePlugin': {msg: 'Test Device plugin'},
|
||||
};
|
||||
expect(pluginStates).toEqual(expectedPluginState);
|
||||
|
||||
@@ -41,18 +41,18 @@ function mockPluginDefinition(name: string): PluginDefinition {
|
||||
}
|
||||
|
||||
test('getActivePluginNames with the plugins getting excluded', () => {
|
||||
let state = mockPluginState(
|
||||
const state = mockPluginState(
|
||||
[mockPluginDefinition('DevicePlugin1')],
|
||||
[mockPluginDefinition('ClientPlugin1')],
|
||||
[[mockPluginDefinition('DevicePlugin2'), 'DevicePlugin2']],
|
||||
);
|
||||
let list = getActivePluginNames(state);
|
||||
const list = getActivePluginNames(state);
|
||||
expect(list).toEqual(['ClientPlugin2']);
|
||||
});
|
||||
|
||||
test('getActivePluginNames with the no plugins getting excluded', () => {
|
||||
let state = mockPluginState([], [], []);
|
||||
let list = getActivePluginNames(state);
|
||||
const state = mockPluginState([], [], []);
|
||||
const list = getActivePluginNames(state);
|
||||
expect(list).toEqual([
|
||||
'ClientPlugin1',
|
||||
'ClientPlugin2',
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
import promiseTimeout from '../promiseTimeout';
|
||||
|
||||
test('test promiseTimeout for timeout to happen', () => {
|
||||
let promise = promiseTimeout(
|
||||
const promise = promiseTimeout(
|
||||
200,
|
||||
new Promise((resolve, reject) => {
|
||||
let id = setTimeout(() => {
|
||||
const id = setTimeout(() => {
|
||||
clearTimeout(id);
|
||||
resolve();
|
||||
}, 500);
|
||||
@@ -22,10 +22,10 @@ test('test promiseTimeout for timeout to happen', () => {
|
||||
});
|
||||
|
||||
test('test promiseTimeout for timeout not to happen', () => {
|
||||
let promise = promiseTimeout(
|
||||
const promise = promiseTimeout(
|
||||
200,
|
||||
new Promise((resolve, reject) => {
|
||||
let id = setTimeout(() => {
|
||||
const id = setTimeout(() => {
|
||||
clearTimeout(id);
|
||||
resolve();
|
||||
}, 100);
|
||||
|
||||
@@ -19,12 +19,12 @@ class TestObject extends Object {
|
||||
set: ?Set<any>;
|
||||
}
|
||||
test('test makeObjectSerializable function for unnested object with no Set and Map', () => {
|
||||
let obj = {key1: 'value1', key2: 'value2'};
|
||||
const obj = {key1: 'value1', key2: 'value2'};
|
||||
const output = makeObjectSerializable(obj);
|
||||
expect(output).toEqual(obj);
|
||||
|
||||
// Testing numbers
|
||||
let obj2 = {key1: 1, key2: 2};
|
||||
const obj2 = {key1: 1, key2: 2};
|
||||
const output2 = makeObjectSerializable(obj2);
|
||||
expect(output2).toEqual(obj2);
|
||||
});
|
||||
@@ -36,27 +36,27 @@ test('makeObjectSerializable function for unnested object with values which retu
|
||||
});
|
||||
|
||||
test('test deserializeObject function for unnested object with no Set and Map', () => {
|
||||
let obj = {key1: 'value1', key2: 'value2'};
|
||||
const obj = {key1: 'value1', key2: 'value2'};
|
||||
const output = deserializeObject(obj);
|
||||
expect(output).toEqual(obj);
|
||||
|
||||
// Testing numbers
|
||||
let obj2 = {key1: 1, key2: 2};
|
||||
const obj2 = {key1: 1, key2: 2};
|
||||
const output2 = deserializeObject(obj2);
|
||||
expect(output2).toEqual(obj2);
|
||||
});
|
||||
|
||||
test('test makeObjectSerializable and deserializeObject function for nested object with no Set and Map', () => {
|
||||
let subObj = {key1: 'value1', key2: 'value2'};
|
||||
let subObj2 = {key21: 'value21', key22: 'value22'};
|
||||
let obj = {key1: subObj, key2: subObj2};
|
||||
const subObj = {key1: 'value1', key2: 'value2'};
|
||||
const subObj2 = {key21: 'value21', key22: 'value22'};
|
||||
const obj = {key1: subObj, key2: subObj2};
|
||||
const output = makeObjectSerializable(obj);
|
||||
expect(output).toEqual(obj);
|
||||
expect(deserializeObject(output)).toEqual(obj);
|
||||
|
||||
let subObjNum = {key1: 1, key2: 2};
|
||||
let subObjNum2 = {key21: 21, key22: 22};
|
||||
let obj2 = {key1: subObjNum, key2: subObjNum2};
|
||||
const subObjNum = {key1: 1, key2: 2};
|
||||
const subObjNum2 = {key21: 21, key22: 22};
|
||||
const obj2 = {key1: subObjNum, key2: subObjNum2};
|
||||
const output2 = makeObjectSerializable(obj2);
|
||||
expect(output2).toEqual(obj2);
|
||||
expect(deserializeObject(output2)).toEqual(obj2);
|
||||
@@ -184,19 +184,19 @@ test('test makeObjectSerializable and deserializeObject function for custom Obje
|
||||
});
|
||||
|
||||
test('test makeObjectSerializable and deserializeObject function for Array as input', () => {
|
||||
let arr = [1, 2, 4, 5];
|
||||
const arr = [1, 2, 4, 5];
|
||||
const output = makeObjectSerializable(arr);
|
||||
expect(output).toEqual(arr);
|
||||
expect(deserializeObject(output)).toEqual(arr);
|
||||
|
||||
let arrMap = [
|
||||
const arrMap = [
|
||||
new Map([['a1', 'v1'], ['a2', 'v2']]),
|
||||
new Map([['b1', 'v1'], ['b2', 'v2']]),
|
||||
new Map([['c1', 'v1'], ['c2', 'v2']]),
|
||||
new Map([['d1', 'v1'], ['d2', 'v2']]),
|
||||
];
|
||||
|
||||
let expectedArr = [
|
||||
const expectedArr = [
|
||||
{
|
||||
__flipper_object_type__: 'Map',
|
||||
data: [['a1', 'v1'], ['a2', 'v2']],
|
||||
@@ -218,7 +218,7 @@ test('test makeObjectSerializable and deserializeObject function for Array as in
|
||||
expect(outputMap).toEqual(expectedArr);
|
||||
expect(deserializeObject(outputMap)).toEqual(arrMap);
|
||||
|
||||
let arrStr = ['first', 'second', 'third', 'fourth'];
|
||||
const arrStr = ['first', 'second', 'third', 'fourth'];
|
||||
const outputStr = makeObjectSerializable(arrStr);
|
||||
expect(outputStr).toEqual(arrStr);
|
||||
expect(deserializeObject(outputStr)).toEqual(arrStr);
|
||||
|
||||
Reference in New Issue
Block a user