Skip to content

Commit

Permalink
Fixes to ProperNamesRule (#10)
Browse files Browse the repository at this point in the history
* ProperNamesRule fix codeBlocks logic and now ignores code block language
  • Loading branch information
mattmook authored Apr 16, 2019
1 parent e27d22e commit 97f7782
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.appmattus.markdown.errors.ErrorReporter
import com.appmattus.markdown.processing.MarkdownDocument
import com.vladsch.flexmark.ast.AutoLink
import com.vladsch.flexmark.ast.Code
import com.vladsch.flexmark.ast.FencedCodeBlock
import com.vladsch.flexmark.ast.Link
import com.vladsch.flexmark.util.sequence.BasedSequence
import org.nibor.autolink.LinkExtractor
Expand Down Expand Up @@ -53,20 +54,21 @@ class ProperNamesRule(

elements.addAll(
document.allText
.filterNot { it.parent is Link || it.parent is Code || it.parent is AutoLink }
.filterNot {
it.parent is Link || it.parent is Code || it.parent is AutoLink || it.parent is FencedCodeBlock
}
.map { it.chars }
)


elements.addAll(
document.links
.filterNot { it.text.isLink() }
.map { it.text }
)

if (!codeBlocks) {
if (codeBlocks) {
elements.addAll(document.inlineCode.map { it.text })
elements.addAll(document.codeBlocks.map { it.chars })
elements.addAll(document.codeBlocks.map { it.contentChars })
}

elements.forEach { text ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import org.spekframework.spek2.style.gherkin.Feature

object ProperNamesRuleTest : Spek({
Feature("ProperNamesRule") {
FileRuleScenario(listOf("proper-names-codeblocks.md")) { ProperNamesRule(codeBlocks = true) }

FileRuleScenario(listOf("proper-names-ignore-codeblocks.md")) { ProperNamesRule(codeBlocks = false) }

FileRuleScenario(listOf("proper-names-projects.md")) {
ProperNamesRule(
names = listOf(
Expand All @@ -17,11 +21,10 @@ object ProperNamesRuleTest : Spek({
"Vue",
"vue-router"
),
codeBlocks = true
codeBlocks = false
)
}

FileRuleScenario(exclude = listOf("proper-names-projects.md")) { ProperNamesRule() }

FileRuleScenario(exclude = listOf("proper-names-projects.md")) { ProperNamesRule(codeBlocks = true) }
}
})
6 changes: 6 additions & 0 deletions markdown/src/test/resources/proper-names-codeblocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

```java
Type above should not trigger but java will trigger {ProperNamesRule}
```

`java` will also trigger {ProperNamesRule}
6 changes: 6 additions & 0 deletions markdown/src/test/resources/proper-names-ignore-codeblocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

```java
Type above should not trigger the proper names rule nor should java
```

`java` should not trigger the rule either
4 changes: 4 additions & 0 deletions markdown/src/test/resources/proper-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ Bare URL exempt https://github.com/DavidAnson/MARKDOWNLINT {NoBareUrlsRule}
A short paragraph
about node.js and {ProperNamesRule}
javascript. {ProperNamesRule}

```java
java will trigger {ProperNamesRule} but the block language will not
```

0 comments on commit 97f7782

Please sign in to comment.