Skip to content

Commit

Permalink
feat: added eslint eqeqeq rule, closes internetarchive#5238 (internet…
Browse files Browse the repository at this point in the history
…archive#5614)

* chore: add eslint eqeqeq rule

Signed-off-by: Anik Das <[email protected]>

* fix: === in place of == from eslint

changed != to !== as well. some vue components also used == in v-if
which did not show up in eslint for some reason? changed them as well

Signed-off-by: Anik Das <[email protected]>
  • Loading branch information
sadn1ck authored Sep 3, 2021
1 parent 1de68f0 commit 3240d52
Show file tree
Hide file tree
Showing 40 changed files with 198 additions and 197 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"globals": {},
"rules": {
"prefer-template": "error",
"eqeqeq": ["error", "always"],
"quotes": ["error", "single"],
"eol-last": ["error", "always"],
"indent": 2,
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/components/LibraryExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default {
let jumpTo = null;
if (urlParams.has('jumpTo')) {
const [classificationName, classificationString] = urlParams.get('jumpTo').split(':');
selectedClassification = classifications.find(c => c.field == classificationName);
selectedClassification = classifications.find(c => c.field === classificationName);
jumpTo = selectedClassification.toQueryFormat(classificationString);
}
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="book-room" :class="{'expanding-animation': expandingAnimation}">
<!-- <div class="room-breadcrumbs">
<span v-for="(node, i) of breadcrumbs" :key="i">
<button @click="goUpTo(i)">{{i == 0 ? 'Home' : node.name}}</button>
<button @click="goUpTo(i)">{{i === 0 ? 'Home' : node.name}}</button>
&gt;
</span>
<span v-if="breadcrumbs.length">{{activeRoom.name}}</span>
Expand Down Expand Up @@ -177,7 +177,7 @@ export default {
});
// Find the offset of the predecessor of the requested item in its shelf
const predecessor = decrementStringSolr(this.jumpToData.classification, false, this.classification.field == 'ddc');
const predecessor = decrementStringSolr(this.jumpToData.classification, false, this.classification.field === 'ddc');
const shelf_query = `${this.classification.field}_sort:${this.jumpToData.shelf.query} ${this.filter}`;
/** @type {number} */
const offset = await fetch(`${CONFIGS.OL_BASE_SEARCH}/search.json?${new URLSearchParams({
Expand Down Expand Up @@ -219,7 +219,7 @@ export default {
this.expandingAnimation = false;
this.breadcrumbs.push(this.activeRoom);
this.activeRoom = bookshelf;
const nodeToScrollTo = shelf?.position == 'root' ? shelf :
const nodeToScrollTo = shelf?.position === 'root' ? shelf :
shelf?.children && shelf?.position ? shelf.children[shelf.position]
: (shelf || bookshelf);
await Vue.nextTick();
Expand All @@ -240,7 +240,7 @@ export default {
this.roomWidth = max(1, this.$el.querySelector('.book-room-shelves').scrollWidth);
this.viewportWidth = max(1, this.$el.getBoundingClientRect().width);
if (this.roomWidth == 1 || this.viewportWidth == 1) {
if (this.roomWidth === 1 || this.viewportWidth === 1) {
setTimeout(this.updateWidths, 100);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
watch: {
async index(newVal, oldVal) {
if (typeof oldVal != 'number') return;
if (typeof oldVal !== 'number') return;
this.direction = newVal > oldVal ? 'slide-right' : 'slide-left';
await new Promise(res => setTimeout(res, 200));
this.direction = null;
Expand All @@ -53,10 +53,10 @@ export default {
computed: {
index: {
get() {
return this.node.position == 'root' ? 0 : this.node.position + 1;
return this.node.position === 'root' ? 0 : this.node.position + 1;
},
set(newVal) {
this.node.position = newVal == 0 ? 'root' : newVal - 1;
this.node.position = newVal === 0 ? 'root' : newVal - 1;
}
},
sections() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<img
v-if="cover == 'image' && coverMultiresUrl"
v-if="cover === 'image' && coverMultiresUrl"
class="cover"
loading="lazy"
@load="$emit('load', $event)"
Expand Down Expand Up @@ -37,7 +37,7 @@ export default {
coverMultiresUrl() {
const { cover_i, lending_edition_s } = this.book;
const fullUrl = lending_edition_s ? this.olCoverUrl(lending_edition_s, 'olid') :
cover_i && cover_i != -1 ? this.olCoverUrl(cover_i) :
cover_i && cover_i !== -1 ? this.olCoverUrl(cover_i) :
null;
if (fullUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ export default {
watch: {
quickLanguageSelect(newVal) {
if (newVal == '') this.filterState.languages = [];
else if (newVal == 'custom') this.filterState.languages = this.fullLanguageSelect;
if (newVal === '') this.filterState.languages = [];
else if (newVal === 'custom') this.filterState.languages = this.fullLanguageSelect;
else this.filterState.languages = [newVal];
},
Expand Down Expand Up @@ -282,7 +282,7 @@ export default {
computedFilters() {
const parts = this.filterState.solrQueryParts();
const computedParts = parts[0] == this.filterState.filter ? parts.slice(1) : parts;
const computedParts = parts[0] === this.filterState.filter ? parts.slice(1) : parts;
return computedParts.length ? ` AND ${computedParts.join(' AND ')}` : '';
},
Expand All @@ -295,7 +295,7 @@ export default {
},
inDebugMode() {
return new URLSearchParams(location.search).get('debug') == 'true';
return new URLSearchParams(location.search).get('debug') === 'true';
},
styles() {
Expand Down Expand Up @@ -323,7 +323,7 @@ export default {
toggleTab(tabName) {
const index = this.openTabs.indexOf(tabName);
if (index == -1) {
if (index === -1) {
this.openTabs.push(tabName);
if (this.openTabs.length > this.maxTabs) {
this.openTabs.shift();
Expand Down
16 changes: 8 additions & 8 deletions openlibrary/components/LibraryExplorer/components/OLCarousel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="ol-carousel">
<BooksCarousel v-if="status == 'Loaded' || results.length" :books="results">
<BooksCarousel v-if="status === 'Loaded' || results.length" :books="results">
<template v-slot:cover-label="{book}">
<slot name="cover-label" v-bind:book="book"/>
</template>
Expand All @@ -13,23 +13,23 @@
<slot name="book-end-start"/>
<div class="book-end" v-if="offset > 0">
<small>{{offset}}-{{offset + results.length}} of {{numFound}}</small>
<button class="load-more" @click="loadPrevPage" :disabled="offset == 0">Load previous</button>
<button class="load-more" @click="loadPrevPage" :disabled="offset === 0">Load previous</button>
<a class="view-all" :href="olUrl" target="_blank">View all</a>
</div>
</template>
<template #book-end>
<div class="book-end">
<small>{{offset}}-{{offset + results.length}} of {{numFound}}</small>
<button class="load-more" @click="loadNextPage" :disabled="offset + results.length == numFound">Load next</button>
<button class="load-more" @click="loadNextPage" :disabled="offset + results.length === numFound">Load next</button>
<a class="view-all" :href="olUrl" target="_blank">View all</a>
</div>
</template>
</BooksCarousel>
<transition>
<div class="status-text" v-if="status == 'Errored'">Something went wrong... <button @click="reloadResults('reload')">Retry</button></div>
<div class="status-text" v-if="status === 'Errored'">Something went wrong... <button @click="reloadResults('reload')">Retry</button></div>
</transition>
<transition>
<div class="status-text" v-if="status == 'Loading'">Loading...</div>
<div class="status-text" v-if="status === 'Loading'">Loading...</div>
</transition>
</div>
</template>
Expand Down Expand Up @@ -61,7 +61,7 @@ class CarouselCoordinator {
registerOnscreenCarousel(carousel) {
const index = this.currentlyRenderedOffscreen.indexOf(carousel);
if (index != -1) {
if (index !== -1) {
// console.log('CarouselCoordinator', `Carousel no longer offscreen -- ${carousel.query}`);
this.currentlyRenderedOffscreen.splice(index, 1);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ export default {
async loadResults(offset, cache='force-cache') {
// Don't re-fetch if already there
if (offset == this.offset && this.results.length) return;
if (offset === this.offset && this.results.length) return;
this.lastFetchAbortController?.abort();
if ('AbortController' in window) this.lastFetchAbortController = new AbortController();
Expand Down Expand Up @@ -230,7 +230,7 @@ export default {
async _loadOffset(newOffset) {
await this.loadResults(newOffset);
if (this.status == 'Loaded') this.offset = newOffset;
if (this.status === 'Loaded') this.offset = newOffset;
},
async loadPageContainingOffset(offset) {
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/components/LibraryExplorer/components/Shelf.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
class="shelf-label"
:node="node"
:key="node.short"
:is="features.shelfLabel == 'slider' ? 'ClassSlider' : 'ShelfLabel'"
:is="features.shelfLabel === 'slider' ? 'ClassSlider' : 'ShelfLabel'"
>
<template #extra-actions>
<button
:title="`See a list of the subsections of ${node.short}: ${node.name}`"
v-if="features.shelfLabel == 'slider' && node.children"
v-if="features.shelfLabel === 'slider' && node.children"
:class="{selected: showShelfIndex}"
@click="showShelfIndex = !showShelfIndex"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ol class="shelf-label--subclasses">
<li>
<a
:class="{ selected: index == 'root' }"
:class="{ selected: index === 'root' }"
href="#"
@click.prevent="index = 'root'"
>
Expand All @@ -13,7 +13,7 @@
</li>
<li v-for="(child, i) of node.children || []" :key="i">
<a
:class="{ selected: index == i }"
:class="{ selected: index === i }"
href="#"
@click.prevent="index = i"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<details class="shelf-label--classes">
<summary>
<RightArrowIcon class="shelf-label--right-arrow"/>
<div class="shelf-label--name">{{index == 'root' ? node.name : node.children[index].name}}</div>
<div class="shelf-label--name">{{index === 'root' ? node.name : node.children[index].name}}</div>
</summary>
<ShelfIndex :node="node" />
</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
:key="section.short"
:title="section.name"
:style="{ flex: section.count }"
:class="{ active: index == i }"
:class="{ active: index === i }"
>
<div
v-if="index == i"
v-if="index === i"
class="marker"
:style="{ left: `${(100 * section.offset) / section.count}%` }"
></div>
Expand Down
4 changes: 2 additions & 2 deletions openlibrary/components/LibraryExplorer/configs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const urlParams = new URLSearchParams(location.search);

const IS_VUE_APP = document.title == 'Vue App';
const IS_VUE_APP = document.title === 'Vue App';
const OL_BASE_DEFAULT = urlParams.get('ol_base') || (IS_VUE_APP ? 'openlibrary.org' : '');

const CONFIGS = {
Expand All @@ -9,7 +9,7 @@ const CONFIGS = {
OL_BASE_BOOKS: urlParams.get('ol_base_books') || OL_BASE_DEFAULT || '',
OL_BASE_LANGS: urlParams.get('ol_base_langs') || OL_BASE_DEFAULT || '',
OL_BASE_PUBLIC: urlParams.get('ol_base') || 'openlibrary.org',
DEBUG_MODE: urlParams.get('debug') == 'true',
DEBUG_MODE: urlParams.get('debug') === 'true',
};

for (const key of ['OL_BASE_COVERS', 'OL_BASE_SEARCH', 'OL_BASE_BOOKS', 'OL_BASE_LANGS']) {
Expand Down
8 changes: 4 additions & 4 deletions openlibrary/components/LibraryExplorer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export function decrementStringSolr(string, caseSensitive=true, numeric=false) {
// Also append Z; this is the equivalent of going back one, and then expanding (e.g. 0.123 decremented is not 0.122, it's 0.12999999)
const maxTail = (numeric ? '9' : 'z').repeat(5);
const newLastChar = (
lastChar == '.' ? '' :
lastChar == '0' ? `.${maxTail}` :
lastChar == 'A' ? `9${maxTail}` :
lastChar == 'a' ? `Z${maxTail}` :
lastChar === '.' ? '' :
lastChar === '0' ? `.${maxTail}` :
lastChar === 'A' ? `9${maxTail}` :
lastChar === 'a' ? `Z${maxTail}` :
`${String.fromCharCode(lastChar.charCodeAt(0) - 1)}${maxTail}`);

return string.slice(0, -1) + newLastChar;
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/components/LibraryExplorer/utils/lcc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function short_lcc_to_sortable_lcc(lcc) {
// E.g. "CPB Box no. 1516 vol. 17"
// Although this might be useful to search by, it's not really an LCC,
// so considering it invalid here.
if (letters == 'CPB') return null;
if (letters === 'CPB') return null;

return `${letters}${number.toFixed(8).padStart(13, '0')}${cutter1}${rest}`;
}
Expand Down
6 changes: 3 additions & 3 deletions openlibrary/plugins/openlibrary/js/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class SearchBar {

if (urlParams.q) {
let q = urlParams.q.replace(/\+/g, ' ');
if (this.facet.read() === 'title' && q.indexOf('title:') != -1) {
if (this.facet.read() === 'title' && q.indexOf('title:') !== -1) {
const parts = q.split('"');
if (parts.length === 3) {
q = parts[1];
Expand Down Expand Up @@ -220,7 +220,7 @@ export class SearchBar {
* @return {String}
*/
static marshalBookSearchQuery(q) {
if (q && q.indexOf(':') == -1 && q.indexOf('"') == -1) {
if (q && q.indexOf(':') === -1 && q.indexOf('"') === -1) {
q = `title: "${q}"`;
}
return q;
Expand Down Expand Up @@ -299,7 +299,7 @@ export class SearchBar {
handleFacetSelectChange(event) {
const newFacet = event.target.value;
// We don't want to persist advanced becaues it behaves like a button
if (newFacet == 'advanced') {
if (newFacet === 'advanced') {
event.preventDefault();
this.navigateTo('/advancedsearch');
} else {
Expand Down
10 changes: 5 additions & 5 deletions openlibrary/plugins/openlibrary/js/SearchUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class PersistentValue {
this.options = Object.assign({}, PersistentValue.DEFAULT_OPTIONS, options);
this._listeners = [];

const noValue = this.read() == null;
const noValue = this.read() === null;
const isValid = () => !this.options.initValidation || this.options.initValidation(this.read());
if (noValue || !isValid()) {
this.write(this.options.default);
Expand All @@ -76,13 +76,13 @@ export class PersistentValue {
toWrite = this.options.writeTransformation(newValue, oldValue);
}

if (toWrite == null) {
if (toWrite === null) {
localStorage.removeItem(this.key);
} else {
localStorage.setItem(this.key, toWrite);
}

if (oldValue != toWrite) {
if (oldValue !== toWrite) {
this._emit(toWrite);
}
}
Expand Down Expand Up @@ -120,10 +120,10 @@ const DEFAULT_MODE = 'everything';
/** Search mode; {@see MODES} */
export const mode = new PersistentValue('mode', {
default: DEFAULT_MODE,
initValidation: mode => MODES.indexOf(mode) != -1,
initValidation: mode => MODES.indexOf(mode) !== -1,
writeTransformation(newValue, oldValue) {
const mode = (newValue && newValue.toLowerCase()) || oldValue;
const isValidMode = MODES.indexOf(mode) != -1;
const isValidMode = MODES.indexOf(mode) !== -1;
return isValidMode ? mode : DEFAULT_MODE;
}
});
Expand Down
6 changes: 3 additions & 3 deletions openlibrary/plugins/openlibrary/js/add_new_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function($){

$this.on('change', function(){
var value = $this.val();
if (value == '__add__') {
if (value === '__add__') {
if (options.onshow) {
options.onshow.apply($this, []);
}
Expand All @@ -45,7 +45,7 @@ export default function($){
// handle cancel
$href.on('cbox_closed', function() {

if ($this.val() == '__add__') {
if ($this.val() === '__add__') {
$this.val('');
$this.trigger('focus');
}
Expand All @@ -68,7 +68,7 @@ export default function($){
}

// validate
if (options.validate && options.validate.apply($this, [d]) == false) {
if (options.validate && options.validate.apply($this, [d]) === false) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions openlibrary/plugins/openlibrary/js/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const Carousel = {
const availabilityStatus = availabilityStatuses[availability.status] || availabilityStatuses.error;
const cls = availabilityStatus.cls;
const cta = availabilityStatus.cta;
const url = cls == 'cta-btn--available' ? `/borrow/ia/${ocaid}` : work.key;
const url = cls === 'cta-btn--available' ? `/borrow/ia/${ocaid}` : work.key;

if (!cover.id && ocaid) {
cover.type = 'ia';
Expand Down Expand Up @@ -151,7 +151,7 @@ const Carousel = {
loadMore.locked = true; // lock for critical section
slick.addSlide('<div class="carousel__item carousel__loading-end">Loading...</div>');

if (loadMore.pageMode == 'page') {
if (loadMore.pageMode === 'page') {
// for first time, we're on page 1 already so initialize as page 2
// otherwise advance to next page
loadMore.page = loadMore.page ? loadMore.page + 1 : 2;
Expand Down
Loading

0 comments on commit 3240d52

Please sign in to comment.