Skip to content

Commit

Permalink
Strict in TSConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
turulix committed Nov 3, 2023
1 parent 80dfe2e commit d085a3d
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 46 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
name: CI
on: push
on:
push:
pull_request:

jobs:
eslint:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Install modules
run: npm i
- name: Install modules
run: npm i

- name: Run build
run: npm run build
- name: Run build
run: npm run build

- name: Check TypeScript
run: npx tsc --noEmit
- name: Check TypeScript
run: npx tsc --noEmit

- name: Run ESLint
run: npx eslint ./src/
- name: Run ESLint
run: npx eslint ./src/
9 changes: 7 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {FolderNoteModule} from "./modules/FolderNoteModule";

// Remember to rename these classes and interfaces!
export default class FolderIndexPlugin extends Plugin {
// @ts-ignore
settings: PluginSetting;
// @ts-ignore
graphManipulator: GraphManipulatorModule | null;
// @ts-ignore
folderNodeModule: FolderNoteModule;
// @ts-ignore
eventManager: EventEmitter
oldGraphSetting = false
static PLUGIN: FolderIndexPlugin;
Expand Down Expand Up @@ -38,7 +42,7 @@ export default class FolderIndexPlugin extends Plugin {
this.registerEvent(this.app.workspace.on("layout-change", this.onLayoutChange.bind(this)))
this.eventManager.on("settingsUpdate", this.onSettingsUpdate.bind(this))

this.registerMarkdownCodeBlockProcessor("folder-index-content", (source, el, ctx) => {
this.registerMarkdownCodeBlockProcessor("folder-index-content", (_source, el, ctx) => {
ctx.addChild(new IndexContentProcessorModule(this.app, this, ctx.sourcePath, el))
})

Expand All @@ -53,7 +57,8 @@ export default class FolderIndexPlugin extends Plugin {
if (this.settings.graphOverwrite) {
this.graphManipulator = new GraphManipulatorModule(this.app, this)
} else {
this.graphManipulator.unload()
if (this.graphManipulator)
this.graphManipulator.unload()
}
this.oldGraphSetting = this.settings.graphOverwrite
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/PluginSettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class PluginSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings()
}))

let textFeld: TextAreaComponent = null;
let textFeld: TextAreaComponent | null = null;
new Setting(containerEl)
.setName("Initial Content")
.setDesc("Set the initial content for new folder indexes.")
Expand All @@ -90,7 +90,7 @@ export class PluginSettingsTab extends PluginSettingTab {
.setTooltip("Reset to default")
.onClick(async () => {
this.plugin.settings.indexFileInitText = DEFAULT_SETTINGS.indexFileInitText
textFeld.setValue(this.plugin.settings.indexFileInitText)
textFeld?.setValue(this.plugin.settings.indexFileInitText)
await this.plugin.saveSettings()
}
))
Expand Down
12 changes: 8 additions & 4 deletions src/modules/FolderNoteModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,23 @@ export class FolderNoteModule {
// FolderNoteModule.showAllIndexFiles()
}


private getTargetFromEvent(event: MouseEvent): HTMLElement | null {
if (!(event.target instanceof HTMLElement)) {
return
return null
}
const target = event.target
// @ts-ignore - This is a hack to get the active plugins.
// noinspection JSUnresolvedReference
const activePlugins: Set = this.app.plugins.enabledPlugins

// Compatibility with https://github.com/ozntel/file-tree-alternative
if (activePlugins.has("file-tree-alternative")) {
if (target.classList.contains("oz-folder-name")) {
return target.parentElement.parentElement.parentElement
return (target.parentElement?.parentElement?.parentElement) ?? null
}
if (target.classList.contains("oz-folder-block")) {
return target.parentElement.parentElement
return (target.parentElement?.parentElement) ?? null
}
}

Expand Down Expand Up @@ -110,6 +112,8 @@ export class FolderNoteModule {
if (this.plugin.settings.autoCreateIndexFile) {
const name = path.split(/\//).last()
try {
if (!name)
return false
const file = await this.app.vault.create(path, this.plugin.settings.indexFileInitText.replace("{{folder}}", name))
new Notice(`Created index file ${file.basename}`)
return true
Expand Down Expand Up @@ -181,7 +185,7 @@ export class FolderNoteModule {
if (currentState.state.file == this.previousState.state.file)
return;

const currentFile = await this.app.vault.getAbstractFileByPath(currentState.state.file) as TFile
const currentFile = this.app.vault.getAbstractFileByPath(currentState.state.file) as TFile

// We did not open an index file, so we need to check if the previous mode was set by this plugin
if (!isIndexFile(currentFile.path)) {
Expand Down
22 changes: 17 additions & 5 deletions src/modules/GraphManipulatorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class GraphManipulatorModule {
constructor(private app: App, private plugin: FolderIndexPlugin) {
this.app = app
this.plugin = plugin
this.graphsLeafs = []
this.oldGraphOverwrite = this.plugin.settings.graphOverwrite
this.load()
}

Expand All @@ -49,7 +51,8 @@ export class GraphManipulatorModule {
if (this.plugin.settings.graphOverwrite) {
this.render(engine)
} else {
engine.oldRender()
if (engine.oldRender)
engine.oldRender()
}
}
// We may need to rerender the graph view, so we do this here.
Expand Down Expand Up @@ -88,6 +91,7 @@ export class GraphManipulatorModule {
const engine = this.getEngine(value)
if (engine.oldRender != null) {
engine.render = engine.oldRender
// @ts-ignore
delete engine.oldRender
this.clearGraph(engine)
engine.render()
Expand All @@ -96,7 +100,12 @@ export class GraphManipulatorModule {
}

render(engine: DataEngine) {
const renderSettings = engine.getOptions()
const renderSettings: {
showOrphans: boolean,
showAttachments: boolean,
showTags: boolean,
hideUnresolved: boolean
} = engine.getOptions()
const graph: Graph = {}

this.app.vault.getFiles().forEach(async file => {
Expand Down Expand Up @@ -146,7 +155,7 @@ export class GraphManipulatorModule {
}
if (cache.frontmatter != null) {
const frontMatterTags = parseFrontMatterTags(cache.frontmatter)
if (frontMatterTags != null && renderSettings.showTags == true) {
if (frontMatterTags != null && renderSettings.showTags) {
frontMatterTags.forEach(tag => {
graph[tag] = {
links: {},
Expand All @@ -156,7 +165,7 @@ export class GraphManipulatorModule {
})
}
}
if (cache.tags != null && renderSettings.showTags == true) {
if (cache.tags != null && renderSettings.showTags) {

cache.tags.forEach(tag => {
// We have to add it, it will not add itself.
Expand Down Expand Up @@ -187,7 +196,7 @@ export class GraphManipulatorModule {
}

let type: NodeType = ""
if (this.app.workspace.getActiveFile() != null && this.app.workspace.getActiveFile().path == file.path) {
if (this.app.workspace.getActiveFile() != null && this.app.workspace.getActiveFile()?.path == file.path) {
type = "focused"
} else if (file.extension != "md") {
type = "attachment"
Expand Down Expand Up @@ -227,10 +236,13 @@ export class GraphManipulatorModule {
const fileFilter = engine.fileFilter
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return !searchQueries || ("" === nodeType ? filePath === engineOptions.localFile || (fileFilter.hasOwnProperty(filePath) ? fileFilter[filePath] : !engine.hasFilter) : "tag" === nodeType ? searchQueries.every((function (e: any) {

// noinspection JSUnresolvedReference
return !!e.color || !!e.query.matchTag(filePath)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
)) : "attachment" !== nodeType || searchQueries.every((function (e: any) {
// noinspection JSUnresolvedReference
return !!e.color || !!e.query.matchFilepath(filePath)
}
)))
Expand Down
2 changes: 1 addition & 1 deletion src/modules/IndexContentProcessorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class IndexContentProcessorModule extends MarkdownRenderChild {

private async render() {
this.container.empty()
const folder: TAbstractFile = this.app.vault.getAbstractFileByPath(this.filePath)
const folder: TAbstractFile | null = this.app.vault.getAbstractFileByPath(this.filePath)
if (folder instanceof TFile) {
const files = folder.parent.children
const renderer = new MarkdownTextRenderer(this.plugin, this.app)
Expand Down
2 changes: 1 addition & 1 deletion src/types/MarkdownTextRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class MarkdownTextRenderer {
let markdownText = ""
markdownText += this.buildMarkdownLinkString(this.getTitleFromPath(file.path), encodeURI(file.path), indentLevel, isFolder)

const headers: HeadingCache[] | null = this.app.metadataCache.getFileCache(file)?.headings
const headers: HeadingCache[] | null = this.app.metadataCache.getFileCache(file)?.headings ?? []
if (headers && !this.plugin.settings.disableHeadlines) {
const headerTree = this.buildHeaderTree(headers)
if (this.plugin.settings.headlineLimit !== 0) {
Expand Down
43 changes: 22 additions & 21 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"lib": [
"DOM",
"ES5",
"ES6",
"ES7"
]
},
"include": [
"**/*.ts"
]
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
"strict": true,
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"lib": [
"DOM",
"ES5",
"ES6",
"ES7"
]
},
"include": [
"**/*.ts"
]
}

0 comments on commit d085a3d

Please sign in to comment.