Skip to content

Commit

Permalink
Update eslint config to 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Mar 11, 2017
1 parent c838900 commit 8ad4cf1
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 95 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Expand Up @@ -28,6 +28,7 @@ engines:
config:
extensions:
- .es6
ignore_warnings: true
fixme:
enabled: false
rubocop:
Expand Down
11 changes: 6 additions & 5 deletions .eslintrc
@@ -1,6 +1,7 @@
ecmaFeatures:
modules: true
jsx: true
parserOptions:
sourceType: module
ecmaFeatures:
jsx: true

env:
amd: true
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
116 changes: 59 additions & 57 deletions 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
)
}
}
3 changes: 1 addition & 2 deletions 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());
Expand All @@ -22,4 +22,3 @@ export class Language {
};
}
}

2 changes: 1 addition & 1 deletion 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());
Expand Down
4 changes: 1 addition & 3 deletions 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());
Expand All @@ -22,5 +22,3 @@ export class Subject {
};
}
}


2 changes: 1 addition & 1 deletion 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;
Expand Down
26 changes: 13 additions & 13 deletions app/assets/javascripts/sufia/notifications.es6
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/sufia/permissions/control.es6
Expand Up @@ -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
Expand All @@ -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')
}
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/sufia/permissions/group_controls.es6
Expand Up @@ -56,15 +56,15 @@ export class GroupControls {
}

selectedGroupValid() {
return this.selectedGroup().index() != 0
return this.selectedGroup().index() !== 0
}

selectedGroup() {
return this.groupField.find(':selected')
}

permissionValid() {
return this.selectedPermission().index() != 0
return this.selectedPermission().index() !== 0
}

selectedPermission() {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/sufia/permissions/user_controls.es6
Expand Up @@ -60,19 +60,19 @@ export class UserControls {
}

selectedUserIsDepositor() {
return this.userName() == this.depositor
return this.userName() === this.depositor
}

userValid() {
return this.userNameValid() && this.permissionValid()
}

userNameValid() {
return this.userName() != ""
return this.userName() !== ""
}

permissionValid() {
return this.selectedPermission().index() != 0
return this.selectedPermission().index() !== 0
}

selectedPermission() {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/sufia/relationships/table.es6
Expand Up @@ -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.");
Expand Down Expand Up @@ -104,15 +104,15 @@ 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();
return false;
}

// 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);
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/sufia/save_work/required_fields.es6
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit 8ad4cf1

Please sign in to comment.