Repository: platers/obsidian-linter (ts)

Issue:
Bug: remove-link-spacing removes spacing inside checkbox when followed by markdown link
Hello again.
I noticed today that when `remove-link-spacing` is active, empty check boxes (`- [ ]`) get nuked on lint. I don't use them often but when I do, I they get linted into oblivion. A sub-option on this to exclude checkboxes would be great.

Pull request description:
Fix Checkboxes Followed by Regular Markdown Link when Removing Whitespace from Link
Fixes #236 

It was reported that empty checkboxes followed by a link would have their whitespace removed. The regex was not preventing a beginning bracket from being added to the link text which is what caused the issue since it would attach it to the link itself.

Changes Made:
- updated the regex to no longer allow an opening square bracket ([) or new line character in link text for either wiki links or regular markdown links
- Added a test to allow us to make sure we do not accidentally create this issue again

Patch:
diff --git a/src/utils.ts b/src/utils.ts
index 03988bf..98f9704 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -13,7 +13,7 @@ export const backtickBlockRegexTemplate = fencedRegexTemplate.replaceAll('X', '`
 export const tildeBlockRegexTemplate = fencedRegexTemplate.replaceAll('X', '~');
 export const indentedBlockRegex = '^((\t|( {4})).*\n)+';
 export const codeBlockRegex = new RegExp(`${backtickBlockRegexTemplate}|${tildeBlockRegexTemplate}|${indentedBlockRegex}`, 'gm');
-export const linkRegex = /((!?)\[.*\]\(.*\))|(\[{2}.*\]{2})/g;
+export const linkRegex = /((!?)\[[^[\n]*\]\([^[\n]*\))|(\[{2}[^[\n]*\]{2})/g;
 export const tagRegex = /#[^\s#]{1,}/g;
 
 // Helper functions


Test patch:
diff --git a/src/test.ts b/src/test.ts
index 415f51f..2ba2fd5 100644
--- a/src/test.ts
+++ b/src/test.ts
@@ -976,6 +976,20 @@ describe('Links', () => {
 
     expect(rulesDict['capitalize-headings'].apply(before, {'Style': 'First letter'})).toBe(after);
   });
+  // accounts for https://github.com/platers/obsidian-linter/issues/236
+  it('Link after checkbox is not affected by removing whitespace in links', () => {
+    const before = dedent`
+    - [ ] [Link text](path/fileName.md)
+    - [ ] [[fileName]]
+    `;
+
+    const after = dedent`
+    - [ ] [Link text](path/fileName.md)
+    - [ ] [[fileName]]
+    `;
+
+    expect(rulesDict['remove-link-spacing'].apply(before)).toBe(after);
+  });
 });
 
 describe('Remove Multiple Spaces', () => {