Skip to content

Conversation

@kdnk
Copy link
Contributor

@kdnk kdnk commented May 27, 2025

Copy link
Collaborator

@pjkaufman pjkaufman left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. There are just a couple of recommended changes.

src/main.ts Outdated
if (!checking) {
this.runLinterEditor(editor);
}
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe true should only be returned here if the active file is not null/the editor exists. Checking determines if the command should show.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This command is overriding editor:save-file, so I'm starting to think that the condition returning true and "lint on save is enabled" are unrelated. In other words, the condition that returns true should be outside the if statement for lintOnSave and isEnabled.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should respect the original checkCallback in editor:save-file while checking, so the following code makes sense to me. WDYT?

        if (checking) {
          return this.originalSaveCallback(checking);
        } else {
          const editor = this.getEditor();
          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 checking status should really be handled at the start of the function. If we are checking, we should go ahead and just check right after the logic for running the original callback. If we are checking, we should return whatever the original callback returns. Otherwise we proceed as normal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the change you posted above for the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pjkaufman Thank you!
I committed the changes. Could you review this PR again?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No problem. I just did put in another review.

Copy link
Collaborator

@pjkaufman pjkaufman left a comment

Choose a reason for hiding this comment

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

Looks like there are two lint issues plus a change in the actual meaning of the save callback logic added by the Linter.

src/main.ts Outdated
Comment on lines 333 to 338
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;
            }
          }
        }
      };

Copy link
Collaborator

@pjkaufman pjkaufman left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for making this change.

@pjkaufman pjkaufman merged commit cfaacde into platers:master May 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants