diff --git a/.codeclimate.yml b/.codeclimate.yml index 44bd98274b..b28ca8ae10 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -28,6 +28,7 @@ engines: config: extensions: - .es6 + ignore_warnings: true fixme: enabled: false rubocop: diff --git a/.eslintrc b/.eslintrc index 9faa37508e..9e9b612342 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,7 @@ -ecmaFeatures: - modules: true - jsx: true +parserOptions: + sourceType: module + ecmaFeatures: + jsx: true env: amd: true @@ -61,7 +62,7 @@ rules: no-empty-pattern: 2 no-eq-null: 2 no-eval: 2 - no-extend-native: 2 + no-extend-native: 1 no-extra-bind: 2 no-fallthrough: 2 no-floating-decimal: 0 @@ -78,7 +79,7 @@ rules: no-native-reassign: 2 no-new-func: 2 no-new-wrappers: 2 - no-new: 2 + no-new: 1 no-octal-escape: 2 no-octal: 2 no-proto: 2 diff --git a/app/assets/javascripts/sufia/autocomplete.es6 b/app/assets/javascripts/sufia/autocomplete.es6 index f886de2f83..95bd01068e 100644 --- a/app/assets/javascripts/sufia/autocomplete.es6 +++ b/app/assets/javascripts/sufia/autocomplete.es6 @@ -1,66 +1,68 @@ +import Location from 'sufia/autocomplete/location' +import Subject from 'sufia/autocomplete/subject' +import Language from 'sufia/autocomplete/language' +import Work from 'sufia/autocomplete/work' + + export class Autocomplete { - constructor() { - } + constructor() { + } - // This is the initial setup for the form. - setup() { - $('[data-autocomplete]').each((index, value) => { - let selector = $(value) - switch (selector.data('autocomplete')) { - case "subject": - this.autocompleteSubject(selector); - break; - case "language": - this.autocompleteLanguage(selector); - break; - case "based_near": - this.autocompleteLocation(selector); - break; - case "work": - var user = selector.data('user'); - var id = selector.data('id'); - this.autocompleteWork(selector, user, id); - break; - } - }); - } + // This is the initial setup for the form. + setup() { + $('[data-autocomplete]').each((index, value) => { + let selector = $(value) + switch (selector.data('autocomplete')) { + case "subject": + this.autocompleteSubject(selector); + break; + case "language": + this.autocompleteLanguage(selector); + break; + case "based_near": + this.autocompleteLocation(selector); + break; + case "work": + var user = selector.data('user'); + var id = selector.data('id'); + this.autocompleteWork(selector, user, id); + break; + } + }); + } - // attach an auto complete based on the field - fieldAdded(cloneElem) { - var $cloneElem = $(cloneElem); - // FIXME this code (comparing the id) depends on a bug. Each input has an id and - // the id is duplicated when you press the plus button. This is not valid html. - if (/_based_near$/.test($cloneElem.attr("id"))) { - this.autocompleteLocation($cloneElem); - } else if (/_language$/.test($cloneElem.attr("id"))) { - this.autocompleteLanguage($cloneElem); - } else if (/_subject$/.test($cloneElem.attr("id"))) { - this.autocompleteSubject($cloneElem); + // attach an auto complete based on the field + fieldAdded(cloneElem) { + var $cloneElem = $(cloneElem); + // FIXME this code (comparing the id) depends on a bug. Each input has an id and + // the id is duplicated when you press the plus button. This is not valid html. + if (/_based_near$/.test($cloneElem.attr("id"))) { + this.autocompleteLocation($cloneElem); + } else if (/_language$/.test($cloneElem.attr("id"))) { + this.autocompleteLanguage($cloneElem); + } else if (/_subject$/.test($cloneElem.attr("id"))) { + this.autocompleteSubject($cloneElem); + } } - } - autocompleteLocation(field) { - var loc = require('sufia/autocomplete/location'); - new loc.Location(field, field.data('autocomplete-url')) - } + autocompleteLocation(field) { + new Location(field, field.data('autocomplete-url')) + } - autocompleteSubject(field) { - var subj = require('sufia/autocomplete/subject'); - new subj.Subject(field, field.data('autocomplete-url')) - } + autocompleteSubject(field) { + new Subject(field, field.data('autocomplete-url')) + } - autocompleteLanguage(field) { - var lang = require('sufia/autocomplete/language'); - new lang.Language(field, field.data('autocomplete-url')) - } + autocompleteLanguage(field) { + new Language(field, field.data('autocomplete-url')) + } - autocompleteWork(field, user, id) { - var work = require('sufia/autocomplete/work') - new work.Work( - field, - field.data('autocomplete-url'), - user, - id - ) - } + autocompleteWork(field, user, id) { + new Work( + field, + field.data('autocomplete-url'), + user, + id + ) + } } diff --git a/app/assets/javascripts/sufia/autocomplete/language.es6 b/app/assets/javascripts/sufia/autocomplete/language.es6 index 8d2d228b63..f09d712f38 100644 --- a/app/assets/javascripts/sufia/autocomplete/language.es6 +++ b/app/assets/javascripts/sufia/autocomplete/language.es6 @@ -1,4 +1,4 @@ -export class Language { +export default class Language { constructor(element, url) { this.url = url element.autocomplete(this.options()); @@ -22,4 +22,3 @@ export class Language { }; } } - diff --git a/app/assets/javascripts/sufia/autocomplete/location.es6 b/app/assets/javascripts/sufia/autocomplete/location.es6 index f257dc9778..2e24b33f41 100644 --- a/app/assets/javascripts/sufia/autocomplete/location.es6 +++ b/app/assets/javascripts/sufia/autocomplete/location.es6 @@ -1,4 +1,4 @@ -export class Location { +export default class Location { constructor(element, url) { this.url = url element.autocomplete(this.options()); diff --git a/app/assets/javascripts/sufia/autocomplete/subject.es6 b/app/assets/javascripts/sufia/autocomplete/subject.es6 index 35fde078aa..fd38c208bc 100644 --- a/app/assets/javascripts/sufia/autocomplete/subject.es6 +++ b/app/assets/javascripts/sufia/autocomplete/subject.es6 @@ -1,4 +1,4 @@ -export class Subject { +export default class Subject { constructor(element, url) { this.url = url element.autocomplete(this.options()); @@ -22,5 +22,3 @@ export class Subject { }; } } - - diff --git a/app/assets/javascripts/sufia/autocomplete/work.es6 b/app/assets/javascripts/sufia/autocomplete/work.es6 index 586bd29959..bfbd7b698b 100644 --- a/app/assets/javascripts/sufia/autocomplete/work.es6 +++ b/app/assets/javascripts/sufia/autocomplete/work.es6 @@ -1,4 +1,4 @@ -export class Work { +export default class Work { // Autocomplete for finding possible related works (child and parent). constructor(element, url, user, id) { this.url = url; diff --git a/app/assets/javascripts/sufia/notifications.es6 b/app/assets/javascripts/sufia/notifications.es6 index 3640cce6c9..1bb73e0af6 100644 --- a/app/assets/javascripts/sufia/notifications.es6 +++ b/app/assets/javascripts/sufia/notifications.es6 @@ -13,28 +13,28 @@ export class Notifications { } poller(interval, url) { - setInterval(() => { this.fetchUpdates(url) }, interval); + setInterval(() => { this.fetchUpdates(url) }, interval); } fetchUpdates(url) { - $.getJSON( url, (data) => this.updatePage(data)) + $.getJSON( url, (data) => this.updatePage(data)) } updatePage(data) { - let notification = $('.notify_number') - notification.find('.count').html(data.notify_number) - if (data.notify_number == 0) { - notification.addClass('label-default') - notification.removeClass('label-danger') - } else { - notification.addClass('label-danger') - notification.removeClass('label-default') - } + let notification = $('.notify_number') + notification.find('.count').html(data.notify_number) + if (data.notify_number === 0) { + notification.addClass('label-default') + notification.removeClass('label-danger') + } else { + notification.addClass('label-danger') + notification.removeClass('label-default') + } } getIntervalSeconds(default_interval) { - var seconds = parseInt(this.queryStringParam("notification_seconds")); - return seconds || default_interval; + var seconds = parseInt(this.queryStringParam("notification_seconds"), 10); + return seconds || default_interval; } // During development allow the frequency of the notifications check to diff --git a/app/assets/javascripts/sufia/permissions/control.es6 b/app/assets/javascripts/sufia/permissions/control.es6 index c10164cd85..4506315722 100644 --- a/app/assets/javascripts/sufia/permissions/control.es6 +++ b/app/assets/javascripts/sufia/permissions/control.es6 @@ -6,10 +6,10 @@ export class PermissionsControl { /** * Initialize the save controls * @param {jQuery} element the jquery selector for the permissions container - * @param {String} template_id the identifier of the template for the added elements + * @param {String} template_id the identifier of the template for the added elements */ constructor(element, template_id) { - if (element.size() == 0) { + if (element.size() === 0) { return } this.element = element @@ -19,7 +19,7 @@ export class PermissionsControl { this.group_controls = new GroupControls(this.element, this.registry) } - // retrieve object_name the name of the object to create + // retrieve object_name the name of the object to create object_name() { return this.element.data('param-key') } diff --git a/app/assets/javascripts/sufia/permissions/group_controls.es6 b/app/assets/javascripts/sufia/permissions/group_controls.es6 index bece9f21fc..d72e1534c3 100644 --- a/app/assets/javascripts/sufia/permissions/group_controls.es6 +++ b/app/assets/javascripts/sufia/permissions/group_controls.es6 @@ -56,7 +56,7 @@ export class GroupControls { } selectedGroupValid() { - return this.selectedGroup().index() != 0 + return this.selectedGroup().index() !== 0 } selectedGroup() { @@ -64,7 +64,7 @@ export class GroupControls { } permissionValid() { - return this.selectedPermission().index() != 0 + return this.selectedPermission().index() !== 0 } selectedPermission() { diff --git a/app/assets/javascripts/sufia/permissions/user_controls.es6 b/app/assets/javascripts/sufia/permissions/user_controls.es6 index fd69e03d1b..e9e68efa00 100644 --- a/app/assets/javascripts/sufia/permissions/user_controls.es6 +++ b/app/assets/javascripts/sufia/permissions/user_controls.es6 @@ -60,7 +60,7 @@ export class UserControls { } selectedUserIsDepositor() { - return this.userName() == this.depositor + return this.userName() === this.depositor } userValid() { @@ -68,11 +68,11 @@ export class UserControls { } userNameValid() { - return this.userName() != "" + return this.userName() !== "" } permissionValid() { - return this.selectedPermission().index() != 0 + return this.selectedPermission().index() !== 0 } selectedPermission() { diff --git a/app/assets/javascripts/sufia/relationships/table.es6 b/app/assets/javascripts/sufia/relationships/table.es6 index d95e3510cb..61c73334f7 100644 --- a/app/assets/javascripts/sufia/relationships/table.es6 +++ b/app/assets/javascripts/sufia/relationships/table.es6 @@ -34,7 +34,7 @@ export default class RelationshipsTable { // Display an error when the input field is empty, or if the work ID is already related, // otherwise clone the row and set appropriate styles - if ($input.val() == "") { + if ($input.val() === "") { $this.setWarningMessage($row, "ID cannot be empty."); } else if ($.inArray($input.val(), $this.existing_related_works_values) > -1) { $this.setWarningMessage($row, "Work is already related."); @@ -104,7 +104,7 @@ export default class RelationshipsTable { // ENTER key was pressed, wait for keyup to click the Add button if (key_code === 13) { - if (event.type == "keyup") { + if (event.type === "keyup") { $this.clickAddbutton($row); } event.preventDefault(); @@ -112,7 +112,7 @@ export default class RelationshipsTable { } // ESC key was pressed, clear the input field and hide the error - if (key_code === 27 && event.type == "keyup") { + if (key_code === 27 && event.type === "keyup") { $(this).val(""); $this.hideWarningMessage($row); } diff --git a/app/assets/javascripts/sufia/save_work/required_fields.es6 b/app/assets/javascripts/sufia/save_work/required_fields.es6 index 9b2c80e99e..9bcd8a2f7b 100644 --- a/app/assets/javascripts/sufia/save_work/required_fields.es6 +++ b/app/assets/javascripts/sufia/save_work/required_fields.es6 @@ -7,7 +7,7 @@ export class RequiredFields { } get areComplete() { - return this.requiredFields.filter((n, elem) => { return this.isValuePresent(elem) } ).length == 0 + return this.requiredFields.filter((n, elem) => { return this.isValuePresent(elem) } ).length === 0 } isValuePresent(elem) { diff --git a/app/assets/javascripts/sufia/save_work/save_work_control.es6 b/app/assets/javascripts/sufia/save_work/save_work_control.es6 index ab66044392..2a8f8daec7 100644 --- a/app/assets/javascripts/sufia/save_work/save_work_control.es6 +++ b/app/assets/javascripts/sufia/save_work/save_work_control.es6 @@ -21,7 +21,7 @@ export default class SaveWorkControl { * @param {AdminSetWidget} adminSetWidget the control for the adminSet dropdown */ constructor(element, adminSetWidget) { - if (element.size() == 0) { + if (element.length < 1) { return } this.element = element