Skip to content

Commit

Permalink
fix issues reported by pnpm lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ronzulu committed Oct 4, 2023
1 parent 5cb9d3a commit 11c0a7a
Show file tree
Hide file tree
Showing 24 changed files with 176 additions and 239 deletions.
3 changes: 1 addition & 2 deletions src/Card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Question } from "./Question";
import { CardScheduleInfo } from "./CardSchedule";
import { CardListType } from "./Deck";
import { SRSettings } from "./settings";

export class Card {
question: Question;
Expand Down Expand Up @@ -34,7 +33,7 @@ export class Card {
}

formatSchedule(): string {
var result: string;
let result: string = "";
if (this.hasSchedule) result = this.scheduleInfo.formatSchedule();
else result = "New";
return result;
Expand Down
52 changes: 25 additions & 27 deletions src/CardSchedule.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import moment, { Moment } from "moment";
import { Moment } from "moment";
import {
ALLOWED_DATE_FORMATS,
LEGACY_SCHEDULING_EXTRACTOR,
MULTI_SCHEDULING_EXTRACTOR,
PREFERRED_DATE_FORMAT,
TICKS_PER_DAY,
} from "./constants";
import { INoteEaseList } from "./NoteEaseList";
Expand Down Expand Up @@ -48,7 +46,7 @@ export class CardScheduleInfo {
ease: number,
delayBeforeReviewTicks: number,
) {
let dueDateTicks: Moment = DateUtil.dateStrToMoment(dueDateStr);
const dueDateTicks: Moment = DateUtil.dateStrToMoment(dueDateStr);
return new CardScheduleInfo(dueDateTicks, interval, ease, delayBeforeReviewTicks);
}

Expand Down Expand Up @@ -91,18 +89,18 @@ export class CardScheduleCalculator {
}

getResetCardSchedule(): CardScheduleInfo {
let interval = CardScheduleInfo.initialInterval;
let ease = this.settings.baseEase;
let dueDate = globalDateProvider.today.add(interval, "d");
let delayBeforeReview = 0;
const interval = CardScheduleInfo.initialInterval;
const ease = this.settings.baseEase;
const dueDate = globalDateProvider.today.add(interval, "d");
const delayBeforeReview = 0;
return CardScheduleInfo.fromDueDateMoment(dueDate, interval, ease, delayBeforeReview);
}

getNewCardSchedule(response: ReviewResponse, notePath: string): CardScheduleInfo {
let initial_ease: number = this.noteEaseList.getEaseByPath(notePath);
let delayBeforeReview = 0;
const initial_ease: number = this.noteEaseList.getEaseByPath(notePath);
const delayBeforeReview = 0;

let schedObj: Record<string, number> = schedule(
const schedObj: Record<string, number> = schedule(
response,
CardScheduleInfo.initialInterval,
initial_ease,
Expand All @@ -111,28 +109,28 @@ export class CardScheduleCalculator {
this.dueDatesFlashcards,
);

let interval = schedObj.interval;
let ease = schedObj.ease;
let dueDate = globalDateProvider.today.add(interval, "d");
const interval = schedObj.interval;
const ease = schedObj.ease;
const dueDate = globalDateProvider.today.add(interval, "d");
return CardScheduleInfo.fromDueDateMoment(dueDate, interval, ease, delayBeforeReview);
}

calcUpdatedSchedule(
response: ReviewResponse,
cardSchedule: CardScheduleInfo,
): CardScheduleInfo {
let schedObj: Record<string, number> = schedule(
const schedObj: Record<string, number> = schedule(
response,
cardSchedule.interval,
cardSchedule.ease,
cardSchedule.delayBeforeReviewTicks,
this.settings,
this.dueDatesFlashcards,
);
let interval = schedObj.interval;
let ease = schedObj.ease;
let dueDate = globalDateProvider.today.add(interval, "d");
let delayBeforeReview: 0;
const interval = schedObj.interval;
const ease = schedObj.ease;
const dueDate = globalDateProvider.today.add(interval, "d");
const delayBeforeReview = 0;
return CardScheduleInfo.fromDueDateMoment(dueDate, interval, ease, delayBeforeReview);
}
}
Expand All @@ -143,17 +141,17 @@ export class NoteCardScheduleParser {
if (scheduling.length === 0)
scheduling = [...questionText.matchAll(LEGACY_SCHEDULING_EXTRACTOR)];

let result: CardScheduleInfo[] = [];
const result: CardScheduleInfo[] = [];
for (let i = 0; i < scheduling.length; i++) {
let match: RegExpMatchArray = scheduling[i];
let dueDateStr = match[1];
let interval = parseInt(match[2]);
let ease = parseInt(match[3]);
let dueDate: Moment = DateUtil.dateStrToMoment(dueDateStr);
let delayBeforeReviewTicks: number =
const match: RegExpMatchArray = scheduling[i];
const dueDateStr = match[1];
const interval = parseInt(match[2]);
const ease = parseInt(match[3]);
const dueDate: Moment = DateUtil.dateStrToMoment(dueDateStr);
const delayBeforeReviewTicks: number =
dueDate.valueOf() - globalDateProvider.today.valueOf();

let info: CardScheduleInfo = new CardScheduleInfo(
const info: CardScheduleInfo = new CardScheduleInfo(
dueDate,
interval,
ease,
Expand Down
39 changes: 20 additions & 19 deletions src/Deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Deck {
if (!topicPath.hasPath) {
return this;
}
let t: TopicPath = topicPath.clone();
const t: TopicPath = topicPath.clone();
const deckName: string = t.shift();
for (const subdeck of this.subdecks) {
if (deckName === subdeck.deckName) {
Expand All @@ -70,16 +70,16 @@ export class Deck {

let result: Deck = null;
if (createAllowed) {
let parent: Deck = this;
const subdeck: Deck = new Deck(deckName, parent);
const subdeck: Deck = new Deck(deckName, this /* parent */);
this.subdecks.push(subdeck);
result = subdeck._getOrCreateDeck(t, createAllowed);
}
return result;
}

getTopicPath(): TopicPath {
let list: string[] = [];
const list: string[] = [];
// eslint-disable-next-line @typescript-eslint/no-this-alias
let deck: Deck = this;
while (!deck.isRootDeck) {
list.push(deck.deckName);
Expand All @@ -89,6 +89,7 @@ export class Deck {
}

getRootDeck(): Deck {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let deck: Deck = this;
while (!deck.isRootDeck) {
deck = deck.parent;
Expand All @@ -97,7 +98,7 @@ export class Deck {
}

getCard(index: number, cardListType: CardListType): Card {
let cardList: Card[] = this.getCardListForCardType(cardListType);
const cardList: Card[] = this.getCardListForCardType(cardListType);
return cardList[index];
}

Expand All @@ -106,20 +107,20 @@ export class Deck {
}

appendCard(topicPath: TopicPath, cardObj: Card): void {
let deck: Deck = this.getOrCreateDeck(topicPath);
let cardList: Card[] = deck.getCardListForCardType(cardObj.cardListType);
const deck: Deck = this.getOrCreateDeck(topicPath);
const cardList: Card[] = deck.getCardListForCardType(cardObj.cardListType);

cardList.push(cardObj);
}

deleteCard(card: Card): void {
let cardList: Card[] = this.getCardListForCardType(card.cardListType);
let idx = cardList.indexOf(card);
const cardList: Card[] = this.getCardListForCardType(card.cardListType);
const idx = cardList.indexOf(card);
if (idx != -1) cardList.splice(idx, 1);
}

deleteCardAtIndex(index: number, cardListType: CardListType): void {
let cardList: Card[] = this.getCardListForCardType(cardListType);
const cardList: Card[] = this.getCardListForCardType(cardListType);
cardList.splice(index, 1);
}

Expand All @@ -130,7 +131,7 @@ export class Deck {
}

toDeckArray(): Deck[] {
let result: Deck[] = [];
const result: Deck[] = [];
result.push(this);
for (const subdeck of this.subdecks) {
result.push(...subdeck.toDeckArray());
Expand Down Expand Up @@ -165,12 +166,12 @@ export class Deck {
result += `${indentStr}${this.deckName}\r\n`;
indentStr += " ";
for (let i = 0; i < this.newFlashcards.length; i++) {
let card = this.newFlashcards[i];
const card = this.newFlashcards[i];
result += `${indentStr}New: ${i}: ${card.front}::${card.back}\r\n`;
}
for (let i = 0; i < this.dueFlashcards.length; i++) {
let card = this.dueFlashcards[i];
let s = card.isDue ? "Due" : "Not due";
const card = this.dueFlashcards[i];
const s = card.isDue ? "Due" : "Not due";
result += `${indentStr}${s}: ${i}: ${card.front}::${card.back}\r\n`;
}

Expand All @@ -181,24 +182,24 @@ export class Deck {
}

clone(): Deck {
return this.copyWithCardFilter((card) => true);
return this.copyWithCardFilter(() => true);
}

copyWithCardFilter(predicate: (value: Card) => boolean, parent: Deck = null): Deck {
let result: Deck = new Deck(this.deckName, parent);
const result: Deck = new Deck(this.deckName, parent);
result.newFlashcards = [...this.newFlashcards.filter((card) => predicate(card))];
result.dueFlashcards = [...this.dueFlashcards.filter((card) => predicate(card))];

for (const s of this.subdecks) {
let newParent = result;
let newDeck = s.copyWithCardFilter(predicate, newParent);
const newParent = result;
const newDeck = s.copyWithCardFilter(predicate, newParent);
result.subdecks.push(newDeck);
}
return result;
}

static otherListType(cardListType: CardListType): CardListType {
var result: CardListType;
let result: CardListType;
if (cardListType == CardListType.NewCard) result = CardListType.DueCard;
else if (cardListType == CardListType.DueCard) result = CardListType.NewCard;
else throw "Invalid cardListType";
Expand Down
10 changes: 5 additions & 5 deletions src/DeckTreeIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class SingleDeckIterator {

private nextCardWithinList(): boolean {
let result: boolean = false;
let cardList: Card[] = this.deck.getCardListForCardType(this.cardListType);
const cardList: Card[] = this.deck.getCardListForCardType(this.cardListType);

// Delete the current card so we don't return it again
if (this.hasCurrentCard) {
Expand All @@ -119,8 +119,8 @@ class SingleDeckIterator {

deleteCurrentQuestion(): void {
this.ensureCurrentCard();
let q: Question = this.currentCard.question;
let cards: Card[] = this.deck.getCardListForCardType(this.cardListType);
const q: Question = this.currentCard.question;
const cards: Card[] = this.deck.getCardListForCardType(this.cardListType);
do {
this.deck.deleteCardAtIndex(this.cardIdx, this.cardListType);
} while (this.cardIdx < cards.length && Object.is(q, cards[this.cardIdx].question));
Expand All @@ -135,9 +135,9 @@ class SingleDeckIterator {

moveCurrentCardToEndOfList(): void {
this.ensureCurrentCard();
let cardList: Card[] = this.deck.getCardListForCardType(this.cardListType);
const cardList: Card[] = this.deck.getCardListForCardType(this.cardListType);
if (cardList.length <= 1) return;
let card = this.currentCard;
const card = this.currentCard;
this.deck.deleteCardAtIndex(this.cardIdx, this.cardListType);
this.deck.appendCard(TopicPath.emptyPath, card);
this.setNoCurrentCard();
Expand Down
12 changes: 6 additions & 6 deletions src/DeckTreeStatsCalculator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CardListType, Deck } from "./Deck";
import { Deck } from "./Deck";
import {
CardListOrder,
DeckTreeIterator,
Expand All @@ -16,21 +16,21 @@ export class DeckTreeStatsCalculator {

calculate(deckTree: Deck): Stats {
// Order doesn't matter as long as we iterate over everything
let iteratorOrder: IIteratorOrder = {
const iteratorOrder: IIteratorOrder = {
deckOrder: OrderMethod.Sequential,
cardListOrder: CardListOrder.DueFirst,
cardOrder: OrderMethod.Sequential,
};
let iterator: IDeckTreeIterator = new DeckTreeIterator(
const iterator: IDeckTreeIterator = new DeckTreeIterator(
iteratorOrder,
IteratorDeckSource.CloneBeforeUse,
);
let result = new Stats();
const result = new Stats();
iterator.setDeck(deckTree);
while (iterator.nextCard()) {
let card: Card = iterator.currentCard;
const card: Card = iterator.currentCard;
if (card.hasSchedule) {
let schedule: CardScheduleInfo = card.scheduleInfo;
const schedule: CardScheduleInfo = card.scheduleInfo;
result.update(schedule.delayBeforeReviewDaysInt, schedule.interval, schedule.ease);
} else {
result.incrementNew();
Expand Down
18 changes: 9 additions & 9 deletions src/FlashcardReviewSequencer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card } from "./Card";
import { CardListType, Deck } from "./Deck";
import { Question, QuestionText } from "./Question";
import { ReviewResponse, schedule } from "./scheduling";
import { ReviewResponse } from "./scheduling";
import { SRSettings } from "./settings";
import { TopicPath } from "./TopicPath";
import { CardScheduleInfo, ICardScheduleCalculator } from "./CardSchedule";
Expand Down Expand Up @@ -93,7 +93,7 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {
}

setCurrentDeck(topicPath: TopicPath): void {
let deck: Deck = this.remainingDeckTree.getDeck(topicPath);
const deck: Deck = this.remainingDeckTree.getDeck(topicPath);
this.cardSequencer.setDeck(deck);
this.cardSequencer.nextCard();
}
Expand All @@ -103,12 +103,12 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {
}

getDeckStats(topicPath: TopicPath): DeckStats {
let totalCount: number = this._originalDeckTree
const totalCount: number = this._originalDeckTree
.getDeck(topicPath)
.getCardCount(CardListType.All, true);
let remainingDeck: Deck = this.remainingDeckTree.getDeck(topicPath);
let newCount: number = remainingDeck.getCardCount(CardListType.NewCard, true);
let dueCount: number = remainingDeck.getCardCount(CardListType.DueCard, true);
const remainingDeck: Deck = this.remainingDeckTree.getDeck(topicPath);
const newCount: number = remainingDeck.getCardCount(CardListType.NewCard, true);
const dueCount: number = remainingDeck.getCardCount(CardListType.DueCard, true);
return new DeckStats(dueCount, newCount, totalCount);
}

Expand Down Expand Up @@ -155,7 +155,7 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {
}

determineCardSchedule(response: ReviewResponse, card: Card): CardScheduleInfo {
var result: CardScheduleInfo;
let result: CardScheduleInfo;

if (response == ReviewResponse.Reset) {
// Resetting the card schedule
Expand All @@ -168,7 +168,7 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {
card.scheduleInfo,
);
} else {
let currentNote: Note = card.question.note;
const currentNote: Note = card.question.note;
result = this.cardScheduleCalculator.getNewCardSchedule(
response,
currentNote.filePath,
Expand All @@ -179,7 +179,7 @@ export class FlashcardReviewSequencer implements IFlashcardReviewSequencer {
}

async updateCurrentQuestionText(text: string): Promise<void> {
let q: QuestionText = this.currentQuestion.questionText;
const q: QuestionText = this.currentQuestion.questionText;

q.actualQuestion = text;

Expand Down
Loading

0 comments on commit 11c0a7a

Please sign in to comment.