From 0ac3cce784f7d52712e4e87987095e7816ec002c Mon Sep 17 00:00:00 2001 From: robyngit Date: Tue, 15 Oct 2024 10:13:36 -0400 Subject: [PATCH] Fix linting errors in EMLAnnotations Issue #2542 --- .../metadata/eml/EMLAnnotations.js | 89 ++++++++----------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/src/js/collections/metadata/eml/EMLAnnotations.js b/src/js/collections/metadata/eml/EMLAnnotations.js index b29c17cfc..015f414e8 100644 --- a/src/js/collections/metadata/eml/EMLAnnotations.js +++ b/src/js/collections/metadata/eml/EMLAnnotations.js @@ -1,75 +1,60 @@ "use strict"; -define([ - "jquery", - "underscore", - "backbone", - "models/metadata/eml211/EMLAnnotation", -], function ($, _, Backbone, EMLAnnotation) { +define(["underscore", "backbone", "models/metadata/eml211/EMLAnnotation"], ( + _, + Backbone, + EMLAnnotation, +) => { /** * @class EMLAnnotations * @classdesc A collection of EMLAnnotations. * @classcategory Collections/Metadata/EML * @since 2.19.0 - * @extends Backbone.Collection + * @augments Backbone.Collection */ - var EMLAnnotations = Backbone.Collection.extend( + const EMLAnnotations = Backbone.Collection.extend( /** @lends EMLAnnotations.prototype */ { - /** - * The reference to the model class that this collection is made of. - * @type EMLAnnotation - * @since 2.19.0 - */ + /** @inheritdoc */ model: EMLAnnotation, /** - * Checks if this collection already has an annotation for the same property URI. - * @param {EMLAnnotation} annotation The EMLAnnotation to compare against the annotations already in this collection. - * @returns {Boolean} Returns true is this collection already has an annotation for this property. - * @since 2.19.0 + * Checks if this collection already has an annotation for the same + * property URI. + * @param {EMLAnnotation} annotation The EMLAnnotation to compare against + * the annotations already in this collection. + * @returns {boolean} Returns true is this collection already has an + * annotation for this property. */ - hasDuplicateOf: function (annotation) { - try { - //If there is at least one model in this collection and there is a propertyURI set on the given model, - if (this.length && annotation.get("propertyURI")) { - //Return whether or not there is a duplicate - let properties = this.pluck("propertyURI"); - return properties.includes(annotation.get("propertyURI")); - } - //If this collection is empty or the propertyURI is falsey, return false - else { - return false; - } - } catch (e) { - console.error("Could not check for a duplicate annotation: ", e); - return false; + hasDuplicateOf(annotation) { + // If there is at least one model in this collection and there is a + // propertyURI set on the given model, + if (this.length && annotation.get("propertyURI")) { + // Return whether or not there is a duplicate + const properties = this.pluck("propertyURI"); + return properties.includes(annotation.get("propertyURI")); } + // If this collection is empty or the propertyURI is falsey, return + // false + return false; }, /** - * Removes the EMLAnnotation from this collection that has the same propertyURI as the given annotation. - * Then adds the given annotation to the collection. If no duplicate is found, the given annotation is still added - * to the collection. - * @param {EMLAnnotation} annotation - * @since 2.19.0 + * Removes the EMLAnnotation from this collection that has the same + * propertyURI as the given annotation. Then adds the given annotation to + * the collection. If no duplicate is found, the given annotation is still + * added to the collection. + * @param {EMLAnnotation} annotation The EMLAnnotation to replace + * duplicates with. */ - replaceDuplicateWith: function (annotation) { - try { - if (this.length && annotation.get("propertyURI")) { - let duplicates = this.findWhere({ - propertyURI: annotation.get("propertyURI"), - }); - this.remove(duplicates); - } - - this.add(annotation); - } catch (e) { - console.error( - "Could not replace the EMLAnnotation in the collection: ", - e, - ); + replaceDuplicateWith(annotation) { + if (this.length && annotation.get("propertyURI")) { + const duplicates = this.findWhere({ + propertyURI: annotation.get("propertyURI"), + }); + this.remove(duplicates); } + this.add(annotation); }, }, );