Repository: platers/obsidian-linter (ts)

Issue:
Bug: Should not handle inline code and block code.
## Describe the Bug

The inline code `h[^ae]llo` will be formatted as `h[^1]llo`.

## Device

- [x] Desktop
- [ ] Mobile



Pull request description:
Make Sure Inline Code Is not Affected by Footnote Rules
Fixes #641 

Changes Made:
- Added a UT for the scenario in question
- Ignored inline code for footnote rules

Patch:
diff --git a/src/rules/footnote-after-punctuation.ts b/src/rules/footnote-after-punctuation.ts
index c7a92ea..2f4de5d 100644
--- a/src/rules/footnote-after-punctuation.ts
+++ b/src/rules/footnote-after-punctuation.ts
@@ -18,7 +18,7 @@ export default class FootnoteAfterPunctuation extends RuleBuilder<FootnoteAfterP
     return FootnoteAfterPunctuationOptions;
   }
   apply(text: string, options: FootnoteAfterPunctuationOptions): string {
-    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag, IgnoreTypes.footnoteAtStartOfLine, IgnoreTypes.footnoteAfterATask], text, (text) => {
+    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag, IgnoreTypes.footnoteAtStartOfLine, IgnoreTypes.footnoteAfterATask], text, (text) => {
       return text.replace(/(\[\^\w+\]) ?([,.;!:?])/gm, '$2$1');
     });
   }
diff --git a/src/rules/move-footnotes-to-the-bottom.ts b/src/rules/move-footnotes-to-the-bottom.ts
index 32874ec..56d1e02 100644
--- a/src/rules/move-footnotes-to-the-bottom.ts
+++ b/src/rules/move-footnotes-to-the-bottom.ts
@@ -19,7 +19,7 @@ export default class MoveFootnotesToTheBottom extends RuleBuilder<MoveFootnotesT
     return MoveFootnotesToTheBottomOptions;
   }
   apply(text: string, options: MoveFootnotesToTheBottomOptions): string {
-    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.math, IgnoreTypes.yaml], text, (text) => {
+    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.yaml], text, (text) => {
       return moveFootnotesToEnd(text);
     });
   }
diff --git a/src/rules/re-index-footnotes.ts b/src/rules/re-index-footnotes.ts
index 5b265ce..93732bc 100644
--- a/src/rules/re-index-footnotes.ts
+++ b/src/rules/re-index-footnotes.ts
@@ -18,7 +18,7 @@ export default class ReIndexFootnotes extends RuleBuilder<ReIndexFootnotesOption
     return ReIndexFootnotesOptions;
   }
   apply(text: string, options: ReIndexFootnotesOptions): string {
-    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
+    return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.inlineCode, IgnoreTypes.math, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
       // re-index footnote-text
       let ft_index = 0;
       text = text.replace(/^\[\^\w+\]: /gm, function() {


Test patch:
diff --git a/__tests__/re-index-footnotes.test.ts b/__tests__/re-index-footnotes.test.ts
new file mode 100644
index 0000000..e149cde
--- /dev/null
+++ b/__tests__/re-index-footnotes.test.ts
@@ -0,0 +1,19 @@
+import ReIndexFootnotes from '../src/rules/re-index-footnotes';
+import dedent from 'ts-dedent';
+import {ruleTest} from './common';
+
+ruleTest({
+  RuleBuilderClass: ReIndexFootnotes,
+  testCases: [
+    { // accounts for https://github.com/platers/obsidian-linter/issues/641
+      testName: 'Inline code should not be affected by re-indexing footnotes',
+      before: dedent`
+        \`h[^ae]llo\`
+      `,
+      after: dedent`
+        \`h[^ae]llo\`
+      `,
+    },
+  ],
+});
+