diff --git a/src/.eslintrc.json b/src/.eslintrc.json index eaf27277..24a7b322 100644 --- a/src/.eslintrc.json +++ b/src/.eslintrc.json @@ -7,6 +7,8 @@ "sourceType": "module", "project": "./tsconfig.json" // <-- Point to your project's "tsconfig.json" or create a new one. }, + + "plugins": ["unused-imports"], "overrides": [ { "files": ["*.ts"], @@ -35,6 +37,17 @@ "prefix": "app", "style": "kebab-case" } + ], + "no-unused-vars": "off", // or "@typescript-eslint/no-unused-vars": "off", + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ + "warn", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_" + } ] } }, diff --git a/src/package-lock.json b/src/package-lock.json index 2991966b..efd22eae 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -54,6 +54,7 @@ "cypress": "latest", "eslint": "^8.57.0", "eslint-plugin-deprecation": "^2.0.0", + "eslint-plugin-unused-imports": "^3.1.0", "firebase-tools": "^13.4.0", "fuzzy": "^0.1.3", "inquirer": "^9.2.15", @@ -11979,6 +11980,36 @@ "typescript": "^4.2.4 || ^5.0.0" } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.1.0.tgz", + "integrity": "sha512-9l1YFCzXKkw1qtAru1RWUtG2EVDZY0a0eChKXcL+EZ5jitG7qxdctu4RnvhOJHv4xfmUf7h+JJPINlVpGhZMrw==", + "dev": true, + "dependencies": { + "eslint-rule-composer": "^0.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "6 - 7", + "eslint": "8" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, + "node_modules/eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/eslint-scope": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.0.tgz", diff --git a/src/package.json b/src/package.json index 1a3a68db..bbc7a4c8 100644 --- a/src/package.json +++ b/src/package.json @@ -62,6 +62,7 @@ "cypress": "latest", "eslint": "^8.57.0", "eslint-plugin-deprecation": "^2.0.0", + "eslint-plugin-unused-imports": "^3.1.0", "firebase-tools": "^13.4.0", "fuzzy": "^0.1.3", "inquirer": "^9.2.15", diff --git a/src/src/app/common/bible-reference.ts b/src/src/app/common/bible-reference.ts index 2277039d..fd856070 100644 --- a/src/src/app/common/bible-reference.ts +++ b/src/src/app/common/bible-reference.ts @@ -924,7 +924,7 @@ export class BibleReference { if (this.ref.length === 0) { return; } - this.parseBook(false); + this.parseBook(); this.parseChapter(false); const foundFirstVerse = this.ref.search(/:.*-/) !== -1; @@ -932,7 +932,7 @@ export class BibleReference { this.maybeParseRangeSep(); const foundSecondBook = this.ref.search(/\w\s+\d/i) !== -1; - this.maybeParseBook(true); + this.maybeParseBook(); this.maybeParseChapterOrVerse(foundSecondBook, foundFirstVerse, true); this.maybeParseVerse(true); } @@ -958,7 +958,7 @@ export class BibleReference { } } - private parseBook(isEnd?: boolean) { + private parseBook() { this.ref = this.ref.toLowerCase().trim(); let fbook = this.ref.substring(0, this.ref.search(/\w\s+\d/i) + 1); @@ -1039,10 +1039,10 @@ export class BibleReference { } } - private maybeParseBook(isEnd: boolean) { + private maybeParseBook() { return this.maybeDo(() => { if (this.ref.search(/\w\s+\d/i) !== -1) { - this.parseBook(isEnd); + this.parseBook(); } }); } diff --git a/src/src/app/common/card-cache-operations.spec.ts b/src/src/app/common/card-cache-operations.spec.ts index 80d6c53e..ac2b0a67 100644 --- a/src/src/app/common/card-cache-operations.spec.ts +++ b/src/src/app/common/card-cache-operations.spec.ts @@ -48,16 +48,6 @@ describe('Card Cache', () => { type: CardType.Passage, data: null, }; - const card2: CardItem = { - qry: 'jason', - type: CardType.Passage, - data: { - id: 'adsf', - xref: '', - title: 'adsf', - content: '', - } as NoteItem, - }; const card3: CardItem = { qry: 'jason3', type: CardType.Passage, diff --git a/src/src/app/components/saved-page-card/saved-page-card.component.ts b/src/src/app/components/saved-page-card/saved-page-card.component.ts index 62fcd476..3c8b9e2a 100644 --- a/src/src/app/components/saved-page-card/saved-page-card.component.ts +++ b/src/src/app/components/saved-page-card/saved-page-card.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { CdkDragDrop } from '@angular/cdk/drag-drop'; import { MatDialog } from '@angular/material/dialog'; import { Observable } from 'rxjs'; diff --git a/src/src/app/components/settings/settings.component.ts b/src/src/app/components/settings/settings.component.ts index 1c42b4dc..7e1954a8 100644 --- a/src/src/app/components/settings/settings.component.ts +++ b/src/src/app/components/settings/settings.component.ts @@ -82,7 +82,7 @@ export class SettingsComponent extends SubscriberBase { const credential = firebase.auth.GoogleAuthProvider.credential(googleUser.authentication.idToken); (await this.authService.app).auth().signInWithCredential(credential); } else { - this.authService.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then((cred) => { + this.authService.signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(() => { console.log('Authenticated.'); }); } diff --git a/src/src/app/components/strongs/modal/strongs-modal.component.ts b/src/src/app/components/strongs/modal/strongs-modal.component.ts index 6182bf3d..878f1b25 100644 --- a/src/src/app/components/strongs/modal/strongs-modal.component.ts +++ b/src/src/app/components/strongs/modal/strongs-modal.component.ts @@ -1,6 +1,5 @@ -import { Component, Inject, ChangeDetectionStrategy, Input } from '@angular/core'; +import { Component, Inject, ChangeDetectionStrategy } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { MatTabsModule } from '@angular/material/tabs'; import { Observable } from 'rxjs'; import { BibleReference } from 'src/app/common/bible-reference'; import { CardItem } from 'src/app/models/card-state'; diff --git a/src/src/app/services/app-state-reducer.spec.ts b/src/src/app/services/app-state-reducer.spec.ts index e51e6411..adcb4087 100644 --- a/src/src/app/services/app-state-reducer.spec.ts +++ b/src/src/app/services/app-state-reducer.spec.ts @@ -8,7 +8,7 @@ import { getCardCacheKey } from '../common/card-cache-operations'; import { MoveDirection } from '../common/move-direction'; import { NoteItem } from '../models/note-state'; import { - addCardAction, + addCardsAction, addCardToSavedPageAction, deleteNoteAction, findNotesAction, @@ -273,7 +273,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const testState = addCardAction(card1, null).handle(preState); + const testState = addCardsAction([card1], null).handle(preState); expect(testState.currentCards.value[0]).toBe(card1, 'Failed to add first card to empty list'); const testState2 = updateCurrentPageAction().handle(testState); @@ -289,7 +289,7 @@ describe('AppService Reducer', () => { type: CardType.Passage, }; - const preState2 = addCardAction(card1, null).handle(preState); + const preState2 = addCardsAction([card1], null).handle(preState); const testState = savePageAction('my saved page').handle(preState2); @@ -328,7 +328,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const testState = addCardAction(card1, null).handle(preState); + const testState = addCardsAction([card1], null).handle(preState); expect(testState.currentCards.value[0]).toBe(card1, 'Failed to add first card to empty list'); const card2: CardItem = { @@ -337,7 +337,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const testState2 = addCardAction(card2, null).handle(testState); + const testState2 = addCardsAction([card2], null).handle(testState); expect(testState2.currentCards.value.length).toBe(2, 'Failed to add second card to list with 1 item'); expect(testState2.currentCards.value[1]).toBe(card2); @@ -370,7 +370,7 @@ describe('AppService Reducer', () => { }, }).handle(testState2); - const testState3 = addCardAction(card3, card2).handle(setState); + const testState3 = addCardsAction([card3], card2).handle(setState); expect(testState3.currentCards.value.length).toBe(3, 'Failed to add third card'); expect(testState3.currentCards.value[1]).toBe(card3, 'Failed to insert card above the second card'); @@ -397,7 +397,7 @@ describe('AppService Reducer', () => { }, }).handle(testState2); - const testState4 = addCardAction(card3, card1).handle(setState); + const testState4 = addCardsAction([card3], card1).handle(setState); expect(testState4.currentCards.value.length).toBe(3, 'Failed to add third card'); expect(testState4.currentCards.value[1]).toBe(card3, 'Failed to insert card below the first card'); @@ -424,7 +424,7 @@ describe('AppService Reducer', () => { }, }).handle(testState2); - const testState5 = addCardAction(card3, card1).handle(setState); + const testState5 = addCardsAction([card3], card1).handle(setState); expect(testState5.currentCards.value.length).toBe(3, 'Failed to add third card'); expect(testState5.currentCards.value[2]).toBe(card3, 'Failed to insert card at end of the list'); @@ -451,7 +451,7 @@ describe('AppService Reducer', () => { }, }).handle(testState2); - const testState6 = addCardAction(card3, card1).handle(setState); + const testState6 = addCardsAction([card3], card1).handle(setState); expect(testState6.currentCards.value.length).toBe(3, 'Failed to add third card'); expect(testState6.currentCards.value[0]).toBe(card3, 'Failed to insert card at start of the list'); }); @@ -463,7 +463,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const preState1 = addCardAction(oldCard, null).handle(preState); + const preState1 = addCardsAction([oldCard], null).handle(preState); const newCard: CardItem = { qry: 'H88', @@ -487,7 +487,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const preState1 = addCardAction(card, null).handle(preState); + const preState1 = addCardsAction([card], null).handle(preState); const testState = removeCardAction(card).handle(preState1); @@ -508,7 +508,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const preState1 = addCardAction(card1, null).handle(preState); + const preState1 = addCardsAction([card1], null).handle(preState); const card2: CardItem = { qry: 'H88', @@ -516,7 +516,7 @@ describe('AppService Reducer', () => { type: CardType.Strongs, }; - const preState2 = addCardAction(card2, null).handle(preState1); + const preState2 = addCardsAction([card2], null).handle(preState1); expect(preState2.currentCards.value.length).toBe(2, 'Should have two cards'); expect(preState2.currentCards.value[0].qry).toBe('G123'); expect(preState2.currentCards.value[1].qry).toBe('H88'); @@ -605,7 +605,4 @@ describe('AppService Reducer', () => { //#endregion }); -function newUserAction(preState: AppState, action1: any) { - throw new Error('Function not implemented.'); -} diff --git a/src/src/app/services/app.service.ts b/src/src/app/services/app.service.ts index c6c8157c..8f34227d 100644 --- a/src/src/app/services/app.service.ts +++ b/src/src/app/services/app.service.ts @@ -252,40 +252,6 @@ export const addCardToSavedPageAction = (card: CardItem, pageId: string): AppAct //#region Cards -export const addCardAction = (card: CardItem, nextToItem: CardItem): AppAction => { - return { - handle(state: AppState) { - let cards = []; - - if (nextToItem && state.settings.value.displaySettings.insertCardNextToItem) { - const idx = state.currentCards.value.indexOf(nextToItem); - - if (state.settings.value.displaySettings.appendCardToBottom) { - const before = state.currentCards.value.slice(0, idx + 1); - const after = state.currentCards.value.slice(idx + 1); - cards = [...before, card, ...after]; - } else { - const before = state.currentCards.value.slice(0, idx); - const after = state.currentCards.value.slice(idx); - cards = [...before, card, ...after]; - } - } else { - if (state.settings.value.displaySettings.appendCardToBottom) { - cards = [...state.currentCards.value, card]; - } else { - cards = [card, ...state.currentCards.value]; - } - } - - return { - ...state, - currentCards: new Storable(cards), - cardCache: updateInCardCache(card, state.cardCache), - }; - }, - }; -}; - export const addCardsAction = (cardsToAdd: CardItem[], nextToItem: CardItem): AppAction => { return { handle(state: AppState) { @@ -581,7 +547,7 @@ export const getNotesAction = (noteId: string, nextToItem: CardItem): AppAction data: note, }; - return addCardAction(card, nextToItem).handle(state); + return addCardsAction([card], nextToItem).handle(state); }, }; }; @@ -841,7 +807,7 @@ export class AppService extends createReducingService(initialState) { if (!card) { return; } - this.dispatch(addCardAction(card, nextToItem)); + this.dispatch(addCardsAction([card], nextToItem)); } async updateCards(queries: IStorable) { @@ -1122,7 +1088,7 @@ export class AppService extends createReducingService(initialState) { const rmacCrossReferences = await lastValueFrom(this.http.get(url)); // deal with RMAC - const referencesForThisStrongsNumber = rmacCrossReferences.filter((el, i) => { + const referencesForThisStrongsNumber = rmacCrossReferences.filter((el) => { return el.i === sn.toString(); }); @@ -1161,7 +1127,7 @@ export class AppService extends createReducingService(initialState) { return; // nothing was returned. so an error occurred. } - this.dispatch(addCardAction(card, nextToItem)); + this.dispatch(addCardsAction([card], nextToItem)); } async updatePassage(oldCard: CardItem, ref: BibleReference) { @@ -1302,7 +1268,6 @@ export class AppService extends createReducingService(initialState) { // create an initial paragraph to hold verses that might come before a paragraph. let para = { p: { h: '', p: 0 }, vss: [] }; const paras = []; - const vss: BibleVerse[] = []; // for each verse in the chapter, break them into paragraphs. for (const v of ch.vss) { @@ -1350,7 +1315,7 @@ export class AppService extends createReducingService(initialState) { data: result, } as CardItem; - this.dispatch(addCardAction(card, nextToItem)); + this.dispatch(addCardsAction([card], nextToItem)); } private async getWordsFromApi(qry: string): Promise { @@ -1411,7 +1376,7 @@ export class AppService extends createReducingService(initialState) { if (excluded.length > 0) { this.dispatch( updateErrorAction({ - msg: `The ${excluded.length > 1 ? 'words' : 'word'} "${excluded.reduce((prev, curr, idx, arr) => { + msg: `The ${excluded.length > 1 ? 'words' : 'word'} "${excluded.reduce((prev, curr) => { return `${prev}, ${curr}`; })}" ${excluded.length > 1 ? 'have' : 'has'} been excluded from search because it is too common.`, })