Repository: platers/obsidian-linter
Pull request #355 (2022-08-15 17:56:18)

Fixed Removal of Empty List Markers in Some Cases and Updated Some Documentation
Changes Made:
- Updated readme template to note that each rule is independent of each other and that some of them are not designed to be run together giving a specific example of this
- Added documentation on how to run a specific set of tests
- Added extra info to Format Yaml Arrays and Remove Spaces Around FullWidth Characters
- Fixed an issue where an empty list marker would not be removed in an otherwise empty file or if it was not followed by a blank line


Patch:
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 29ab65a..61da3a4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -122,6 +122,8 @@ To update the documentation you can run `npm run compile` if you need to compile
 
 Tests are run by jest. They can be run by either running `npm run test` or `npm run compile`. The output will let you know how many of the tests passed and if any failed, why they failed.
 
+If you know the suite of tests that you would like to run, you can use `npm run test-suite TEST_SUITE_HERE` to run just the desired test suite. The test suite names are the names of the files in `__tests` minus `.test.ts`. So for example, `npm run test-suite format-yaml-arrays` would run the test suite for formatting yaml arrays. _Note: this does not run the examples for that rule as all examples are bundled together in the examples test suite._
+
 ## Linting Files
 
 Files should be linted prior to creating a pull request. The linter will make sure that the code follows the desired codestyle and formats the files as needed. The linter can be run by `npm run lint` or `npm run compile`
diff --git a/README.md b/README.md
index 1379e35..1e92888 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,8 @@ Add `disabled rules: [ all ]` to the YAML frontmatter of a file to disable all r
 
 Documentation for all rules can be found in the [rules docs](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md). The docs are updated before the plugin is released, so may not be completely accurate.
 
+Each rule is its own set of logic and is designed to be run independently. This means that enabling certain rules together could cause undesired results. One such case would be using "Paragraph blank lines" with "Two Spaces Between Lines with Content". These two rules have some overlap in what they target to change which results in undesired or unexpected results since together they work differently than if they were run by themselves.
+
 
 ### YAML rules
 
