Skip to content

Commit

Permalink
chore: add linting for camelcase variables
Browse files Browse the repository at this point in the history
  • Loading branch information
st3v3nmw committed Sep 26, 2024
1 parent a4b88dc commit ba7d0a0
Show file tree
Hide file tree
Showing 68 changed files with 538 additions and 576 deletions.
4 changes: 2 additions & 2 deletions docs/docs/en/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default {
SHOW_ANSWER: "Show Answer",
DAYS_STR_IVL: "${interval} days",
CHECK_ALGORITHM_WIKI:
'For more information, check the <a href="${algo_url}">algorithm implementation</a>.',
'For more information, check the <a href="${algoUrl}">algorithm implementation</a>.',
};
```

Expand All @@ -62,7 +62,7 @@ export default {
SHOW_ANSWER: "Onyesha Jibu",
DAYS_STR_IVL: "Siku ${interval}",
CHECK_ALGORITHM_WIKI:
'Kwa habari zaidi, angalia <a href="${algo_url}">utekelezaji wa algorithm</a>.',
'Kwa habari zaidi, angalia <a href="${algoUrl}">utekelezaji wa algorithm</a>.',
};
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/zh/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default {
SHOW_ANSWER: "Show Answer",
DAYS_STR_IVL: "${interval} days",
CHECK_ALGORITHM_WIKI:
'For more information, check the <a href="${algo_url}">algorithm implementation</a>.',
'For more information, check the <a href="${algoUrl}">algorithm implementation</a>.',
};
```

