All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.gradle_plugins.toolkit.build_logic.sonarlint.gradle Maven / Gradle / Ivy

There is a newer version: 0.64.11
Show newest version
import static org.gradle.api.artifacts.ArtifactRepositoryContainer.MAVEN_CENTRAL_URL
import static org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP

allprojects {
    pluginManager.withPlugin('java') {
        apply plugin: 'name.remal.sonarlint'
    }

    pluginManager.withPlugin('name.remal.sonarlint') {
        sonarLint {
            rules {
                disable(
                    // see https://rules.sonarsource.com/

                    'java:S110',  // Inheritance tree of classes should not be too deep
                    'java:S112',  // Generic exceptions should never be thrown
                    'java:S125',  // Sections of code should not be commented out
                    'java:S135',  // Loops should not contain more than a single "break" or "continue" statement
                    'java:S1066', // Collapsible "if" statements should be merged
                    'java:S1117', // Local variables should not shadow class fields
                    'java:S1119', // Labels should not be used
                    'java:S1126', // Return of boolean expressions should not be wrapped into an "if-then-else" statement
                    'java:S1133', // Deprecated code should be removed
                    'java:S1134', // Track uses of "FIXME" tags
                    'java:S1135', // Track uses of "TODO" tags
                    'java:S1171', // Only static class initializers should be used
                    'java:S1186', // Methods should not be empty
                    'java:S1192', // String literals should not be duplicated
                    'java:S1199', // Nested code blocks should not be used
                    'java:S1214', // Constants should not be defined in interfaces
                    'java:S1452', // Generic wildcard types should not be used in return types
                    'java:S1488', // Local variables should not be declared and then immediately returned or thrown
                    'java:S1602', // Lambdas containing only one statement should not nest this statement in a block
                    'java:S1610', // Abstract classes without fields should be converted to interfaces
                    'java:S1181', // Throwable and Error should not be caught
                    'java:S1874', // "@Deprecated" code should not be used
                    'java:S2259', // Null pointers should not be dereferenced
                    'java:S2583', // Conditionally executed code should be reachable
                    'java:S3077', // Non-primitive fields should not be "volatile"
                    'java:S3516', // Methods returns should not be invariant
                    'java:S5976', // Similar tests should be grouped in a single Parameterized test
                    'java:S5993', // Constructors of an "abstract" class should not be declared "public"
                    'java:S6548', // The Singleton design pattern should be used with care

                    'xml:S125', // Sections of code should not be commented out
                )
            }

            nodeJs {
                detectNodeJs = false
                logNodeJsNotFound = false
            }
        }

        tasks.register('allSonarlint') {
            group = VERIFICATION_GROUP
            dependsOn(project.provider { project.sourceSets.collect { SourceSet sourceSet -> sourceSet.getTaskName('sonarlint', null) } })
        }

        NamedDomainObjectSet sonarlintConfs = configurations.matching { startWithWord(it.name, 'sonarlint') }
        sonarlintConfs.configureEach { Configuration conf ->
            conf.extendsFrom = conf.extendsFrom.findAll { it.name != 'projectDependencyConstraints' }
        }

        pluginManager.withPlugin('java') {
            URI mavenCentralUri = project.uri(MAVEN_CENTRAL_URL)
            repositories.withType(MavenArtifactRepository)
                .matching { MavenArtifactRepository repo -> repo.url.scheme != 'file' && repo.url != mavenCentralUri }
                .configureEach { MavenArtifactRepository repo ->
                    repo.content { RepositoryContentDescriptor content ->
                        sonarlintConfs.all { Configuration conf ->
                            content.notForConfigurations(conf.name)
                        }
                    }
                }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy