Skip to content

Commit

Permalink
Move the generated checkstyle config to root dir (#66442)
Browse files Browse the repository at this point in the history
Storing the generated config in the `build` dir meant that it could be
removed for various reasons, which causes e.g. IntelliJ to pop up
dialog, and is a mild annoyance. Instead, write the file to the project
root.

Also inline the path to the suppressions config, which removes a step
from the setup instructions.
  • Loading branch information
pugnascotia authored Dec 16, 2020
1 parent 7c65a2b commit a9118e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ testfixtures_shared/

# These are generated from .ci/jobs.t
.ci/jobs/

# Generated
checkstyle_ide.xml
16 changes: 6 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,13 @@ it is removed due to a `./gradlew clean` or other action.
3. Check the "+" under "Configuration file"
4. Set "Description" to "Elasticsearch" (or whatever you want)
5. Select "Use a local Checkstyle file"
6. For the "File", navigate to `build/checkstyle_ide.xml`
6. For the "File", enter `checkstyle_ide.xml`
7. Tick "Store relative to project location"
8. Click "Next"
9. The Checkstyle config file contains the variable `config_loc`, and
IntelliJ will ask for a value. Fill in `buildSrc/src/main/resources`.
This allows the config file to reference the exclusions file in that directory.
10. Click "Next", then "Finish".
11. Click the box next to the new configuration to make it "Active". Without doing this,
you'll have to explicitly choose the "Elasticsearch" configuration in the Checkstyle
tool window and run the check manually. You can still do this with an active config.
12. Click "OK" to apply the new preferences
8. Click "Next", then "Finish".
9. Click the box next to the new configuration to make it "Active". Without doing this,
you'll have to explicitly choose the "Elasticsearch" configuration in the Checkstyle
tool window and run the check manually. You can still do this with an active config.
10. Click "OK" to apply the new preferences

#### Formatting

Expand Down
12 changes: 9 additions & 3 deletions gradle/ide.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tasks.register('configureIdeCheckstyle') {
description = 'Generated a suitable checkstyle config for IDEs'

String checkstyleConfig = 'buildSrc/src/main/resources/checkstyle.xml'
String checkstyleIdeConfig = "${buildDir}/checkstyle_ide.xml"
String checkstyleIdeConfig = "$rootDir/checkstyle_ide.xml"

inputs.files(file(checkstyleConfig))
outputs.files(file(checkstyleIdeConfig))
Expand All @@ -43,7 +43,7 @@ tasks.register('configureIdeCheckstyle') {
)
// Edit the copy so that IntelliJ can copy with it
modifyXml(checkstyleIdeConfig, { xml ->
// This module since it is implemented with custom code
// Remove this module since it is implemented with custom code
xml.module.findAll { it.'@name' == 'org.elasticsearch.gradle.checkstyle.SnippetLengthCheck' }.each { it.parent().remove(it) }

// Move the line length check because the IDE thinks it can't belong under a TreeWalker. Moving the
Expand All @@ -52,11 +52,17 @@ tasks.register('configureIdeCheckstyle') {
Node lineLength = treeWalker.module.find { it.'@name' == 'LineLength' }
treeWalker.remove(lineLength)
xml.append(lineLength)

// Change the checkstyle config to inline the path to the
// suppressions config. This removes a configuration step when using
// the checkstyle config in an IDE.
Node suppressions = xml.module.find { it.'@name' == 'SuppressionFilter' }
suppressions.property.findAll { it.'@name' == 'file' }.each { it.'@value' = "buildSrc/src/main/resources/checkstyle_suppressions.xml" }
},
"<!DOCTYPE module PUBLIC\n" +
" \"-//Puppy Crawl//DTD Check Configuration 1.3//EN\"\n" +
" \"http://www.puppycrawl.com/dtds/configuration_1_3.dtd\">\n" +
"<!-- Generated automatically from ./checkstyle.xml - do not edit this file directly. -->\n"
"<!-- Generated automatically from ${checkstyleConfig} - do not edit this file directly. -->\n"
)
}
}
Expand Down

0 comments on commit a9118e0

Please sign in to comment.