diff --git a/docs/readme_template.md b/docs/readme_template.md
index 42c6874..0012445 100644
--- a/docs/readme_template.md
+++ b/docs/readme_template.md
@@ -35,6 +35,8 @@ Add `disabled rules: [ all ]` to the YAML frontmatter of a file to disable all r
 
 Documentation for all rules can be found in the [rules docs](https://github.com/platers/obsidian-linter/blob/master/docs/rules.md). The docs are updated before the plugin is released, so may not be completely accurate.
 
+Each rule is its own set of logic and is designed to be run independently. This means that enabling certain rules together could cause undesired results. One such case would be using "Paragraph blank lines" with "Two Spaces Between Lines with Content". These two rules have some overlap in what they target to change which results in undesired or unexpected results since together they work differently than if they were run by themselves.
+
 {{RULES PLACEHOLDER}}
 
 ## Installing
diff --git a/docs/rules.md b/docs/rules.md
index 6b8683a..af6f982 100644
--- a/docs/rules.md
+++ b/docs/rules.md
@@ -200,7 +200,7 @@ Options:
 	- `single string comma delimited`: ```aliases: Title, Other Title```
 	- `single string to single-line`: Aliases will be formatted as a string if there is 1 or fewer elements like so ```aliases: Title```. If there is more than 1 element, it will be formatted like a single-line array.
 	- `single string to multi-line`: Aliases will be formatted as a string if there is 1 or fewer elements like so ```aliases: Title```. If there is more than 1 element, it will be formatted like a multi-line array.
-- Format yaml aliases section: Turns on formatting for the yaml aliases section
+- Format yaml aliases section: Turns on formatting for the yaml aliases section. You should not enable this option alongside the rule `YAML Title Alias` as they may not work well together or they may have different format styles selected causing unexpected results.
 	- Default: `true`
 - Yaml tags section style: The style of the yaml tags section
 	- Default: `single-line`
@@ -2440,7 +2440,7 @@ After:
 
 Alias: `remove-space-around-fullwidth-characters`
 
-Ensures that fullwidth characters are not followed by whitespace (either single spaces or a tab)
+Ensures that fullwidth characters are not followed by whitespace (either single spaces or a tab). Note that this may causes issues with markdown format in some cases.
 
 
 
diff --git a/src/rules/format-yaml-arrays.ts b/src/rules/format-yaml-arrays.ts
index e621e5c..593f9fc 100644
--- a/src/rules/format-yaml-arrays.ts
+++ b/src/rules/format-yaml-arrays.ts
@@ -190,7 +190,7 @@ export default class RuleTemplate extends RuleBuilder<FormatYamlArrayOptions> {
       new BooleanOptionBuilder({
         OptionsClass: FormatYamlArrayOptions,
         name: 'Format yaml aliases section',
-        description: 'Turns on formatting for the yaml aliases section',
+        description: 'Turns on formatting for the yaml aliases section. You should not enable this option alongside the rule `YAML Title Alias` as they may not work well together or they may have different format styles selected causing unexpected results.',
         optionsKey: 'formatAliasKey',
       }),
       new DropdownOptionBuilder({
diff --git a/src/rules/remove-empty-list-markers.ts b/src/rules/remove-empty-list-markers.ts
index fbb02df..4675b46 100644
--- a/src/rules/remove-empty-list-markers.ts
+++ b/src/rules/remove-empty-list-markers.ts
@@ -22,7 +22,13 @@ export default class RemoveEmptyListMarkers extends RuleBuilder<RemoveEmptyListM
   }
   apply(text: string, options: RemoveEmptyListMarkersOptions): string {
     return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
-      return text.replace(/^\s*(>\s*)*(-|\*|\+|\d+.|- (\[( |x)\]))\s*?$\n/gm, '');
+      const emptyListMarkerRegex = /^\s*(>\s*)*(-|\*|\+|\d+.|- (\[( |x)\]))\s*?$/gm;
+      // remove all empty list markers followed by a new line
+      text = text.replace(new RegExp(emptyListMarkerRegex.source + '\\n', 'gm'), '');
+      // remove all empty list markers proceeded by a new line
+      text = text.replace(new RegExp('\\n' + emptyListMarkerRegex.source, 'gm'), '');
+      // remove all empty list markers where they are the only line in the file
+      return text.replace(emptyListMarkerRegex, '');
     });
   }
   get exampleBuilders(): ExampleBuilder<RemoveEmptyListMarkersOptions>[] {
diff --git a/src/rules/remove-space-around-fullwidth-characters.ts b/src/rules/remove-space-around-fullwidth-characters.ts
index 17812ce..6811f64 100644
--- a/src/rules/remove-space-around-fullwidth-characters.ts
+++ b/src/rules/remove-space-around-fullwidth-characters.ts
@@ -16,7 +16,7 @@ export default class RemoveSpaceAroundFullwidthCharacters extends RuleBuilder<Re
     return 'Remove Space around Fullwidth Characters';
   }
   get description(): string {
-    return 'Ensures that fullwidth characters are not followed by whitespace (either single spaces or a tab)';
+    return 'Ensures that fullwidth characters are not followed by whitespace (either single spaces or a tab). Note that this may causes issues with markdown format in some cases.';
   }
   get type(): RuleType {
     return RuleType.SPACING;


Test patch:
diff --git a/__tests__/remove-empty-list-markers.test.ts b/__tests__/remove-empty-list-markers.test.ts
new file mode 100644
index 0000000..4bab0b0
--- /dev/null
+++ b/__tests__/remove-empty-list-markers.test.ts
@@ -0,0 +1,28 @@
+import RemoveEmptyListMarkers from '../src/rules/remove-empty-list-markers';
+import dedent from 'ts-dedent';
+import {ruleTest} from './common';
+
+ruleTest({
+  RuleBuilderClass: RemoveEmptyListMarkers,
+  testCases: [
+    {
+      testName: 'Remove empty list markers that do not have a new line after them',
+      before: dedent`
+        * Some list item 1
+        *
+      `,
+      after: dedent`
+        * Some list item 1
+      `,
+    },
+    {
+      testName: 'Remove empty list markers that are the only line in the file',
+      before: dedent`
+        *
+      `,
+      after: dedent`
+        ${''}
+      `,
+    },
+  ],
+});