[DRAFT] Update dependencies, add prettier/eslint for consistent style, add more type safety - #127
[DRAFT] Update dependencies, add prettier/eslint for consistent style, add more type safety#127epsilonhalbe wants to merge 3 commits into
Conversation
| charset = utf-8 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| indent_style = space |
There was a problem hiding this comment.
I got warnings of mixed tabs and spaces => changed this to spaces
| @@ -1,2 +1,2 @@ | |||
| npm node_modules | |||
There was a problem hiding this comment.
I think this was wrong, there is no build directory and npm node_modules doesn't make sense
| import { Plugin } from 'obsidian' | ||
| import HeatmapCalendarSettingsTab from 'settings' | ||
|
|
||
| declare global { |
There was a problem hiding this comment.
adding the global declare removes the need for ts-ignore when accessing the window object
|
|
||
| const intensities = calEntries | ||
| .map((e: Entry) => e.intensity) | ||
| .filter((intensity): intensity is number => intensity !== undefined) |
There was a problem hiding this comment.
this is a neat trick - to type filters for undefined. intensities with this has type number[] inferred by the compiler
| parent: heatmapCalendarGraphDiv, | ||
| }) | ||
|
|
||
| const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] |
There was a problem hiding this comment.
simplifies the previous duplication
| } | ||
|
|
||
| async onload(): Promise<void> { | ||
| const settings = await this.loadSettings() |
There was a problem hiding this comment.
settings is only used here - no need for a global variable.
|
|
||
| getWeekdayShort(dayNumber: number): string { | ||
| return new Date(1970, 0, dayNumber + this.settings.weekStartDay + 4).toLocaleDateString('en-US', { | ||
| getWeekdayShort(weekStartDay: number, dayNumber: number): string { |
There was a problem hiding this comment.
add parameter to avoid accessing a global variable
| weekStartDay: 1, | ||
| } | ||
| export default class HeatmapCalendar extends Plugin { | ||
| settings: CalendarSettings |
There was a problem hiding this comment.
removing this since it is not needed, and this way we can enable strictPropertyInitialization in tsconfig
I noticed the dependencies were a bit out of date and the style was not very consistent. As well as a few
as ...andts-ignore.I moved the ts file into a src folder and extracted default values and the domain model.
I ran the linter & formatter on the codebase, I tried to make it do as little changes as possible but the mix of commas/semicolons/quotes needed some changes to be unified.
the formatting & linting is cnotained in a single commit so it can be reverted more easily and review of unrelated content is easier.