Expand All @@ -62,7 +62,7 @@ export default {
SHOW_ANSWER: "Onyesha Jibu",
DAYS_STR_IVL: "Siku ${interval}",
CHECK_ALGORITHM_WIKI:
'Kwa habari zaidi, angalia <a href="${algo_url}">utekelezaji wa algorithm</a>.',
'Kwa habari zaidi, angalia <a href="${algoUrl}">utekelezaji wa algorithm</a>.',
};
```

Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default tseslint.config(
"linebreak-style": 0,
quotes: ["warn", "double", "avoid-escape"],
semi: ["error", "always"],
camelcase: ["error"],
"@typescript-eslint/no-unused-vars": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {

// GUI & Obsidian coupled code
"src/core.ts",
"src/sr-file.ts",
"src/file.ts",
"src/gui/",
"src/icons/",
"src/main.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/base/rep-item-schedule-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Moment } from "moment";

import { TICKS_PER_DAY } from "src/constants";
import { formatDate_YYYY_MM_DD, globalDateProvider } from "src/utils/dates";
import { formatDateYYYYMMDD, globalDateProvider } from "src/utils/dates";

export abstract class RepItemScheduleInfo {
dueDate: Moment;
Expand All @@ -18,7 +18,7 @@ export abstract class RepItemScheduleInfo {
}

formatDueDate(): string {
return formatDate_YYYY_MM_DD(this.dueDate);
return formatDateYYYYMMDD(this.dueDate);
}

delayedBeforeReviewDaysInt(): number {
Expand Down
8 changes: 3 additions & 5 deletions src/algorithms/osr/osr-note-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export class OsrNoteGraph {
}

const targetLinks =
this.vaultNoteLinkInfoFinder.getResolvedTargetLinksForNotePath(path) ||
/* c8 ignore next */ {};
this.vaultNoteLinkInfoFinder.getResolvedTargetLinksForNotePath(path) || {};
for (const targetPath in targetLinks) {
if (this.incomingLinks[targetPath] === undefined) this.incomingLinks[targetPath] = [];

Expand All @@ -64,7 +63,7 @@ export class OsrNoteGraph {
linkPGTotal = 0,
totalLinkCount = 0;

for (const statObj of this.incomingLinks[notePath] || /* c8 ignore next */ []) {
for (const statObj of this.incomingLinks[notePath] || []) {
const ease: number = noteEaseList.getEaseByPath(statObj.sourcePath);
if (ease) {
linkTotal += statObj.linkCount * this.pageranks[statObj.sourcePath] * ease;
Expand All @@ -74,8 +73,7 @@ export class OsrNoteGraph {
}

const outgoingLinks =
this.vaultNoteLinkInfoFinder.getResolvedTargetLinksForNotePath(notePath) ||
/* c8 ignore next */ {};
this.vaultNoteLinkInfoFinder.getResolvedTargetLinksForNotePath(notePath) || {};
for (const outgoingLink in outgoingLinks) {
const ease: number = noteEaseList.getEaseByPath(outgoingLink);
const linkCount: number = outgoingLinks[outgoingLink];
Expand Down
14 changes: 7 additions & 7 deletions src/algorithms/osr/rep-item-schedule-info-osr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RepItemScheduleInfo } from "src/algorithms/base/rep-item-schedule-info"
import { SRSettings } from "src/settings";
import { DateUtil, globalDateProvider } from "src/utils/dates";

export class RepItemScheduleInfo_Osr extends RepItemScheduleInfo {
export class RepItemScheduleInfoOsr extends RepItemScheduleInfo {
// A question can have multiple cards. The schedule info for all sibling cards are formatted together
// in a single <!--SR: --> comment, such as:
// <!--SR:!2023-09-02,4,270!2023-09-02,5,270!2023-09-02,6,270!2023-09-02,7,270-->
Expand Down Expand Up @@ -34,18 +34,18 @@ export class RepItemScheduleInfo_Osr extends RepItemScheduleInfo {
// We always want the correct schedule format, so we use the dummy due date if there is no schedule for a card
const dateStr: string = this.dueDate
? this.formatDueDate()
: RepItemScheduleInfo_Osr.dummyDueDateForNewCard;
: RepItemScheduleInfoOsr.dummyDueDateForNewCard;
return `!${dateStr},${this.interval},${this.latestEase}`;
}

static get initialInterval(): number {
return 1.0;
}

static getDummyScheduleForNewCard(settings: SRSettings): RepItemScheduleInfo_Osr {
return RepItemScheduleInfo_Osr.fromDueDateStr(
RepItemScheduleInfo_Osr.dummyDueDateForNewCard,
RepItemScheduleInfo_Osr.initialInterval,
static getDummyScheduleForNewCard(settings: SRSettings): RepItemScheduleInfoOsr {
return RepItemScheduleInfoOsr.fromDueDateStr(
RepItemScheduleInfoOsr.dummyDueDateForNewCard,
RepItemScheduleInfoOsr.initialInterval,
settings.baseEase,
);
}
Expand All @@ -57,6 +57,6 @@ export class RepItemScheduleInfo_Osr extends RepItemScheduleInfo {
delayedBeforeReviewTicks: number | null = null,
) {
const dueDate: Moment = DateUtil.dateStrToMoment(dueDateStr);
return new RepItemScheduleInfo_Osr(dueDate, interval, ease, delayedBeforeReviewTicks);
return new RepItemScheduleInfoOsr(dueDate, interval, ease, delayedBeforeReviewTicks);
}
}
44 changes: 21 additions & 23 deletions src/algorithms/osr/srs-algorithm-osr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { RepItemScheduleInfo } from "src/algorithms/base/rep-item-schedule-info"
import { ReviewResponse } from "src/algorithms/base/repetition-item";
import { osrSchedule } from "src/algorithms/osr/note-scheduling";
import { NoteLinkStat, OsrNoteGraph } from "src/algorithms/osr/osr-note-graph";
import { RepItemScheduleInfo_Osr } from "src/algorithms/osr/rep-item-schedule-info-osr";
import { RepItemScheduleInfoOsr } from "src/algorithms/osr/rep-item-schedule-info-osr";
import { DueDateHistogram } from "src/due-date-histogram";
import { Note } from "src/note";
import { INoteEaseList, NoteEaseList } from "src/note-ease-list";
import { Question } from "src/question";
import { SRSettings } from "src/settings";
import { globalDateProvider } from "src/utils/dates";

export class SrsAlgorithm_Osr implements ISrsAlgorithm {
export class SrsAlgorithmOsr implements ISrsAlgorithm {
private settings: SRSettings;
private noteEaseList: INoteEaseList;

Expand Down Expand Up @@ -47,18 +47,17 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {
: linkContribution * this.settings.baseEase);

// add note's average flashcard ease if available
/* c8 ignore next 3 */
if (this.noteEaseList.hasEaseForPath(notePath)) {
ease = (ease + this.noteEaseList.getEaseByPath(notePath)) / 2;
}

// Don't know the due date until we know the calculated interval
const dueDate: Moment = null;
const interval: number = SrsAlgorithm_Osr.initialInterval;
const interval: number = SrsAlgorithmOsr.initialInterval;
ease = Math.round(ease);
const temp: RepItemScheduleInfo_Osr = new RepItemScheduleInfo_Osr(dueDate, interval, ease);
const temp: RepItemScheduleInfoOsr = new RepItemScheduleInfoOsr(dueDate, interval, ease);

const result: RepItemScheduleInfo_Osr = this.calcSchedule(
const result: RepItemScheduleInfoOsr = this.calcSchedule(
temp,
response,
dueDateNoteHistogram,
Expand All @@ -72,7 +71,7 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {
noteOnLoadedNote(path: string, note: Note, noteEase: number): void {
let flashcardsInNoteAvgEase: number = null;
if (note) {
flashcardsInNoteAvgEase = SrsAlgorithm_Osr.calculateFlashcardAvgEase(
flashcardsInNoteAvgEase = SrsAlgorithmOsr.calculateFlashcardAvgEase(
note.questionList,
this.settings,
);
Expand Down Expand Up @@ -122,8 +121,8 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {
response: ReviewResponse,
dueDateNoteHistogram: DueDateHistogram,
): RepItemScheduleInfo {
const noteScheduleOsr: RepItemScheduleInfo_Osr = noteSchedule as RepItemScheduleInfo_Osr;
const temp: RepItemScheduleInfo_Osr = this.calcSchedule(
const noteScheduleOsr: RepItemScheduleInfoOsr = noteSchedule as RepItemScheduleInfoOsr;
const temp: RepItemScheduleInfoOsr = this.calcSchedule(
noteScheduleOsr,
response,
dueDateNoteHistogram,
Expand All @@ -133,14 +132,14 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {

const dueDate: Moment = moment(globalDateProvider.today.add(interval, "d"));
this.noteEaseList.setEaseForPath(notePath, ease);
return new RepItemScheduleInfo_Osr(dueDate, interval, ease);
return new RepItemScheduleInfoOsr(dueDate, interval, ease);
}

private calcSchedule(
schedule: RepItemScheduleInfo_Osr,
schedule: RepItemScheduleInfoOsr,
response: ReviewResponse,
dueDateHistogram: DueDateHistogram,
): RepItemScheduleInfo_Osr {
): RepItemScheduleInfoOsr {
const temp: Record<string, number> = osrSchedule(
response,
schedule.interval,
Expand All @@ -150,32 +149,31 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {
dueDateHistogram,
);

return new RepItemScheduleInfo_Osr(globalDateProvider.today, temp.interval, temp.ease);
return new RepItemScheduleInfoOsr(globalDateProvider.today, temp.interval, temp.ease);
}

cardGetResetSchedule(): RepItemScheduleInfo {
const interval = SrsAlgorithm_Osr.initialInterval;
const interval = SrsAlgorithmOsr.initialInterval;
const ease = this.settings.baseEase;
const dueDate = globalDateProvider.today.add(interval, "d");
return new RepItemScheduleInfo_Osr(dueDate, interval, ease);
return new RepItemScheduleInfoOsr(dueDate, interval, ease);
}

cardGetNewSchedule(
response: ReviewResponse,
notePath: string,
dueDateFlashcardHistogram: DueDateHistogram,
): RepItemScheduleInfo {
let initial_ease: number = this.settings.baseEase;
/* c8 ignore next 3 */
let initialEase: number = this.settings.baseEase;
if (this.noteEaseList.hasEaseForPath(notePath)) {
initial_ease = Math.round(this.noteEaseList.getEaseByPath(notePath));
initialEase = Math.round(this.noteEaseList.getEaseByPath(notePath));
}
const delayBeforeReview = 0;

const schedObj: Record<string, number> = osrSchedule(
response,
SrsAlgorithm_Osr.initialInterval,
initial_ease,
SrsAlgorithmOsr.initialInterval,
initialEase,
delayBeforeReview,
this.settings,
dueDateFlashcardHistogram,
Expand All @@ -184,15 +182,15 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {
const interval = schedObj.interval;
const ease = schedObj.ease;
const dueDate = globalDateProvider.today.add(interval, "d");
return new RepItemScheduleInfo_Osr(dueDate, interval, ease, delayBeforeReview);
return new RepItemScheduleInfoOsr(dueDate, interval, ease, delayBeforeReview);
}

cardCalcUpdatedSchedule(
response: ReviewResponse,
cardSchedule: RepItemScheduleInfo,
dueDateFlashcardHistogram: DueDateHistogram,
): RepItemScheduleInfo {
const cardScheduleOsr: RepItemScheduleInfo_Osr = cardSchedule as RepItemScheduleInfo_Osr;
const cardScheduleOsr: RepItemScheduleInfoOsr = cardSchedule as RepItemScheduleInfoOsr;
const schedObj: Record<string, number> = osrSchedule(
response,
cardScheduleOsr.interval,
Expand All @@ -205,6 +203,6 @@ export class SrsAlgorithm_Osr implements ISrsAlgorithm {
const ease = schedObj.ease;
const dueDate = globalDateProvider.today.add(interval, "d");
const delayBeforeReview = 0;
return new RepItemScheduleInfo_Osr(dueDate, interval, ease, delayBeforeReview);
return new RepItemScheduleInfoOsr(dueDate, interval, ease, delayBeforeReview);
}
}
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { DataStoreAlgorithm } from "src/data-store-algorithm/data-store-algorith
import { Deck, DeckTreeFilter } from "src/deck";
import { DeckTreeStatsCalculator } from "src/deck-tree-stats-calculator";
import { CardDueDateHistogram, NoteDueDateHistogram } from "src/due-date-histogram";
import { ISRFile, SrTFile } from "src/file";
import { FlashcardReviewMode } from "src/flashcard-review-sequencer";
import { Note } from "src/note";
import { NoteEaseList } from "src/note-ease-list";
import { NoteFileLoader } from "src/note-file-loader";
import { NoteReviewQueue } from "src/note-review-queue";
import { QuestionPostponementList } from "src/question-postponement-list";
import { SettingsUtil, SRSettings } from "src/settings";
import { ISRFile, SrTFile } from "src/sr-file";
import { Stats } from "src/stats";
import { TopicPath } from "src/topic-path";
import { globalDateProvider } from "src/utils/dates";
Expand Down
24 changes: 11 additions & 13 deletions src/data-store-algorithm/data-store-in-note-algorithm-osr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Moment } from "moment";
import moment from "moment";

import { RepItemScheduleInfo } from "src/algorithms/base/rep-item-schedule-info";
import { RepItemScheduleInfo_Osr } from "src/algorithms/osr/rep-item-schedule-info-osr";
import { RepItemScheduleInfoOsr } from "src/algorithms/osr/rep-item-schedule-info-osr";
import { Card } from "src/card";
import {
ALLOWED_DATE_FORMATS,
Expand All @@ -12,18 +12,16 @@ import {
YAML_FRONT_MATTER_REGEX,
} from "src/constants";
import { IDataStoreAlgorithm } from "src/data-store-algorithm/idata-store-algorithm";
import { ISRFile } from "src/file";
import { Question } from "src/question";
import { SRSettings } from "src/settings";
import { ISRFile } from "src/sr-file";
import { formatDate_YYYY_MM_DD } from "src/utils/dates";
import { formatDateYYYYMMDD } from "src/utils/dates";

//
// Algorithm: The original OSR algorithm
// (RZ: Perhaps not the original algorithm, but the only one available in 2023/early 2024)
//
// Data Store: With data stored in the note's markdown file
//
export class DataStoreInNote_AlgorithmOsr implements IDataStoreAlgorithm {
export class DataStoreInNoteAlgorithmOsr implements IDataStoreAlgorithm {
private settings: SRSettings;

constructor(settings: SRSettings) {
Expand All @@ -43,16 +41,16 @@ export class DataStoreInNote_AlgorithmOsr implements IDataStoreAlgorithm {
const dueDate: Moment = moment(frontmatter.get("sr-due"), ALLOWED_DATE_FORMATS);
const interval: number = parseFloat(frontmatter.get("sr-interval"));
const ease: number = parseFloat(frontmatter.get("sr-ease"));
result = new RepItemScheduleInfo_Osr(dueDate, interval, ease);
result = new RepItemScheduleInfoOsr(dueDate, interval, ease);
}
return result;
}

async noteSetSchedule(note: ISRFile, repItemScheduleInfo: RepItemScheduleInfo): Promise<void> {
let fileText: string = await note.read();

const schedInfo: RepItemScheduleInfo_Osr = repItemScheduleInfo as RepItemScheduleInfo_Osr;
const dueString: string = formatDate_YYYY_MM_DD(schedInfo.dueDate);
const schedInfo: RepItemScheduleInfoOsr = repItemScheduleInfo as RepItemScheduleInfoOsr;
const dueString: string = formatDateYYYYMMDD(schedInfo.dueDate);
const interval: number = schedInfo.interval;
const ease: number = schedInfo.latestEase;

Expand Down Expand Up @@ -96,13 +94,13 @@ export class DataStoreInNote_AlgorithmOsr implements IDataStoreAlgorithm {
formatCardSchedule(card: Card) {
let result: string;
if (card.hasSchedule) {
const schedule = card.scheduleInfo as RepItemScheduleInfo_Osr;
const schedule = card.scheduleInfo as RepItemScheduleInfoOsr;
const dateStr = schedule.dueDate
? formatDate_YYYY_MM_DD(schedule.dueDate)
: RepItemScheduleInfo_Osr.dummyDueDateForNewCard;
? formatDateYYYYMMDD(schedule.dueDate)
: RepItemScheduleInfoOsr.dummyDueDateForNewCard;
result = `!${dateStr},${schedule.interval},${schedule.latestEase}`;
} else {
result = `!${RepItemScheduleInfo_Osr.dummyDueDateForNewCard},${RepItemScheduleInfo_Osr.initialInterval},${this.settings.baseEase}`;
result = `!${RepItemScheduleInfoOsr.dummyDueDateForNewCard},${RepItemScheduleInfoOsr.initialInterval},${this.settings.baseEase}`;
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/data-store-algorithm/idata-store-algorithm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RepItemScheduleInfo } from "src/algorithms/base/rep-item-schedule-info";
import { ISRFile } from "src/file";
import { Question } from "src/question";
import { ISRFile } from "src/sr-file";

export interface IDataStoreAlgorithm {
noteGetSchedule(note: ISRFile): Promise<RepItemScheduleInfo>;
Expand Down
Loading

0 comments on commit ba7d0a0

Please sign in to comment.