-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from 2 commits
e8caeb6
f73884e
7206eb8
6166aaf
8d5ee0c
73afaa8
ca67047
dc3e033
6a1b838
b52e00f
7512208
a96da0b
1316dc0
e6f16ad
dca01fb
f3c84a5
cc3e3fa
81aa3cf
1c70ad9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.cqfn.save.IgnoreLinesTest.IgnoreLines | ||
|
||
class D { | ||
val x = 0 | ||
|
||
/** | ||
* @return | ||
*/ | ||
fun bar(): Bar { | ||
val qux = 42 | ||
return Bar(qux) | ||
} | ||
} | ||
|
||
/** | ||
* @param foo | ||
*/ | ||
fun readFile(foo: Foo) { | ||
var bar: Bar | ||
} | ||
// ;warn:0: [TEST] JUST_A_TEST |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package test.smoke.src.main.kotlin | ||
|
||
fun readFile(foo: Foo) { | ||
var bar: Bar | ||
} | ||
|
||
class D {val x = 0 | ||
fun bar(): Bar {val qux = 42; return Bar(qux)} | ||
} | ||
// ;warn:0: [TEST] JUST_A_TEST | ||
// IGNORE_ME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[general] | ||
tags = ["FixIgnoreLines"] | ||
description = "Test for ignoreLines option in Fix" | ||
suiteName = "Autofix: Smoke Tests" | ||
|
||
[fix] | ||
ignoreLines = ["// IGNORE_ME"] | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.cqfn.save.IgnoreLinesTest.IgnoreLinesIsEmpty | ||
|
||
class D { | ||
val x = 0 | ||
|
||
/** | ||
* @return | ||
*/ | ||
fun bar(): Bar { | ||
val qux = 42 | ||
return Bar(qux) | ||
} | ||
} | ||
|
||
/** | ||
* @param foo | ||
*/ | ||
fun readFile(foo: Foo) { | ||
var bar: Bar | ||
} | ||
// ;warn:0: [TEST] JUST_A_TEST | ||
// IGNORE_ME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package test.smoke.src.main.kotlin | ||
|
||
fun readFile(foo: Foo) { | ||
var bar: Bar | ||
} | ||
|
||
class D {val x = 0 | ||
fun bar(): Bar {val qux = 42; return Bar(qux)} | ||
} | ||
// ;warn:0: [TEST] JUST_A_TEST | ||
// IGNORE_ME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[general] | ||
tags = ["smoke"] | ||
description = "Smoke tests for diktat" | ||
suiteName = "Autofix: Smoke Tests" | ||
|
||
[fix] | ||
ignoreLines = [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.cqfn.save.IgnoreLinesTest.NoIgnoreLines | ||
|
||
class D { | ||
val x = 0 | ||
|
||
/** | ||
* @return | ||
*/ | ||
fun bar(): Bar { | ||
val qux = 42 | ||
return Bar(qux) | ||
} | ||
} | ||
|
||
/** | ||
* @param foo | ||
*/ | ||
fun readFile(foo: Foo) { | ||
var bar: Bar | ||
} | ||
// IGNORE_ME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package test.smoke.src.main.kotlin | ||
|
||
fun readFile(foo: Foo) { | ||
var bar: Bar | ||
} | ||
|
||
class D {val x = 0 | ||
fun bar(): Bar {val qux = 42; return Bar(qux)} | ||
} | ||
// ;warn:0: [TEST] JUST_A_TEST | ||
// IGNORE_ME |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[general] | ||
tags = ["smoke"] | ||
description = "Smoke tests for diktat" | ||
suiteName = "Autofix: Smoke Tests" | ||
|
||
[fix] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[general] | ||
tags = ["smoke"] | ||
description = "Smoke tests for diktat" | ||
suiteName = "Autofix: Smoke Tests" | ||
|
||
[fix] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.cqfn.diktat.test.resources.test.paragraph1.naming.enum_ | ||
|
||
// ;warn:3:1: [MISSING_KDOC_TOP_LEVEL] all public and internal top-level classes and functions should have Kdoc: EnumTestDetection (cannot be auto-corrected) | ||
// ;warn:30: [WRONG_DECLARATIONS_ORDER] declarations of constants and enum members should be sorted alphabetically: enum entries order is incorrect | ||
// ;warn:10:5: [ENUMS_SEPARATED] enum is incorrectly formatted: enums must end with semicolon | ||
enum class EnumTestDetection { | ||
// ;warn:$line+1:5: [ENUM_VALUE] enum values should be{{ in }}selected UPPER_CASE snake/PascalCase format: paSC_SAl_l | ||
paSC_SAl_l, | ||
|
||
// ;warn:5: [ENUM_VALUE] enum values{{ should }}be in selected{{ UPPER_CASE }}snake/PascalCase format: PascAsl_f | ||
PascAsl_f | ||
// ;warn:$line-2:5: [ENUMS_SEPARATED] enum is incorrectly formatted: last enum entry must end with a comma | ||
|
||
// ;warn:1:9: {{.*}}[PACKAGE_NAME_INCORRECT_PREFIX] package name should start from company's domain: org.cqfn.save{{.*}} | ||
} | ||
// ;warn:0:0: [YOU SHOULD NOT SEE THIS] this warning should not be shown |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[general] | ||
tags = ["WarnIgnoreLines"] | ||
description = "Test suite that checks if filtering by regex work." | ||
|
||
[warn] | ||
testNameRegex = "^E.*T.*D.*" | ||
ignoreLines = [".*// ;warn:0:0: \\[YOU SHOULD NOT SEE THIS\\] this warning should not be shown.*"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,11 @@ interface PluginConfig { | |
*/ | ||
val type: TestConfigSections | ||
|
||
/** | ||
* list of regexes to be ignored | ||
*/ | ||
var ignoreLinesPatterns: MutableList<Regex> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/** | ||
* Location of the toml config | ||
*/ | ||
|
@@ -69,6 +74,7 @@ data class GeneralConfig( | |
val runConfigPattern: Regex? = null, | ||
) : PluginConfig { | ||
override val type = TestConfigSections.GENERAL | ||
override var ignoreLinesPatterns: MutableList<Regex> = mutableListOf() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
@Transient | ||
override var configLocation: Path = "undefined_toml_location".toPath() | ||
|
@@ -88,8 +94,10 @@ data class GeneralConfig( | |
this.suiteName ?: other.suiteName, | ||
this.excludedTests ?: other.excludedTests, | ||
this.expectedWarningsPattern ?: other.expectedWarningsPattern, | ||
this.runConfigPattern ?: other.runConfigPattern, | ||
).also { it.configLocation = this.configLocation } | ||
this.runConfigPattern ?: other.runConfigPattern | ||
).also { | ||
it.configLocation = this.configLocation | ||
} | ||
} | ||
|
||
override fun validateAndSetDefaults(): GeneralConfig { | ||
|
@@ -113,7 +121,9 @@ data class GeneralConfig( | |
excludedTests ?: emptyList(), | ||
expectedWarningsPattern ?: defaultExpectedWarningPattern, | ||
runConfigPattern ?: defaultRunConfigPattern, | ||
).also { it.configLocation = this.configLocation } | ||
).also { | ||
it.configLocation = this.configLocation | ||
} | ||
} | ||
|
||
private fun errorMsgForRequireCheck(field: String) = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,14 +25,19 @@ data class FixAndWarnPluginConfig( | |
@Transient | ||
override var configLocation: Path = "undefined_toml_location".toPath() | ||
|
||
@Transient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point it that we deserialize |
||
override var ignoreLinesPatterns: MutableList<Regex> = defaultIgnoreLines | ||
|
||
override fun mergeWith(otherConfig: PluginConfig): PluginConfig { | ||
val other = otherConfig as FixAndWarnPluginConfig | ||
val mergedFixPluginConfig = fix.mergeWith(other.fix) | ||
val mergedWarnPluginConfig = warn.mergeWith(other.warn) | ||
return FixAndWarnPluginConfig( | ||
mergedFixPluginConfig as FixPluginConfig, | ||
mergedWarnPluginConfig as WarnPluginConfig | ||
).also { it.configLocation = this.configLocation } | ||
).also { | ||
it.configLocation = this.configLocation | ||
} | ||
} | ||
|
||
override fun validateAndSetDefaults(): PluginConfig { | ||
|
@@ -48,6 +53,11 @@ data class FixAndWarnPluginConfig( | |
return FixAndWarnPluginConfig( | ||
fix.validateAndSetDefaults(), | ||
warn.validateAndSetDefaults() | ||
).also { it.configLocation = this.configLocation } | ||
).also { | ||
it.configLocation = this.configLocation | ||
} | ||
} | ||
companion object { | ||
internal val defaultIgnoreLines: MutableList<Regex> = mutableListOf() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done