Skip to content

Commit

Permalink
#242: ESLint: Replace 'any' with better data types.
Browse files Browse the repository at this point in the history
I didn't replace all 'anys' because in some cases replacing them caused hard to fix TypeScript compiler errors.
  • Loading branch information
Taitava committed Jul 17, 2022
1 parent 65b5d2b commit 2babe20
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function setDEBUG_ON(value: boolean) {
* Calls console.log(), but only if debugging is enabled.
* @param message
*/
export function debugLog(message: any) {
export function debugLog(message: unknown) {
if (DEBUG_ON) {
console.log(message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function EnsureShellCommandsHaveAllFields(plugin: SC_Plugin) {
const shell_command_configuration = shell_command_configurations[shell_command_id];
for (const property_name in shell_command_default_configuration) {
// @ts-ignore property_default_value can have (almost) whatever datatype
const property_default_value: any = shell_command_default_configuration[property_name];
const property_default_value = shell_command_default_configuration[property_name];
// @ts-ignore
if (undefined === shell_command_configuration[property_name]) {
// This shell command does not have this property.
Expand Down
2 changes: 1 addition & 1 deletion src/events/SC_VaultEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export abstract class SC_VaultEvent extends SC_Event {
}

protected getTrigger(t_shell_command: TShellCommand) {
return (file: TAbstractFile, ...extra_arguments: any[] /* Needed for SC_Event_FileRenamed and SC_Event_FolderRenamed to be able to define an additional parameter.*/) => {
return (file: TAbstractFile, ...extra_arguments: unknown[] /* Needed for SC_Event_FileRenamed and SC_Event_FolderRenamed to be able to define an additional parameter.*/) => {

// Check that it's the correct type of file: if the SC_Event requires a file, 'file' needs to be a TFile, otherwise it needs to be a TFolder.
if ((this.file_or_folder === "folder" && file instanceof TFolder) || (this.file_or_folder === "file" && file instanceof TFile)) {
Expand Down
2 changes: 1 addition & 1 deletion src/events/SC_WorkspaceEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export abstract class SC_WorkspaceEvent extends SC_Event {
}

protected getTrigger(t_shell_command: TShellCommand) {
return (...parameters: any[] /* Need to have this ugly parameter thing so that subclasses can define their own parameters. */) => this.trigger(t_shell_command);
return (...parameters: unknown[] /* Need to have this ugly parameter thing so that subclasses can define their own parameters. */) => this.trigger(t_shell_command);
}
}
2 changes: 1 addition & 1 deletion src/models/custom_variable/CustomVariableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class CustomVariableModel extends Model {
instance.getCustomVariable().updateProperties(); // Update the name also to the operational variable, not only in configuration.
await this.plugin.saveSettings();
this.plugin.updateCustomVariableViews();
}, (reason: string | any) => {
}, (reason: string | unknown) => {
// Not valid
if (typeof reason === "string") {
// This is a validation error message.
Expand Down
2 changes: 1 addition & 1 deletion src/models/custom_variable/CustomVariableView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class CustomVariableView extends ItemView {
custom_variable_value = "An empty text.";
emphasize = true;
}
const variable_list_element: any = this.container_element.createEl("ul");
const variable_list_element: HTMLUListElement = this.container_element.createEl("ul");
const variable_list_item_element = variable_list_element.createEl("li", {
text: custom_variable_instance.getFullName(),
attr: {
Expand Down
2 changes: 1 addition & 1 deletion src/models/prompt/PromptModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class PromptModal extends SC_Modal {
this.resolve_promise(true);
this.user_confirmed_ok = true;
this.close();
}, (error_messages: string[] | any) => {
}, (error_messages: string[] | unknown) => {
if (Array.isArray(error_messages)) {
// There were some problems with the fields.
this.plugin.newErrors(error_messages);
Expand Down
4 changes: 2 additions & 2 deletions src/models/prompt/prompt_fields/PromptField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ export abstract class PromptField extends Instance {
* Gets a value from the form field.
* @protected
*/
protected abstract getValue(): any;
protected abstract getValue(): string;

/**
* Sets a value to the form field.
* @param value
* @protected
*/
protected abstract setValue(value: any): void;
protected abstract setValue(value: string): void;

/**
* Parses the default value and sets it to the form element.
Expand Down
2 changes: 1 addition & 1 deletion src/models/prompt/prompt_fields/PromptFieldModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class PromptFieldModel extends Model {
prompt_field.setIfValid("target_variable_id", new_target_variable_id).then(async () => {
// It can be used.
await this.plugin.saveSettings();
}, (error_message: string | any) => {
}, (error_message: string | unknown) => {
if (typeof error_message === "string") {
// This is a validation error message.
// The target variable is reserved.
Expand Down
2 changes: 1 addition & 1 deletion src/output_channels/OutputChannelDriverFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function getOutputChannelDriversOptionList(output_stream: OutputStream) {
[key: string]: string;
} = {ignore: "Ignore"};
for (const name in output_channel_drivers) {
const output_channel_driver: any = output_channel_drivers[name];
const output_channel_driver: OutputChannelDriver = output_channel_drivers[name];
// Check that the stream is suitable for the channel
if (output_channel_driver.acceptsOutputStream(output_stream)) {
list[name] = output_channel_driver.getTitle(output_stream);
Expand Down
2 changes: 1 addition & 1 deletion src/output_channels/OutputChannelDriver_OpenFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class OutputChannelDriver_OpenFiles extends OutputChannelDriver {
}
}, 500); // 500ms is probably long enough even if a new tab is opened (takes more time than opening a file into an existing tab). This can be made into a setting sometime. If you change this, remember to change it in the documentation, too.
}
}, (error_message: string | any) => {
}, (error_message: string | unknown) => {
if (typeof error_message === "string") {
// Opening the file has failed.
this.plugin.newError(error_message);
Expand Down
4 changes: 2 additions & 2 deletions src/settings/ExtraOptionsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,13 @@ export class ExtraOptionsModal extends SC_Modal {
"value": "Execute with value:",
})
.setValue(default_value_configuration ? default_value_configuration.type : "show-errors")
.onChange(async (new_type: string) => {
.onChange(async (new_type: typeof default_value_configuration.type) => {
if (!default_value_configuration) {
default_value_configuration = create_default_value_configuration();
}

// Set the new type
default_value_configuration.type = new_type as any;
default_value_configuration.type = new_type;
if ("show-errors" === new_type && default_value_configuration.value === "") {
// If "show-errors" is selected and no text value is typed, the configuration file can be cleaned up by removing this configuration object completely.
// Prevent deleting, if a text value is present, because the user might want to keep it if they will later change 'type' to 'value'.
Expand Down
3 changes: 2 additions & 1 deletion src/settings/setting_elements/Autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export function addCustomAutocompleteItems(custom_autocomplete_yaml: string) {
}

// Try to parse YAML syntax
let yaml: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let yaml: any; // 'any' is defined in obsidian.d.ts for the return type of parseYaml(), so I made ESLint ignore it.
try {
yaml = parseYaml(custom_autocomplete_yaml);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/variables/Variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export abstract class Variable {
}

interface IArguments {
[key: string]: any;
[key: string]: unknown;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/variables/parseVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function parseVariables(
parsing_result.count_parsed_variables++;

// Remove stuff that should not be iterated in a later loop.
const _arguments = argument_matches.filter((value: any/* Won't be used */, key: any) => {
const _arguments = argument_matches.filter((value: unknown /* Won't be used */, key: unknown) => {
return "number" === typeof key;
// This leaves out for example the following non-numeric keys (and their values):
// - "groups"
Expand Down

0 comments on commit 2babe20

Please sign in to comment.