diff --git a/.eslintrc.json b/.eslintrc.json index 2a16144c..7e4337ee 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -13,6 +13,7 @@ "arrow-spacing": ["error"], "no-const-assign": ["error"], "prefer-const": ["error"], + "prefer-arrow-callback": ["error"], "spaced-comment": ["error", "always"], "semi": ["error", "always"] } diff --git a/auth/cordova.js b/auth/cordova.js index 1da36ef1..e7c3fc40 100644 --- a/auth/cordova.js +++ b/auth/cordova.js @@ -14,7 +14,7 @@ function createGoogleProvider() { function cordovaSignInRedirect(provider) { // [START auth_cordova_sign_in_redirect] - firebase.auth().signInWithRedirect(provider).then(function() { + firebase.auth().signInWithRedirect(provider).then(() => { return firebase.auth().getRedirectResult(); }).then((result) => { /** @type {firebase.auth.OAuthCredential} */ diff --git a/auth/firebaseui.js b/auth/firebaseui.js index 2a359d5a..dbbf9031 100644 --- a/auth/firebaseui.js +++ b/auth/firebaseui.js @@ -218,13 +218,13 @@ function fuiConfig() { // [START auth_fui_config] var uiConfig = { callbacks: { - signInSuccessWithAuthResult: function(authResult, redirectUrl) { + signInSuccessWithAuthResult: (authResult, redirectUrl) => { // User successfully signed in. // Return type determines whether we continue the redirect automatically // or whether we leave that to developer to handle. return true; }, - uiShown: function() { + uiShown: () => { // The widget is rendered. // Hide the loader. document.getElementById('loader').style.display = 'none'; diff --git a/auth/link-multiple-accounts.js b/auth/link-multiple-accounts.js index b6419431..30f5a2ec 100644 --- a/auth/link-multiple-accounts.js +++ b/auth/link-multiple-accounts.js @@ -41,10 +41,10 @@ function getProviders() { function simpleLink(credential) { // [START auth_simple_link] auth.currentUser.linkWithCredential(credential) - .then(function(usercred) { + .then((usercred) => { var user = usercred.user; console.log("Account linking success", user); - }).catch(function(error) { + }).catch((error) => { console.log("Account linking error", error); }); // [END auth_simple_link] @@ -53,10 +53,10 @@ function simpleLink(credential) { function anonymousLink(credential) { // [START auth_anonymous_link] auth.currentUser.linkWithCredential(credential) - .then(function(usercred) { + .then((usercred) => { var user = usercred.user; console.log("Anonymous account successfully upgraded", user); - }).catch(function(error) { + }).catch((error) => { console.log("Error upgrading anonymous account", error); }); // [END auth_anonymous_link] @@ -66,12 +66,12 @@ function linkWithPopup() { var provider = new firebase.auth.GoogleAuthProvider(); // [START auth_link_with_popup] - auth.currentUser.linkWithPopup(provider).then(function(result) { + auth.currentUser.linkWithPopup(provider).then((result) => { // Accounts successfully linked. var credential = result.credential; var user = result.user; // ... - }).catch(function(error) { + }).catch((error) => { // Handle Errors here. // ... }); @@ -88,14 +88,14 @@ function linkWithRedirect() { // [END auth_link_with_redirect] // [START auth_get_redirect_result] - auth.getRedirectResult().then(function(result) { + auth.getRedirectResult().then((result) => { if (result.credential) { // Accounts successfully linked. var credential = result.credential; var user = result.user; // ... } - }).catch(function(error) { + }).catch((error) => { // Handle Errors here. // ... }); @@ -118,7 +118,7 @@ function mergeAccounts(newCredential) { repo.delete(prevUser); // Sign in user with the account you want to link to - auth.signInWithCredential(newCredential).then(function(result) { + auth.signInWithCredential(newCredential).then((result) => { console.log("Sign In Success", result); var currentUser = result.user; var currentUserData = repo.get(currentUser); @@ -128,15 +128,15 @@ function mergeAccounts(newCredential) { var mergedData = repo.merge(prevUserData, currentUserData); return prevUser.linkWithCredential(result.credential) - .then(function(linkResult) { + .then((linkResult) => { // Sign in with the newly linked credential return auth.signInWithCredential(linkResult.credential); }) - .then(function(signInResult) { + .then((signInResult) => { // Save the merged data to the new user repo.set(signInResult.user, mergedData); }); - }).catch(function(error) { + }).catch((error) => { // If there are errors we want to undo the data merge/deletion console.log("Sign In Error", error); repo.set(prevUser, prevUserData); @@ -157,10 +157,10 @@ function unlink(providerId) { var user = auth.currentUser; // [START auth_unlink_provider] - user.unlink(providerId).then(function() { + user.unlink(providerId).then(() => { // Auth provider unlinked from account // ... - }).catch(function(error) { + }).catch((error) => { // An error happened // ... }); diff --git a/database/read-and-write.js b/database/read-and-write.js index 5fce6c97..59336c8f 100644 --- a/database/read-and-write.js +++ b/database/read-and-write.js @@ -20,7 +20,7 @@ function writeUserDataWithCompletion(userId, name, email, imageUrl) { username: name, email: email, profile_picture : imageUrl - }, function(error) { + }, (error) => { if (error) { // The write failed... } else { diff --git a/firestore-next/test.firestore.js b/firestore-next/test.firestore.js index 0be9c3ef..15bc159e 100644 --- a/firestore-next/test.firestore.js +++ b/firestore-next/test.firestore.js @@ -16,15 +16,15 @@ class City { } // Firestore data converter -var cityConverter = { - toFirestore: function(city) { +const cityConverter = { + toFirestore: (city) => { return { name: city.name, state: city.state, country: city.country }; }, - fromFirestore: function(snapshot, options){ + fromFirestore: (snapshot, options) => { const data = snapshot.data(options); return new City(data.name, data.state, data.country); } @@ -190,7 +190,7 @@ describe("firestore", () => { const q = query(collection(db, "users"), where("born", "<", 1900)); const unsubscribe = onSnapshot(q, (snapshot) => { console.log("Current users born before 1900:"); - snapshot.forEach(function (userSnapshot) { + snapshot.forEach((userSnapshot) => { console.log(userSnapshot.data()); }); }); @@ -360,7 +360,7 @@ describe("firestore", () => { function deleteCollection(db, collectionRef, batchSize) { const q = query(collectionRef, orderBy('__name__'), limit(batchSize)); - return new Promise(function(resolve) { + return new Promise((resolve) => { deleteQueryBatch(db, q, batchSize, resolve); }); } @@ -616,7 +616,7 @@ describe("firestore", () => { }); // [END listen_document] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -632,7 +632,7 @@ describe("firestore", () => { }); // [END listen_document_local] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -650,7 +650,7 @@ describe("firestore", () => { }); // [END listen_with_metadata] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -695,7 +695,7 @@ describe("firestore", () => { console.log("Current cities in CA: ", cities.join(", ")); }); // [END listen_multiple] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); @@ -720,7 +720,7 @@ describe("firestore", () => { }); }); // [END listen_diffs] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); diff --git a/firestore/test.firestore.js b/firestore/test.firestore.js index fe600769..988a3c97 100644 --- a/firestore/test.firestore.js +++ b/firestore/test.firestore.js @@ -61,7 +61,7 @@ describe("firestore", () => { // [START initialize_persistence] firebase.firestore().enablePersistence() - .catch(function(err) { + .catch((err) => { if (err.code == 'failed-precondition') { // Multiple tabs open, persistence can only be enabled // in one tab at a a time. @@ -80,7 +80,7 @@ describe("firestore", () => { var disable = // [START disable_network] firebase.firestore().disableNetwork() - .then(function() { + .then(() => { // Do offline actions // [START_EXCLUDE] console.log("Network disabled!"); @@ -91,7 +91,7 @@ describe("firestore", () => { var enable = // [START enable_network] firebase.firestore().enableNetwork() - .then(function() { + .then(() => { // Do online actions // [START_EXCLUDE] console.log("Network enabled!"); @@ -105,8 +105,8 @@ describe("firestore", () => { it("should reply with .fromCache fields", () => { // [START use_from_cache] db.collection("cities").where("state", "==", "CA") - .onSnapshot({ includeMetadataChanges: true }, function(snapshot) { - snapshot.docChanges().forEach(function(change) { + .onSnapshot({ includeMetadataChanges: true }, (snapshot) => { + snapshot.docChanges().forEach((change) => { if (change.type === "added") { console.log("New city: ", change.doc.data()); } @@ -127,10 +127,10 @@ describe("firestore", () => { last: "Lovelace", born: 1815 }) - .then(function(docRef) { + .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) - .catch(function(error) { + .catch((error) => { console.error("Error adding document: ", error); }); // [END add_ada_lovelace] @@ -159,10 +159,10 @@ describe("firestore", () => { last: "Turing", born: 1912 }) - .then(function(docRef) { + .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) - .catch(function(error) { + .catch((error) => { console.error("Error adding document: ", error); }); // [END add_alan_turing] @@ -176,9 +176,9 @@ describe("firestore", () => { // [START listen_for_users] db.collection("users") .where("born", "<", 1900) - .onSnapshot(function(snapshot) { + .onSnapshot((snapshot) => { console.log("Current users born before 1900:"); - snapshot.forEach(function (userSnapshot) { + snapshot.forEach((userSnapshot) => { console.log(userSnapshot.data()); }); }); @@ -224,10 +224,10 @@ describe("firestore", () => { state: "CA", country: "USA" }) - .then(function() { + .then(() => { console.log("Document successfully written!"); }) - .catch(function(error) { + .catch((error) => { console.error("Error writing document: ", error); }); // [END set_document] @@ -250,7 +250,7 @@ describe("firestore", () => { // [START get_custom_object] db.collection("cities").doc("LA") .withConverter(cityConverter) - .get().then(function(doc) { + .get().then((doc) => { if (doc.exists){ // Convert to City object var city = doc.data(); @@ -258,7 +258,7 @@ describe("firestore", () => { console.log(city.toString()); } else { console.log("No such document!"); - }}).catch(function(error) { + }}).catch((error) => { console.log("Error getting document:", error); }); // [END get_custom_object] @@ -283,7 +283,7 @@ describe("firestore", () => { batch.delete(laRef); // Commit the batch - batch.commit().then(function () { + batch.commit().then(() => { // [START_EXCLUDE] done(); // [END_EXCLUDE] @@ -307,7 +307,7 @@ describe("firestore", () => { } } }; - db.collection("data").doc("one").set(docData).then(function() { + db.collection("data").doc("one").set(docData).then(() => { console.log("Document successfully written!"); }); // [END data_types] @@ -339,7 +339,7 @@ describe("firestore", () => { "age": 13, "favorites.color": "Red" }) - .then(function() { + .then(() => { console.log("Document successfully updated!"); }); // [END update_document_nested] @@ -354,7 +354,7 @@ describe("firestore", () => { function deleteCollection(db, collectionRef, batchSize) { var query = collectionRef.orderBy('__name__').limit(batchSize); - return new Promise(function(resolve, reject) { + return new Promise((resolve, reject) => { deleteQueryBatch(db, query, batchSize, resolve, reject); }); } @@ -369,14 +369,14 @@ describe("firestore", () => { // Delete documents in a batch var batch = db.batch(); - snapshot.docs.forEach(function(doc) { + snapshot.docs.forEach((doc) => { batch.delete(doc.ref); }); - return batch.commit().then(function() { + return batch.commit().then(() => { return snapshot.size; }); - }).then(function(numDeleted) { + }).then((numDeleted) => { if (numDeleted < batchSize) { resolve(); return; @@ -384,7 +384,7 @@ describe("firestore", () => { // Recurse on the next process tick, to avoid // exploding the stack. - setTimeout(function() { + setTimeout(() => { deleteQueryBatch(db, query, batchSize, resolve, reject); }, 0); }) @@ -440,10 +440,10 @@ describe("firestore", () => { name: "Tokyo", country: "Japan" }) - .then(function(docRef) { + .then((docRef) => { console.log("Document written with ID: ", docRef.id); }) - .catch(function(error) { + .catch((error) => { console.error("Error adding document: ", error); }); // [END add_document] @@ -470,10 +470,10 @@ describe("firestore", () => { return washingtonRef.update({ capital: true }) - .then(function() { + .then(() => { console.log("Document successfully updated!"); }) - .catch(function(error) { + .catch((error) => { // The document probably doesn't exist. console.error("Error updating document: ", error); }); @@ -510,9 +510,9 @@ describe("firestore", () => { it("should delete a document", () => { var output = // [START delete_document] - db.collection("cities").doc("DC").delete().then(function() { + db.collection("cities").doc("DC").delete().then(() => { console.log("Document successfully deleted!"); - }).catch(function(error) { + }).catch((error) => { console.error("Error removing document: ", error); }); // [END delete_document] @@ -528,9 +528,9 @@ describe("firestore", () => { // Uncomment to initialize the doc. // sfDocRef.set({ population: 0 }); - return db.runTransaction(function(transaction) { + return db.runTransaction((transaction) => { // This code may get re-run multiple times if there are conflicts. - return transaction.get(sfDocRef).then(function(sfDoc) { + return transaction.get(sfDocRef).then((sfDoc) => { if (!sfDoc.exists) { throw "Document does not exist!"; } @@ -541,9 +541,9 @@ describe("firestore", () => { var newPopulation = sfDoc.data().population + 1; transaction.update(sfDocRef, { population: newPopulation }); }); - }).then(function() { + }).then(() => { console.log("Transaction successfully committed!"); - }).catch(function(error) { + }).catch((error) => { console.log("Transaction failed: ", error); }); // [END transaction] @@ -555,8 +555,8 @@ describe("firestore", () => { // Create a reference to the SF doc. var sfDocRef = db.collection("cities").doc("SF"); - db.runTransaction(function(transaction) { - return transaction.get(sfDocRef).then(function(sfDoc) { + db.runTransaction((transaction) => { + return transaction.get(sfDocRef).then((sfDoc) => { if (!sfDoc.exists) { throw "Document does not exist!"; } @@ -569,9 +569,9 @@ describe("firestore", () => { return Promise.reject("Sorry! Population is too big."); } }); - }).then(function(newPopulation) { + }).then((newPopulation) => { console.log("Population increased to ", newPopulation); - }).catch(function(err) { + }).catch((err) => { // This will be an "population is too big" error. console.error(err); }); @@ -582,14 +582,14 @@ describe("firestore", () => { // [START get_document] var docRef = db.collection("cities").doc("SF"); - docRef.get().then(function(doc) { + docRef.get().then((doc) => { if (doc.exists) { console.log("Document data:", doc.data()); } else { // doc.data() will be undefined in this case console.log("No such document!"); } - }).catch(function(error) { + }).catch((error) => { console.log("Error getting document:", error); }); // [END get_document] @@ -607,11 +607,11 @@ describe("firestore", () => { }; // Get a document, forcing the SDK to fetch from the offline cache. - docRef.get(getOptions).then(function(doc) { + docRef.get(getOptions).then((doc) => { // Document was found in the cache. If no cached document exists, // an error will be returned to the 'catch' block below. console.log("Cached document data:", doc.data()); - }).catch(function(error) { + }).catch((error) => { console.log("Error getting cached document:", error); }); // [END get_document_options] @@ -621,12 +621,12 @@ describe("firestore", () => { var unsub = // [START listen_document] db.collection("cities").doc("SF") - .onSnapshot(function(doc) { + .onSnapshot((doc) => { console.log("Current data: ", doc.data()); }); // [END listen_document] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -636,13 +636,13 @@ describe("firestore", () => { var unsub = // [START listen_document_local] db.collection("cities").doc("SF") - .onSnapshot(function(doc) { + .onSnapshot((doc) => { var source = doc.metadata.hasPendingWrites ? "Local" : "Server"; console.log(source, " data: ", doc.data()); }); // [END listen_document_local] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -655,12 +655,12 @@ describe("firestore", () => { .onSnapshot({ // Listen for document metadata changes includeMetadataChanges: true - }, function(doc) { + }, (doc) => { // ... }); // [END listen_with_metadata] - setTimeout(function() { + setTimeout(() => { unsub(); done(); }, 3000); @@ -671,13 +671,13 @@ describe("firestore", () => { // [START get_multiple] db.collection("cities").where("capital", "==", true) .get() - .then(function(querySnapshot) { - querySnapshot.forEach(function(doc) { + .then((querySnapshot) => { + querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); }) - .catch(function(error) { + .catch((error) => { console.log("Error getting documents: ", error); }); // [END get_multiple] @@ -687,8 +687,8 @@ describe("firestore", () => { it("should get all documents from a collection", () => { var output = // [START get_multiple_all] - db.collection("cities").get().then(function(querySnapshot) { - querySnapshot.forEach(function(doc) { + db.collection("cities").get().then((querySnapshot) => { + querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); @@ -701,15 +701,15 @@ describe("firestore", () => { var unsubscribe = // [START listen_multiple] db.collection("cities").where("state", "==", "CA") - .onSnapshot(function(querySnapshot) { + .onSnapshot((querySnapshot) => { var cities = []; - querySnapshot.forEach(function(doc) { + querySnapshot.forEach((doc) => { cities.push(doc.data().name); }); console.log("Current cities in CA: ", cities.join(", ")); }); // [END listen_multiple] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); @@ -719,8 +719,8 @@ describe("firestore", () => { var unsubscribe = // [START listen_diffs] db.collection("cities").where("state", "==", "CA") - .onSnapshot(function(snapshot) { - snapshot.docChanges().forEach(function(change) { + .onSnapshot((snapshot) => { + snapshot.docChanges().forEach((change) => { if (change.type === "added") { console.log("New city: ", change.doc.data()); } @@ -733,7 +733,7 @@ describe("firestore", () => { }); }); // [END listen_diffs] - setTimeout(function() { + setTimeout(() => { unsubscribe(); done(); }, 2500); @@ -742,7 +742,7 @@ describe("firestore", () => { it("should unsubscribe a listener", () => { // [START detach_listener] var unsubscribe = db.collection("cities") - .onSnapshot(function (){ + .onSnapshot(() => { // Respond to data // ... }); @@ -758,9 +758,9 @@ describe("firestore", () => { var unsubscribe = // [START handle_listen_errors] db.collection("cities") - .onSnapshot(function(snapshot) { + .onSnapshot((snapshot) => { // ... - }, function(error) { + }, (error) => { // ... }); // [END handle_listen_errors] @@ -803,7 +803,7 @@ describe("firestore", () => { docRef.update({ timestamp: firebase.firestore.FieldValue.serverTimestamp() }); - docRef.onSnapshot(function(snapshot) { + docRef.onSnapshot((snapshot) => { var data = snapshot.data(options); console.log( 'Timestamp: ' + data.timestamp + @@ -984,7 +984,7 @@ describe("firestore", () => { // [START start_doc] var citiesRef = db.collection("cities"); - return citiesRef.doc("SF").get().then(function(doc) { + return citiesRef.doc("SF").get().then((doc) => { // Get all cities with a population bigger than San Francisco var biggerThanSf = citiesRef .orderBy("population") @@ -1017,7 +1017,7 @@ describe("firestore", () => { .orderBy("population") .limit(25); - return first.get().then(function (documentSnapshots) { + return first.get().then((documentSnapshots) => { // Get the last visible document var lastVisible = documentSnapshots.docs[documentSnapshots.docs.length-1]; console.log("last", lastVisible); @@ -1087,8 +1087,8 @@ describe("firestore", () => { it("should query a collection group", () => { // [START fs_collection_group_query] var museums = db.collectionGroup('landmarks').where('type', '==', 'museum'); - museums.get().then(function (querySnapshot) { - querySnapshot.forEach(function (doc) { + museums.get().then((querySnapshot) => { + querySnapshot.forEach((doc) => { console.log(doc.id, ' => ', doc.data()); }); }); diff --git a/snippets/firestore-next/test-firestore/city_custom_object.js b/snippets/firestore-next/test-firestore/city_custom_object.js index 4335d06e..2b9f2c02 100644 --- a/snippets/firestore-next/test-firestore/city_custom_object.js +++ b/snippets/firestore-next/test-firestore/city_custom_object.js @@ -16,15 +16,15 @@ class City { } // Firestore data converter -var cityConverter = { - toFirestore: function(city) { +const cityConverter = { + toFirestore: (city) => { return { name: city.name, state: city.state, country: city.country }; }, - fromFirestore: function(snapshot, options){ + fromFirestore: (snapshot, options) => { const data = snapshot.data(options); return new City(data.name, data.state, data.country); } diff --git a/snippets/firestore-next/test-firestore/delete_collection.js b/snippets/firestore-next/test-firestore/delete_collection.js index d9d6c70a..758e653e 100644 --- a/snippets/firestore-next/test-firestore/delete_collection.js +++ b/snippets/firestore-next/test-firestore/delete_collection.js @@ -13,7 +13,7 @@ import { collection, query, orderBy, limit, getDocs, writeBatch } from "firebase function deleteCollection(db, collectionRef, batchSize) { const q = query(collectionRef, orderBy('__name__'), limit(batchSize)); - return new Promise(function(resolve) { + return new Promise((resolve) => { deleteQueryBatch(db, q, batchSize, resolve); }); } diff --git a/snippets/firestore-next/test-firestore/listen_for_users.js b/snippets/firestore-next/test-firestore/listen_for_users.js index 4a8de4a9..3c42287a 100644 --- a/snippets/firestore-next/test-firestore/listen_for_users.js +++ b/snippets/firestore-next/test-firestore/listen_for_users.js @@ -9,7 +9,7 @@ import { collection, where, query, onSnapshot } from "firebase/firestore"; const q = query(collection(db, "users"), where("born", "<", 1900)); const unsubscribe = onSnapshot(q, (snapshot) => { console.log("Current users born before 1900:"); - snapshot.forEach(function (userSnapshot) { + snapshot.forEach((userSnapshot) => { console.log(userSnapshot.data()); }); }); diff --git a/storage/upload-files.js b/storage/upload-files.js index 988fc3eb..2f889019 100644 --- a/storage/upload-files.js +++ b/storage/upload-files.js @@ -203,7 +203,7 @@ function uploadHandleError(file) { }, () => { // Upload completed successfully, now we can get the download URL - uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) { + uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => { console.log('File available at', downloadURL); }); }