markdown-lint
markdown-lint copied to clipboard
"Configuration" example for Groovy Gradle files
Hi,
Is possible to provide an example with "Configuration" but not for .kts Gradle files?
Thanks for a very useful library!
Hello, thanks for this awesome plugin 🎉 !
I too think a sample for configuring the plugin via a groovy build script, would be of great help. (I would/could contribute a PR for this, if I manage to figure it out 😄 )
The Kotlin DSL classes in the plugin don't lend themselves conveniently for expressing the same thing in Groovy. This is a Groovy conversion of the example in the README.md. Please note that the default rule parameters need to be explicitly specified. I believe adding @JvmOverloads to the rule constructors could mitigate this. The operator overloading unaryPlus is also a problem for Groovy. Here goes:
plugins {
id 'com.appmattus.markdown' version '0.6.0'
}
import com.appmattus.markdown.rules.config.HeaderStyle
import com.appmattus.markdown.rules.ConsistentHeaderStyleRule
import com.appmattus.markdown.rules.NoDuplicateHeaderRule
import com.appmattus.markdown.rules.SingleH1Rule
markdownlint.with {
// Optional - Use to override settings for individual rules or add in custom rules
rules { rb ->
// Change the default settings of a rule
rb.unaryPlus(new ConsistentHeaderStyleRule(HeaderStyle.Atx, {rsb -> }))
rb.unaryPlus(new NoDuplicateHeaderRule(false, { rsb ->
// Include files using RegEx for this rule, default=".*" (i.e. all files)
includes = [".*/directory_to_include/.*"]
// Exclude files using RegEx for this rule, default=empty (i.e. exclude nothing)
excludes = [".*/a_file_to_exclude.md"]
}))
// Disable a rule by setting active to false
rb.unaryPlus(new SingleH1Rule(1, { rsb ->
rsb.active = false
}))
}
// Optional - Include files using RegEx for ALL rules, default=".*" (i.e. all files in root project directory)
includes = [".*/directory_to_include/.*"]
// Optional - Exclude files using RegEx for ALL rules, default=empty (i.e. exclude nothing)
excludes = [".*/a_file_to_exclude.md"]
// Optional - Specify the reports to generate, default=html,checkstyle
// If you specify the reports block the plugin will output only the types
// specified i.e. to output no reports implement an empty block
reports { rb ->
// enable html report
rb.html()
// enable checkstyle xml report
rb.checkstyle()
}
// Optional - Specify the error count threshold that triggers a failed build, default=0
threshold = 10
}
Thanks @davidburstromspotify for the helpful comment.
I've been meaning to look into this myself for quite a while! Since I wrote the initial version of the plugin I'm certain there are better ways I can create the configuration that would provide better compatibility for both Groovy and Kotlin DSL.