Skip to content

Commit

Permalink
fix(scan): warnings now displaying in the console and can be disabled…
Browse files Browse the repository at this point in the history
… in the settings
  • Loading branch information
sundevista committed Jul 23, 2022
1 parent 6f3d7b1 commit caad54b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.8.3] - 2022/07/23
## Fixed
- Warnings now displaying in the console and can be disabled in the settings

## [1.8.2] - 2022/07/23
## Fixed
- Reducing `TypeError` with empty frontmatter (#19)
Expand Down
13 changes: 13 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface LocalQuotesSettings {
quoteVault: Quote[];
templateFolder: string;
hideRefreshButton: boolean;
displayWarnings: boolean;
enableDblClick: boolean;
}

Expand All @@ -38,6 +39,7 @@ export const DEFAULT_SETTINGS: LocalQuotesSettings = {
quoteVault: [],
templateFolder: '',
hideRefreshButton: false,
displayWarnings: true,
enableDblClick: true,
};

Expand Down Expand Up @@ -195,6 +197,17 @@ export class LocalQuotesSettingTab extends PluginSettingTab {
}));

containerEl.createEl('h2', {text: 'Danger Zone'});
new Setting(containerEl)
.setName('Display warnings')
.setDesc('If you turn it on plugin will display any warning those need your attention in the developer ' +
'console. If it\'s annoying and you don\'t agree with warnings or will not fix them, you can disable ' +
'this option.')
.addToggle(t => t
.setValue(this.plugin.settings.displayWarnings)
.onChange(async (value) => {
this.plugin.settings.displayWarnings = value;
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName('Clear block metadata')
Expand Down
11 changes: 8 additions & 3 deletions src/utils/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ export function checkFileTag(f: TFile, tag: string): boolean {
const tagInContent = fileCache && fileCache.tags &&
(fileCache.tags.findIndex((t) => t.tag === `#${tag}`) >= 0);
if (tagInContent) return true;
const tagInFrontmatter = fileCache.frontmatter.tags.includes(tag);
return !!tagInFrontmatter;
const tagInFrontmatter = fileCache && fileCache.frontmatter && fileCache.frontmatter.tags
&& fileCache.frontmatter.tags.includes(tag);
if (tagInFrontmatter) return true;
} catch (e) {
if (e instanceof TypeError) return false;
if (e instanceof TypeError) {
console.log('! This file may have invalid YAML: ' + f.name + ' (' + f.path + ').\nYou can disable warnings ' +
'in the settings of the Local Quotes plugin.');
return false;
}
else throw e;
}
}
Expand Down

0 comments on commit caad54b

Please sign in to comment.