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

ignoreLines feature for filtering the input file #307

Merged
merged 19 commits into from
Nov 24, 2021

Conversation

sanyavertolet
Copy link
Member

@sanyavertolet sanyavertolet commented Nov 5, 2021

feature/ignoreLines

This pull request closes #133

What's done:

  • Added ignoreLines option for Warn plugin.
  • Added tests for ignoreLines and Warn plugin.
  • Added ignoreLines option for Fix plugin.
  • Added tests for ignoreLines and Fix plugin.
  • Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

sanyavertolet added 2 commits November 5, 2021 11:33
###What's done:
 * Added ignoreLines option for Fix plugin.
 * Added tests for ignoreLines and Fix plugin.
 * Added ignoreLines option for Warn plugin.
 * Added tests for ignoreLines and Warn plugin.
 * Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#303)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.

(#303)
suiteName = "Autofix: Smoke Tests"

[fix]
ignoreLines = ["// IGNORE_ME"]
Copy link
Member

Choose a reason for hiding this comment

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

may be test with regex here?

Copy link
Member

Choose a reason for hiding this comment

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

and better to test with several different regexes

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

sanyavertolet and others added 3 commits November 5, 2021 12:07
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.

(#303)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
@@ -74,6 +79,7 @@ data class GeneralConfig(
val runConfigPattern: Regex? = null,
) : PluginConfig {
override val type = TestConfigSections.GENERAL
override var ignoreLinesPatterns: MutableList<Regex> = mutableListOf()
Copy link
Member

Choose a reason for hiding this comment

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

why var here?

Copy link
Member Author

Choose a reason for hiding this comment

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

val should be here

/**
* list of regexes to be ignored
*/
var ignoreLinesPatterns: MutableList<Regex>
Copy link
Member

@orchestr7 orchestr7 Nov 6, 2021

Choose a reason for hiding this comment

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

why var should be here? Because of the hierarchical inheritance of configs?

Copy link
Member Author

Choose a reason for hiding this comment

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

val should be here

@@ -26,14 +26,19 @@ data class FixAndWarnPluginConfig(
override var configLocation: Path = "undefined_toml_location".toPath()
override val resourceNamePatternStr: String = "(${fix.resourceNamePatternStr})|(${warn.resourceNamePatternStr})"

@Transient
Copy link
Member

Choose a reason for hiding this comment

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

why @Transient? I though that we deserialize this value from toml config

Copy link
Member Author

Choose a reason for hiding this comment

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

The point it that we deserialize ignoreLines from toml config. ignoreLinesPatterns is initialized with ignoreLines that we parse from config so it is not deserialized directly from toml.

}
}
companion object {
internal val defaultIgnoreLines: MutableList<Regex> = mutableListOf()
Copy link
Member

@orchestr7 orchestr7 Nov 6, 2021

Choose a reason for hiding this comment

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

Do we really need an extra constant for it? May be you will simply set the default value (mutableListOf()) in place, where it is created?

Copy link
Member Author

Choose a reason for hiding this comment

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

To my mind it looked nicer. But ok, it seems that we don't need it here.

val pathCopy: Path = constructPathForCopyOfTestFile(FixPlugin::class.simpleName!!, path)
createTempDir(pathCopy.parent!!)

val expectedWarningPattern = generalConfig.expectedWarningsPattern
val defaultIgnoreLinesPatterns: MutableList<Regex> = mutableListOf()
Copy link
Member

@orchestr7 orchestr7 Nov 6, 2021

Choose a reason for hiding this comment

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

why is it named as defaultIgnoreLinesPatterns? Why "default"? You are adding values to this list, is it really default?

Copy link
Member Author

Choose a reason for hiding this comment

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

If ignoreLines is not set in config file, I should use expectedWarningsPattern and runConfigPattern by default. So the values I add to this list are values for default case. In this way I think default is ok here.

fixPluginConfig.ignoreLinesPatterns.none { pattern -> pattern.matches(line) }
}
?: run {
defaultIgnoreLinesPatterns.none {regex -> regex.matches(line) }
Copy link
Member

Choose a reason for hiding this comment

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

diktat is not working? where are spaces after {

Copy link
Member

Choose a reason for hiding this comment

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

gradlew.bat diktatFixAll

Copy link
Member Author

@sanyavertolet sanyavertolet Nov 15, 2021

Choose a reason for hiding this comment

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

Interesting. Seems like this case is ignored by diktat.

fs.readLines(path)
.filter { line ->
fixPluginConfig.ignoreLines?.let {
fixPluginConfig.ignoreLinesPatterns.none { pattern -> pattern.matches(line) }
Copy link
Member

Choose a reason for hiding this comment

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

use it in such small lambdas, it looks better with such syntax sugar

if (expectedWarningPattern == null || !generalConfig.expectedWarningsPattern!!.matches(it)) {
fs.readLines(path)
.filter { line ->
fixPluginConfig.ignoreLines?.let {
Copy link
Member

@orchestr7 orchestr7 Nov 6, 2021

Choose a reason for hiding this comment

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

what will happen here if ignoreLines == null? Sorry, if I am not completely understand this logic
Also I suppose that fixPluginConfig.ignoreLines is a not nullable constant due to your logic and you can move it to some val with !! OUTside of this loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have two variables: ignoreLines and ignoreLinesPatterns. We deserialize ignoreLines from toml config so it is nullable. Than we use ignoreLinesPatterns is a mutable list of Regex and it is not nullable.
In fix plugin there are three cases: ignoreLines is empty, ignoreLines is null or ignoreLines is a list of regular expressions. Here I check if ignoreLines is null


fs.write(fs.createFile(pathCopy)) {
fs.readLines(path).forEach {
if (expectedWarningPattern == null || !generalConfig.expectedWarningsPattern!!.matches(it)) {
Copy link
Member

Choose a reason for hiding this comment

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

warningsPattern will be now included into the ignoreLinesPatterns?

Copy link
Member Author

Choose a reason for hiding this comment

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

User should explicitly put warningPattern into ignoreLines in toml config.

).also { it.configLocation = this.configLocation }
other.ignoreLines?.let {
this.ignoreLines?.let { other.ignoreLines.union(this.ignoreLines) } ?: other.ignoreLines
}?.toMutableList() ?: this.ignoreLines
Copy link
Member

Choose a reason for hiding this comment

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

why do you need to convert it to mutableList? I thought that you created this field as a mutableList from a very beginning.

Copy link
Member Author

@sanyavertolet sanyavertolet Nov 15, 2021

Choose a reason for hiding this comment

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

The point is that we use .union(), which returns Set.

}

// due to probable bug in ktoml, ignoreLines = [] and no ignoreLines is ktoml are parsed to be mutableListOf("null")
Copy link
Member

Choose a reason for hiding this comment

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

it.configLocation = this.configLocation
}
companion object {
internal val defaultIgnoreLines: MutableList<Regex> = mutableListOf()
Copy link
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Member

@orchestr7 orchestr7 left a comment

Choose a reason for hiding this comment

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

please see comments above

sanyavertolet and others added 6 commits November 15, 2021 11:49
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
@orchestr7
Copy link
Member

ok, let's test it

sanyavertolet and others added 8 commits November 23, 2021 11:25
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.

(#133)
###What's done:
 * TESTING
(#133)
###What's done:
 * TESTING
(#133)
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.
###What's done:
* Added ignoreLines option for Warn plugin.
* Added tests for ignoreLines and Warn plugin.
* Added ignoreLines option for Fix plugin.
* Added tests for ignoreLines and Fix plugin.
* Implemented copying a file in Warn plugin in order to filter out lines that match any regex from ignoreLines.
@sanyavertolet sanyavertolet merged commit 530f7e8 into main Nov 24, 2021
@sanyavertolet sanyavertolet deleted the feature/ignoreLines branch November 24, 2021 11:14
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

Successfully merging this pull request may close these issues.

Support ignoreLines for all plugins: warn, fix, fix and warn
2 participants