Skip to content

Use stdlib functions for file & path operations#5754

Merged
3flex merged 13 commits into
detekt:mainfrom
3flex:paths-api
Feb 22, 2023
Merged

Use stdlib functions for file & path operations#5754
3flex merged 13 commits into
detekt:mainfrom
3flex:paths-api

Conversation

@3flex
Copy link
Copy Markdown
Member

@3flex 3flex commented Feb 4, 2023

I set out to remove these imports and use replacements from stdlib:

  • java.io.File
  • java.nio.file.Files
  • java.nio.file.Paths

I was mostly successful, held back by the detekt-gradle-plugin being on API version 1.4, and a couple of stdlib functions which still require an opt in. I chose not to use the opt in functions until they're stable, hopefully in Kotlin 1.9 if not before.

I recommend reviewing by individual commit as I've broken up the changes into logical chunks.

Comment thread detekt-psi-utils/src/main/kotlin/io/github/detekt/psi/KtFiles.kt Fixed
Comment thread detekt-psi-utils/src/main/kotlin/io/github/detekt/psi/KtFiles.kt Fixed
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2023

Codecov Report

Merging #5754 (91597c9) into main (728de81) will decrease coverage by 0.02%.
The diff coverage is 58.02%.

@@             Coverage Diff              @@
##               main    #5754      +/-   ##
============================================
- Coverage     84.60%   84.59%   -0.02%     
  Complexity     3790     3790              
============================================
  Files           547      547              
  Lines         12917    12909       -8     
  Branches       2262     2262              
============================================
- Hits          10929    10920       -9     
- Misses          861      862       +1     
  Partials       1127     1127              
Impacted Files Coverage Δ
.../detekt/compiler/plugin/DetektAnalysisExtension.kt 0.00% <0.00%> (ø)
...tekt/compiler/plugin/DetektCommandLineProcessor.kt 0.00% <0.00%> (ø)
...t/compiler/plugin/DetektCompilerPluginRegistrar.kt 0.00% <0.00%> (ø)
...in/kotlin/io/gitlab/arturbosch/detekt/core/Junk.kt 100.00% <ø> (ø)
...io/gitlab/arturbosch/detekt/core/KtFileModifier.kt 0.00% <0.00%> (ø)
.../arturbosch/detekt/core/baseline/BaselineFacade.kt 86.66% <0.00%> (ø)
...arturbosch/detekt/core/baseline/DefaultBaseline.kt 75.00% <0.00%> (ø)
...rturbosch/detekt/core/settings/ClassloaderAware.kt 63.63% <0.00%> (ø)
...b/arturbosch/detekt/core/tooling/AnalysisFacade.kt 62.85% <0.00%> (ø)
...tlin/io/gitlab/arturbosch/detekt/generator/Main.kt 38.46% <0.00%> (ø)
... and 25 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Copy Markdown
Contributor

@Goooler Goooler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And these ones

val config = File(value).toPath()
if (Files.notExists(config)) {
throw ParameterException("Provided path '$value' does not exist!")
}

class PathConverter : IStringConverter<Path> {
override fun convert(value: String): Path {
return Paths.get(value)
}
}

@3flex
Copy link
Copy Markdown
Member Author

3flex commented Feb 5, 2023

@Goooler
Copy link
Copy Markdown
Contributor

Goooler commented Feb 5, 2023

You are right, just see it.


fun Path.exists(): Boolean = Files.exists(this)
fun Path.isFile(): Boolean = Files.isRegularFile(this)
fun Path.isDirectory(): Boolean = Files.isDirectory(this)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

@BraisGabin
Copy link
Copy Markdown
Member

Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants