Skip to content

Commit

Permalink
fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
mProjectsCode committed Nov 29, 2022
1 parent f5b9020 commit 48bef13
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 149 deletions.
7 changes: 5 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": ["@typescript-eslint"],
"plugins": ["@typescript-eslint", "only-warn"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"],
"parserOptions": {
"sourceType": "module"
Expand All @@ -12,6 +12,9 @@
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off"
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": ["warn"]
}
}
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"builtin-modules": "^3.2.0",
"esbuild": "0.13.12",
"esbuild-svelte": "^0.7.1",
"eslint-plugin-only-warn": "^1.0.3",
"jest": "^28.1.2",
"jest-fetch-mock": "^3.0.3",
"obsidian": "latest",
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/BoardGameGeekAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BoardGameGeekAPI extends APIModel {

console.debug(response);

let ret: MediaTypeModel[] = [];
const ret: MediaTypeModel[] = [];

for (const boardgame of Array.from(response.querySelectorAll('boardgame'))) {
const id = boardgame.attributes.getNamedItem('objectid')!.value;
Expand Down
1 change: 0 additions & 1 deletion src/api/apis/LocGovAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { APIModel } from '../APIModel';
import { MediaTypeModel } from '../../models/MediaTypeModel';
import MediaDbPlugin from '../../main';
import { debugLog } from '../../utils/Utils';

// WIP
export class LocGovAPI extends APIModel {
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/MALAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MALAPI extends APIModel {

console.debug(data);

let ret: MediaTypeModel[] = [];
const ret: MediaTypeModel[] = [];

for (const result of data.data) {
const type = this.typeMappings.get(result.type?.toLowerCase());
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/MusicBrainzAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class MusicBrainzAPI extends APIModel {

const data = await fetchData.json;
console.debug(data);
let ret: MediaTypeModel[] = [];
const ret: MediaTypeModel[] = [];

for (const result of data['release-groups']) {
ret.push(
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/OMDbAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class OMDbAPI extends APIModel {

console.debug(data.Search);

let ret: MediaTypeModel[] = [];
const ret: MediaTypeModel[] = [];

for (const result of data.Search) {
const type = this.typeMappings.get(result.Type.toLowerCase());
Expand Down
6 changes: 3 additions & 3 deletions src/api/apis/SteamAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class SteamAPI extends APIModel {

console.debug(data);

let filteredData = [];
const filteredData = [];

for (const app of data.applist.apps) {
if (app.name.toLowerCase().includes(title.toLowerCase())) {
Expand All @@ -48,7 +48,7 @@ export class SteamAPI extends APIModel {
}
}

let ret: MediaTypeModel[] = [];
const ret: MediaTypeModel[] = [];

for (const result of filteredData) {
ret.push(
Expand All @@ -69,7 +69,7 @@ export class SteamAPI extends APIModel {
async getById(id: string): Promise<MediaTypeModel> {
console.log(`MDB | api "${this.apiName}" queried by ID`);

const searchUrl = `http://store.steampowered.com/api/appdetails?appids=${encodeURIComponent(id)}`;
const searchUrl = `http://store.steampowered.com/api/appdetails?appids=${encodeURIComponent(id)}&l=en`;
const fetchData = await requestUrl({
url: searchUrl,
});
Expand Down
2 changes: 1 addition & 1 deletion src/api/apis/WikipediaAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class WikipediaAPI extends APIModel {

const data = await fetchData.json();
console.debug(data);
let ret: MediaTypeModel[] = [];
const ret: MediaTypeModel[] = [];

for (const result of data.query.search) {
ret.push(
Expand Down
61 changes: 30 additions & 31 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class MediaDbPlugin extends Plugin {

frontMatterRexExpPattern: string = '^(---)\\n[\\s\\S]*?\\n---';

async onload() {
async onload(): Promise<void> {
this.apiManager = new APIManager();
// register APIs
this.apiManager.registerAPI(new OMDbAPI(this));
Expand All @@ -48,7 +48,7 @@ export default class MediaDbPlugin extends Plugin {
this.mediaTypeManager.updateFolders(this.settings);

// add icon to the left ribbon
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', (evt: MouseEvent) => this.createEntryWithAdvancedSearchModal());
const ribbonIconEl = this.addRibbonIcon('database', 'Add new Media DB entry', () => this.createEntryWithAdvancedSearchModal());
ribbonIconEl.addClass('obsidian-media-db-plugin-ribbon-class');

this.registerEvent(
Expand Down Expand Up @@ -136,8 +136,8 @@ export default class MediaDbPlugin extends Plugin {
* - replace the detail query
* - maybe custom link syntax
*/
async createLinkWithSearchModal() {
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
async createLinkWithSearchModal(): Promise<void> {
const apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
});

Expand All @@ -163,7 +163,7 @@ export default class MediaDbPlugin extends Plugin {
}
}

async createEntryWithSearchModal(searchModalOptions?: SearchModalOptions) {
async createEntryWithSearchModal(searchModalOptions?: SearchModalOptions): Promise<void> {
let types: string[] = [];
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openSearchModal(searchModalOptions ?? {}, async searchModalData => {
types = searchModalData.types;
Expand Down Expand Up @@ -198,8 +198,8 @@ export default class MediaDbPlugin extends Plugin {
await this.createMediaDbNotes(selectResults);
}

async createEntryWithAdvancedSearchModal() {
let apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
async createEntryWithAdvancedSearchModal(): Promise<void> {
const apiSearchResults: MediaTypeModel[] = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
});

Expand Down Expand Up @@ -254,7 +254,7 @@ export default class MediaDbPlugin extends Plugin {
}

async queryDetails(models: MediaTypeModel[]): Promise<MediaTypeModel[]> {
let detailModels: MediaTypeModel[] = [];
const detailModels: MediaTypeModel[] = [];
for (const model of models) {
try {
detailModels.push(await this.apiManager.queryDetailedInfo(model));
Expand All @@ -270,7 +270,7 @@ export default class MediaDbPlugin extends Plugin {
try {
console.debug('MDB | creating new note');

let fileContent = await this.generateMediaDbNoteContents(mediaTypeModel, options);
const fileContent = await this.generateMediaDbNoteContents(mediaTypeModel, options);

if (!options.folder) {
options.folder = await this.mediaTypeManager.getFolder(mediaTypeModel, this.app);
Expand All @@ -283,7 +283,7 @@ export default class MediaDbPlugin extends Plugin {
}
}

async generateMediaDbNoteContents(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions) {
async generateMediaDbNoteContents(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions): Promise<string> {
let fileMetadata = this.modelPropertyMapper.convertObject(mediaTypeModel.toMetaDataObject());
let fileContent = '';
const template = options.attachTemplate ? await this.mediaTypeManager.getTemplate(mediaTypeModel, this.app) : '';
Expand All @@ -300,7 +300,7 @@ export default class MediaDbPlugin extends Plugin {
return { fileMetadata: fileMetadata, fileContent: fileContent };
}

let attachFileMetadata: any = this.getMetadataFromFileCache(fileToAttach);
const attachFileMetadata: any = this.getMetadataFromFileCache(fileToAttach);
fileMetadata = Object.assign(attachFileMetadata, fileMetadata);

let attachFileContent: string = await this.app.vault.read(fileToAttach);
Expand All @@ -317,7 +317,7 @@ export default class MediaDbPlugin extends Plugin {
return { fileMetadata: fileMetadata, fileContent: fileContent };
}

let templateMetadata: any = this.getMetaDataFromFileContent(template);
const templateMetadata: any = this.getMetaDataFromFileContent(template);
fileMetadata = Object.assign(templateMetadata, fileMetadata);

const regExp = new RegExp(this.frontMatterRexExpPattern);
Expand Down Expand Up @@ -353,7 +353,7 @@ export default class MediaDbPlugin extends Plugin {
return metadata;
}

getMetadataFromFileCache(file: TFile) {
getMetadataFromFileCache(file: TFile): any {
let metadata: any = this.app.metadataCache.getFileCache(file).frontmatter;
if (metadata) {
metadata = Object.assign({}, metadata); // copy
Expand All @@ -371,7 +371,7 @@ export default class MediaDbPlugin extends Plugin {
* @param fileContent
* @param options
*/
async createNote(fileName: string, fileContent: string, options: CreateNoteOptions) {
async createNote(fileName: string, fileContent: string, options: CreateNoteOptions): Promise<void> {
// find and possibly create the folder set in settings or passed in folder
const folder = options.folder ?? this.app.vault.getAbstractFileByPath('/');

Expand Down Expand Up @@ -403,7 +403,7 @@ export default class MediaDbPlugin extends Plugin {
* Update the active note by querying the API again.
* Tries to read the type, id and dataSource of the active note. If successful it will query the api, delete the old note and create a new one.
*/
async updateActiveNote(onlyMetadata: boolean = false) {
async updateActiveNote(onlyMetadata: boolean = false): Promise<void> {
const activeFile: TFile = this.app.workspace.getActiveFile();
if (!activeFile) {
throw new Error('MDB | there is no active note');
Expand All @@ -418,7 +418,7 @@ export default class MediaDbPlugin extends Plugin {
throw new Error('MDB | active note is not a Media DB entry or is missing metadata');
}

let oldMediaTypeModel = this.mediaTypeManager.createMediaTypeModelFromMediaType(metadata, metadata.type);
const oldMediaTypeModel = this.mediaTypeManager.createMediaTypeModelFromMediaType(metadata, metadata.type);
// console.debug(oldMediaTypeModel);

let newMediaTypeModel = await this.apiManager.queryDetailedInfoById(metadata.id, metadata.dataSource);
Expand All @@ -438,11 +438,11 @@ export default class MediaDbPlugin extends Plugin {
}
}

async createEntriesFromFolder(folder: TFolder) {
async createEntriesFromFolder(folder: TFolder): Promise<void> {
const erroredFiles: { filePath: string; error: string }[] = [];
let canceled: boolean = false;

const { selectedAPI, titleFieldName, appendContent } = await new Promise<{ selectedAPI: string; titleFieldName: string; appendContent: boolean }>((resolve, reject) => {
const { selectedAPI, titleFieldName, appendContent } = await new Promise<{ selectedAPI: string; titleFieldName: string; appendContent: boolean }>(resolve => {
new MediaDbFolderImportModal(this.app, this, (selectedAPI: string, titleFieldName: string, appendContent: boolean) => {
resolve({ selectedAPI, titleFieldName, appendContent });
}).open();
Expand All @@ -456,11 +456,11 @@ export default class MediaDbPlugin extends Plugin {
continue;
}

let metadata: any = this.getMetadataFromFileCache(file);
const metadata: any = this.getMetadataFromFileCache(file);

let title = metadata[titleFieldName];
const title = metadata[titleFieldName];
if (!title) {
erroredFiles.push({ filePath: file.path, error: `metadata field \'${titleFieldName}\' not found or empty` });
erroredFiles.push({ filePath: file.path, error: `metadata field '${titleFieldName}' not found or empty` });
continue;
}

Expand All @@ -476,7 +476,7 @@ export default class MediaDbPlugin extends Plugin {
continue;
}

let { selectModalResult, selectModal } = await this.modalHelper.createSelectModal({ elements: results, skipButton: true, modalTitle: `Results for \'${title}\'` });
const { selectModalResult, selectModal } = await this.modalHelper.createSelectModal({ elements: results, skipButton: true, modalTitle: `Results for '${title}'` });

if (selectModalResult.code === ModalResultCode.ERROR) {
erroredFiles.push({ filePath: file.path, error: selectModalResult.error.message });
Expand Down Expand Up @@ -520,30 +520,29 @@ export default class MediaDbPlugin extends Plugin {

const table = [['file', 'error']].concat(erroredFiles.map(x => [x.filePath, x.error]));

let fileContent = `# ${title}\n\n${markdownTable(table)}`;

const targetFile = await this.app.vault.create(filePath, fileContent);
const fileContent = `# ${title}\n\n${markdownTable(table)}`;
await this.app.vault.create(filePath, fileContent);
}

async loadSettings() {
async loadSettings(): Promise<void> {
// console.log(DEFAULT_SETTINGS);
const diskSettings: MediaDbPluginSettings = await this.loadData();
const defaultSettings: MediaDbPluginSettings = getDefaultSettings(this);
const loadedSettings: MediaDbPluginSettings = Object.assign({}, defaultSettings, diskSettings);

// migrate the settings loaded from the disk to match the structure of the default settings
let newPropertyMappings: PropertyMappingModel[] = [];
const newPropertyMappings: PropertyMappingModel[] = [];
for (const defaultPropertyMappingModel of defaultSettings.propertyMappingModels) {
let newPropertyMappingModel: PropertyMappingModel = loadedSettings.propertyMappingModels.find(x => x.type === defaultPropertyMappingModel.type);
const newPropertyMappingModel: PropertyMappingModel = loadedSettings.propertyMappingModels.find(x => x.type === defaultPropertyMappingModel.type);
if (newPropertyMappingModel === undefined) {
// if the propertyMappingModel exists in the default settings but not the loaded settings, add it
newPropertyMappings.push(defaultPropertyMappingModel);
} else {
// if the propertyMappingModel also exists in the loaded settings, add it from there
let newProperties: PropertyMapping[] = [];
const newProperties: PropertyMapping[] = [];

for (const defaultProperty of defaultPropertyMappingModel.properties) {
let newProperty = newPropertyMappingModel.properties.find(x => x.property === defaultProperty.property);
const newProperty = newPropertyMappingModel.properties.find(x => x.property === defaultProperty.property);
if (newProperty === undefined) {
// default property is an instance
newProperties.push(defaultProperty);
Expand All @@ -561,7 +560,7 @@ export default class MediaDbPlugin extends Plugin {
this.settings = loadedSettings;
}

async saveSettings() {
async saveSettings(): Promise<void> {
this.mediaTypeManager.updateTemplates(this.settings);
this.mediaTypeManager.updateFolders(this.settings);

Expand Down
6 changes: 3 additions & 3 deletions src/modals/MediaDbAdvancedSearchModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
this.closeCallback = closeCallback;
}

keyPressCallback(event: KeyboardEvent) {
keyPressCallback(event: KeyboardEvent): void {
if (event.key === 'Enter') {
this.search();
}
Expand Down Expand Up @@ -66,7 +66,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
}
}

onOpen() {
onOpen(): void {
const { contentEl } = this;

contentEl.createEl('h2', { text: this.title });
Expand Down Expand Up @@ -123,7 +123,7 @@ export class MediaDbAdvancedSearchModal extends Modal {
});
}

onClose() {
onClose(): void {
this.closeCallback();
const { contentEl } = this;
contentEl.empty();
Expand Down
Loading

0 comments on commit 48bef13

Please sign in to comment.