Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
private overridePaste: boolean = false;
private hasCustomCommands: boolean = false;
private customCommandsLock = new AsyncLock();
private originalSaveCallback?: () => void = null;
private originalSaveCallback?: (checking: boolean) => boolean | void = null;
// The amount of files you can use editor lint on at once is pretty small, so we will use an array
private editorLintFiles: TFile[] = [];
// the amount of files that can be linted as a file can be quite large, so we will want to use a set to make
Expand Down Expand Up @@ -322,15 +322,20 @@
this.originalSaveCallback = saveCommandDefinition?.checkCallback;

if (typeof this.originalSaveCallback === 'function') {
saveCommandDefinition.checkCallback = () => {
this.originalSaveCallback();
saveCommandDefinition.checkCallback = (checking: boolean) => {

Check failure on line 325 in src/main.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Block must not be padded by blank lines

if (checking) {
return this.originalSaveCallback(checking);
} else {
this.originalSaveCallback(checking)

Check failure on line 330 in src/main.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

if (this.settings.lintOnSave && this.isEnabled) {
const editor = this.getEditor();
if (editor) {
const file = this.app.workspace.getActiveFile();
if (!this.shouldIgnoreFile(file) && this.isMarkdownFile(file) && editor.cm) {
void this.runLinterEditor(editor);
const file = this.app.workspace.getActiveFile();
if (this.settings.lintOnSave && this.isEnabled) {
if (editor) {
if (!this.shouldIgnoreFile(file) && this.isMarkdownFile(file) && editor.cm) {
void this.runLinterEditor(editor);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here should be the same as the original to avoid trying to act on null or undefined files:

 if (this.settings.lintOnSave && this.isEnabled) {
          const editor = this.getEditor();
          if (editor) {
            const file = this.app.workspace.getActiveFile();
            if (!this.shouldIgnoreFile(file) && this.isMarkdownFile(file) && editor.cm) {
              if (!checking) {
                this.runLinterEditor(editor);
              }
              return true;
            }
          }
        }
      };

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface ObsidianCommandInterface {
executeCommandById(id: string): void;
commands: {
'editor:save-file': {
checkCallback(): void;
checkCallback(checking: boolean): boolean | void;
};
};
listCommands(): Command[];
Expand Down
Loading