matrei commented on code in PR #15686: URL: https://github.com/apache/grails-core/pull/15686#discussion_r3334884023
########## build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/GrailsCodeStylePluginSpec.groovy: ########## @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.grails.buildsrc + +import org.gradle.testkit.runner.GradleRunner +import spock.lang.Specification +import spock.lang.TempDir +import java.nio.file.Path + +class GrailsCodeStylePluginSpec extends Specification { + @TempDir + Path testProjectDir + + File buildFile + File groovyFile + + def setup() { + buildFile = testProjectDir.resolve('build.gradle').toFile() + buildFile << """ + plugins { + id 'groovy' + id 'org.apache.grails.gradle.grails-code-style' + } + + // Minimal configuration for the plugin + repositories { + mavenCentral() + } + """ + + testProjectDir.resolve('src/main/groovy').toFile().mkdirs() + groovyFile = testProjectDir.resolve('src/main/groovy/Test.groovy').toFile() + } + + def "test codenarcFix task fixes violations"() { + given: "a file with violations" + groovyFile.text = """package org.test + +class Test{ + def map = [key:"value"] + def str = "unnecessary gstring" + def semi = "semicolon"; + def lines = 1 + + + def other = 2 +} +""" + when: "running codenarcFix" + def result = GradleRunner.create() + .withProjectDir(testProjectDir.toFile()) + .withArguments('codenarcFix', '--stacktrace') + .withPluginClasspath() + .build() + + then: "task finished successfully" + result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS Review Comment: Unnecessary qualified reference? (here and below) ########## build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GradleUtils.groovy: ########## @@ -37,6 +38,12 @@ class GradleUtils { asfFile.exists() ? currentDirectory : findAsfRootDir(currentDirectory.dir('../')) } + static Provider<Boolean> booleanProvider(Project project, String name, boolean defaultValue = false) { + project.providers.gradleProperty(name) + .map { String it -> it.trim().toBoolean() } Review Comment: No need for explicit `it` parameter? ########## .idea/codeStyles/codeStyleConfig.xml: ########## @@ -1,25 +1,5 @@ -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> <component name="ProjectCodeStyleConfiguration"> <state> - <option name="USE_PER_PROJECT_SETTINGS" value="true" /> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default copy" /> Review Comment: What happened here? ########## .idea/codeStyles/Project.xml: ########## @@ -1,105 +1,97 @@ -<!-- - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - ---> <component name="ProjectCodeStyleConfiguration"> - <code_scheme name="Project" version="173"> - <option name="AUTODETECT_INDENTS" value="false"/> - <GroovyCodeStyleSettings> - <option name="ENABLE_GROOVYDOC_FORMATTING" value="false"/> - <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/> - <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/> - <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND"> - <value/> - </option> - <option name="IMPORT_LAYOUT_TABLE"> - <value> - <package name="java" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="javax" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="groovy" withSubpackages="true" static="false"/> - <package name="org.apache.groovy" withSubpackages="true" static="false"/> - <package name="org.codehaus.groovy" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="jakarta" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="io.spring" withSubpackages="true" static="false"/> - <package name="org.springframework" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="grails" withSubpackages="true" static="false"/> - <package name="org.apache.grails" withSubpackages="true" static="false"/> - <package name="org.grails" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="" withSubpackages="true" static="true"/> - </value> - </option> - </GroovyCodeStyleSettings> - <JavaCodeStyleSettings> - <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/> - <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/> - <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND"> - <value/> - </option> - <option name="IMPORT_LAYOUT_TABLE"> - <value> - <package name="java" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="javax" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="groovy" withSubpackages="true" static="false"/> - <package name="org.apache.groovy" withSubpackages="true" static="false"/> - <package name="org.codehaus.groovy" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="jakarta" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="io.spring" withSubpackages="true" static="false"/> - <package name="org.springframework" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="grails" withSubpackages="true" static="false"/> - <package name="org.apache.grails" withSubpackages="true" static="false"/> - <package name="org.grails" withSubpackages="true" static="false"/> - <emptyLine/> - <package name="" withSubpackages="true" static="true"/> - </value> - </option> - <option name="ENABLE_JAVADOC_FORMATTING" value="false"/> - </JavaCodeStyleSettings> - <editorconfig> - <option name="ENABLED" value="false"/> - </editorconfig> - <codeStyleSettings language="Groovy"> - <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1"/> - </codeStyleSettings> - <codeStyleSettings language="JAVA"> - <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1"/> - <option name="KEEP_BLANK_LINES_IN_CODE" value="1"/> - <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1"/> - <option name="ARRAY_INITIALIZER_WRAP" value="1"/> - <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true"/> - <indentOptions> - <option name="CONTINUATION_INDENT_SIZE" value="4"/> - </indentOptions> - </codeStyleSettings> - </code_scheme> + <code_scheme name="Project" version="173"> + <option name="AUTODETECT_INDENTS" value="false" /> Review Comment: Refrain from functional and whitespace changes in the same commit? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
