Skip to content

Commit

Permalink
applied lint suggested code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
aferditamuriqi committed Apr 13, 2021
1 parent a6ec949 commit 34f5d4d
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 271 deletions.
18 changes: 9 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@ module.exports = {
extends: [
// extends from the create-react-app prettier config, which
// is not react-specific, but just a good set of defaults
'react-app',
"react-app",
// this disables the errors that prettier fixes automatically
// and runs prettier as part of eslint --fix
'plugin:prettier/recommended',
"plugin:prettier/recommended",
],
settings: {
react: {
// Fix for a warning coming from the react-app config when there is
// no react installed.
version: '999.999.999',
version: "999.999.999",
},
},
rules: {
// allow unused vars and params that start with an underscore: _unused
'@typescript-eslint/no-unused-vars': [
'error',
"@typescript-eslint/no-unused-vars": [
"error",
{
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
// turn off the disallowing of "use-strict"
strict: 0,
// turn this off for now, but we should throw errors in the future
'no-throw-literal': 0,
"no-throw-literal": 0,
},
};
4 changes: 2 additions & 2 deletions injectables/footnotes/footnotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ document.addEventListener(

var link = element.querySelector("a");
if (link) {
var attribute = link.getAttribute("epub:type") == "noteref";
var attribute = link.getAttribute("epub:type") === "noteref";
if (attribute) {
var href = link.getAttribute("href");
if (href.indexOf("#") > 0) {
Expand Down Expand Up @@ -77,7 +77,7 @@ document.addEventListener(
};

window.onclick = function (event) {
if (event.target == modal) {
if (event.target === modal) {
modal.style.display = "none";
modal.parentElement.removeChild(modal);
}
Expand Down
2 changes: 1 addition & 1 deletion injectables/glossary/glossary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function markCuedWords(glossary: Array<GlossaryItem>) {
};

window.onclick = function (event) {
if (event.target == modal) {
if (event.target === modal) {
modal.style.display = "none";
modal.parentElement.removeChild(modal);
}
Expand Down
30 changes: 16 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ export async function currentSettings() {
}
export async function increase(incremental) {
if (
(incremental == "pitch" ||
incremental == "rate" ||
incremental == "volume") &&
(incremental === "pitch" ||
incremental === "rate" ||
incremental === "volume") &&
oc(R2Navigator.rights).enableTTS(false)
) {
if (IS_DEV) {
Expand All @@ -259,9 +259,9 @@ export async function increase(incremental) {
}
export async function decrease(incremental) {
if (
(incremental == "pitch" ||
incremental == "rate" ||
incremental == "volume") &&
(incremental === "pitch" ||
incremental === "rate" ||
incremental === "volume") &&
oc(R2Navigator.rights).enableTTS(false)
) {
if (IS_DEV) {
Expand Down Expand Up @@ -410,7 +410,7 @@ export async function load(config: ReaderConfig): Promise<any> {
if (
(oc(config.protection).enforceSupportedBrowsers(false) &&
supportedBrowsers.test(navigator.userAgent)) ||
oc(config.protection).enforceSupportedBrowsers(false) == false
oc(config.protection).enforceSupportedBrowsers(false) === false
) {
var mainElement = document.getElementById("D2Reader-Container");
var headerMenu = document.getElementById("headerMenu");
Expand All @@ -436,7 +436,7 @@ export async function load(config: ReaderConfig): Promise<any> {
store
);

if (oc(publication.metadata.rendition).layout("unknown") == "fixed") {
if (oc(publication.metadata.rendition).layout("unknown") === "fixed") {
config.rights.enableAnnotations = false;
config.rights.enableSearch = false;
config.rights.enableTTS = false;
Expand All @@ -448,7 +448,7 @@ export async function load(config: ReaderConfig): Promise<any> {
var totalContentLength = 0;
var positions = [];
publication.readingOrder.map(async (link, index) => {
if (oc(publication.metadata.rendition).layout("unknown") == "fixed") {
if (oc(publication.metadata.rendition).layout("unknown") === "fixed") {
const locator: Locator = {
href: link.href,
locations: {
Expand Down Expand Up @@ -485,8 +485,10 @@ export async function load(config: ReaderConfig): Promise<any> {
startPosition = startPosition + positionCount;
});
}
if (index + 1 == publication.readingOrder.length) {
if (oc(publication.metadata.rendition).layout("unknown") != "fixed") {
if (index + 1 === publication.readingOrder.length) {
if (
oc(publication.metadata.rendition).layout("unknown") !== "fixed"
) {
publication.readingOrder.map(async (link) => {
if (IS_DEV) console.log(totalContentLength);
if (IS_DEV) console.log(link.contentLength);
Expand Down Expand Up @@ -525,7 +527,7 @@ export async function load(config: ReaderConfig): Promise<any> {
material: config.material,
api: config.api,
layout:
oc(publication.metadata.rendition).layout("unknown") == "fixed"
oc(publication.metadata.rendition).layout("unknown") === "fixed"
? "fixed"
: "reflowable",
});
Expand All @@ -545,14 +547,14 @@ export async function load(config: ReaderConfig): Promise<any> {
rights: config.rights,
tts: config.tts,
injectables:
oc(publication.metadata.rendition).layout("unknown") == "fixed"
oc(publication.metadata.rendition).layout("unknown") === "fixed"
? []
: config.injectables,
attributes: config.attributes,
});

// Highlighter
if (oc(publication.metadata.rendition).layout("unknown") != "fixed") {
if (oc(publication.metadata.rendition).layout("unknown") !== "fixed") {
D2Highlighter = await TextHighlighter.create({
delegate: R2Navigator,
config: config.highlighter,
Expand Down
59 changes: 31 additions & 28 deletions src/model/user-settings/UserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class UserSettings implements IUserSettings {
(el: any) => el === initialUserSettings.fontFamily
);
if (IS_DEV) console.log(settings.fontFamily);
if (settings.fontFamily != 0) {
if (settings.fontFamily !== 0) {
settings.fontOverride = true;
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ export class UserSettings implements IUserSettings {
this.store = store;

this.view =
layout == "fixed"
layout === "fixed"
? new FixedBookView(this.store)
: new ReflowableBookView(this.store);

Expand Down Expand Up @@ -283,7 +283,7 @@ export class UserSettings implements IUserSettings {
? ((await this.getProperty(ReadiumCSS.FONT_FAMILY_KEY)) as Enumerable)
.value
: this.fontFamily;
if (this.fontFamily != 0) {
if (this.fontFamily !== 0) {
this.fontOverride = true;
}
this.publisherDefaults =
Expand Down Expand Up @@ -414,8 +414,9 @@ export class UserSettings implements IUserSettings {

async applyProperties(): Promise<any> {
if (
oc(this.view.delegate.publication.metadata.rendition).layout("unknown") !=
"fixed"
oc(this.view.delegate.publication.metadata.rendition).layout(
"unknown"
) !== "fixed"
) {
const html = HTMLUtilities.findRequiredIframeElement(
this.iframe.contentDocument,
Expand Down Expand Up @@ -523,17 +524,17 @@ export class UserSettings implements IUserSettings {
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).toString()
);
if (
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).value == 0
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).value === 0
) {
HTMLUtilities.setAttr(rootElement, "data-viewer-theme", "day");
HTMLUtilities.setAttr(body, "data-viewer-theme", "day");
} else if (
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).value == 1
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).value === 1
) {
HTMLUtilities.setAttr(rootElement, "data-viewer-theme", "sepia");
HTMLUtilities.setAttr(body, "data-viewer-theme", "sepia");
} else if (
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).value == 2
this.userProperties.getByRef(ReadiumCSS.APPEARANCE_REF).value === 2
) {
HTMLUtilities.setAttr(rootElement, "data-viewer-theme", "night");
HTMLUtilities.setAttr(body, "data-viewer-theme", "night");
Expand All @@ -553,23 +554,23 @@ export class UserSettings implements IUserSettings {
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).toString()
);
if (
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).value == 0
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).value === 0
) {
HTMLUtilities.setAttr(html, "data-viewer-font", "publisher");
html.style.setProperty(
ReadiumCSS.FONT_OVERRIDE_KEY,
"readium-font-off"
);
} else if (
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).value == 1
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).value === 1
) {
HTMLUtilities.setAttr(html, "data-viewer-font", "serif");
html.style.setProperty(
ReadiumCSS.FONT_OVERRIDE_KEY,
"readium-font-on"
);
} else if (
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).value == 2
this.userProperties.getByRef(ReadiumCSS.FONT_FAMILY_REF).value === 2
) {
HTMLUtilities.setAttr(html, "data-viewer-font", "sans");
html.style.setProperty(
Expand Down Expand Up @@ -600,7 +601,9 @@ export class UserSettings implements IUserSettings {
}

if (await this.getProperty(ReadiumCSS.SCROLL_KEY)) {
if (this.userProperties.getByRef(ReadiumCSS.SCROLL_REF).value == true) {
if (
this.userProperties.getByRef(ReadiumCSS.SCROLL_REF).value === true
) {
html.style.setProperty("--USER__scroll", "readium-scroll-on");
} else {
html.style.setProperty("--USER__scroll", "readium-scroll-off");
Expand Down Expand Up @@ -1077,7 +1080,7 @@ export class UserSettings implements IUserSettings {
if (savedProperties) {
let array = JSON.parse(savedProperties);
array = array.filter((el: any) => el.name !== property.name);
if (property.value != undefined) {
if (property.value !== undefined) {
array.push(property);
}
await this.store.set(this.USERSETTINGS, JSON.stringify(array));
Expand All @@ -1094,7 +1097,7 @@ export class UserSettings implements IUserSettings {
if (array) {
let properties = JSON.parse(array) as Array<UserProperty>;
properties = properties.filter((el: UserProperty) => el.name === name);
if (properties.length == 0) {
if (properties.length === 0) {
return null;
}
return properties[0];
Expand Down Expand Up @@ -1140,18 +1143,18 @@ export class UserSettings implements IUserSettings {
if (userSettings.appearance) {
var a: string;
if (
userSettings.appearance == "day" ||
userSettings.appearance == "readium-default-on"
userSettings.appearance === "day" ||
userSettings.appearance === "readium-default-on"
) {
a = UserSettings.appearanceValues[0];
} else if (
userSettings.appearance == "sepia" ||
userSettings.appearance == "readium-sepia-on"
userSettings.appearance === "sepia" ||
userSettings.appearance === "readium-sepia-on"
) {
a = UserSettings.appearanceValues[1];
} else if (
userSettings.appearance == "night" ||
userSettings.appearance == "readium-night-on"
userSettings.appearance === "night" ||
userSettings.appearance === "readium-night-on"
) {
a = UserSettings.appearanceValues[2];
} else {
Expand Down Expand Up @@ -1309,28 +1312,28 @@ export class UserSettings implements IUserSettings {
}

async increase(incremental): Promise<void> {
if (incremental == "fontSize") {
if (incremental === "fontSize") {
(this.userProperties.getByRef(
ReadiumCSS.FONT_SIZE_REF
) as Incremental).increment();
this.storeProperty(
this.userProperties.getByRef(ReadiumCSS.FONT_SIZE_REF)
);
} else if (incremental == "letterSpacing") {
} else if (incremental === "letterSpacing") {
(this.userProperties.getByRef(
ReadiumCSS.LETTER_SPACING_REF
) as Incremental).increment();
this.storeProperty(
this.userProperties.getByRef(ReadiumCSS.LETTER_SPACING_REF)
);
} else if (incremental == "wordSpacing") {
} else if (incremental === "wordSpacing") {
(this.userProperties.getByRef(
ReadiumCSS.WORD_SPACING_REF
) as Incremental).increment();
this.storeProperty(
this.userProperties.getByRef(ReadiumCSS.WORD_SPACING_REF)
);
} else if (incremental == "lineHeight") {
} else if (incremental === "lineHeight") {
(this.userProperties.getByRef(
ReadiumCSS.LINE_HEIGHT_REF
) as Incremental).increment();
Expand All @@ -1343,28 +1346,28 @@ export class UserSettings implements IUserSettings {
}

async decrease(incremental): Promise<void> {
if (incremental == "fontSize") {
if (incremental === "fontSize") {
(this.userProperties.getByRef(
ReadiumCSS.FONT_SIZE_REF
) as Incremental).decrement();
this.storeProperty(
this.userProperties.getByRef(ReadiumCSS.FONT_SIZE_REF)
);
} else if (incremental == "letterSpacing") {
} else if (incremental === "letterSpacing") {
(this.userProperties.getByRef(
ReadiumCSS.LETTER_SPACING_REF
) as Incremental).decrement();
this.storeProperty(
this.userProperties.getByRef(ReadiumCSS.LETTER_SPACING_REF)
);
} else if (incremental == "wordSpacing") {
} else if (incremental === "wordSpacing") {
(this.userProperties.getByRef(
ReadiumCSS.WORD_SPACING_REF
) as Incremental).decrement();
this.storeProperty(
this.userProperties.getByRef(ReadiumCSS.WORD_SPACING_REF)
);
} else if (incremental == "lineHeight") {
} else if (incremental === "lineHeight") {
(this.userProperties.getByRef(
ReadiumCSS.LINE_HEIGHT_REF
) as Incremental).decrement();
Expand Down
Loading

0 comments on commit 34f5d4d

Please sign in to comment.