Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Configuration" example for Groovy Gradle files #26

Open
ghost opened this issue Jan 30, 2020 · 3 comments
Open

"Configuration" example for Groovy Gradle files #26

ghost opened this issue Jan 30, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 30, 2020

Hi,

Is possible to provide an example with "Configuration" but not for .kts Gradle files?

Thanks for a very useful library!

@cmargonis
Copy link

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 😄 )

@davidburstromspotify
Copy link
Contributor

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
}

@mattmook
Copy link
Member

mattmook commented Oct 4, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants