Skip to content

Use lint***Filter instead of ***LintKeys for more reliable tests#5985

Merged
eed3si9n merged 1 commit intosbt:developfrom
xirc:use-lint-xxx-filter-in-test
Oct 18, 2020
Merged

Use lint***Filter instead of ***LintKeys for more reliable tests#5985
eed3si9n merged 1 commit intosbt:developfrom
xirc:use-lint-xxx-filter-in-test

Conversation

@xirc
Copy link
Copy Markdown
Contributor

@xirc xirc commented Oct 18, 2020

Use lint***Filter instead of ***LintKeys for more reliable tests.
I have found this improvement when I attempted to solve the issue #5849.

Problem

lintUnusedTask passes the result of lintExcludeFilter as the argument to lintUnused.

def lintUnusedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
val _ = Def.spaceDelimited().parsed // not used yet
val state = Keys.state.value
val log = streams.value.log
val includeKeys = (lintIncludeFilter in Global).value
val excludeKeys = (lintExcludeFilter in Global).value
val result = lintUnused(state, includeKeys, excludeKeys)
if (result.isEmpty) log.success("ok")
else lintResultLines(result) foreach { log.warn(_) }
}

lintExcludeFilter excludes watch related settings which has the prefix watch.

lintExcludeFilter := {
val excludes = excludeLintKeys.value.map(_.scopedKey.key.label)
keyName => excludes(keyName) || keyName.startsWith("watch")
},

But, in the test, excludeLintKeys are passed to lintUnused.
excludeLintKeys are used in lintExcludeFilter, and it doesn't exclude watch related settings.
Thus, excluding watch related settings from lint keys are not well tested.

val includeKeys = (includeLintKeys in Global).value map { _.scopedKey.key.label }
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
val result = sbt.internal.LintUnused.lintUnused(state, includeKeys, excludeKeys)

I think I can say same thing also about lintIncludeFilter and includeLintKeys.

Solution

  • Use lintExcludeFilter instead of excludeLintKeys in the test
  • Use lintIncludeFilter instead of includeLintKeys in the test

Below functions pass lintIncludeFilter and lintExcludeFilter to lintUnusedinstead of includeLintKeys and excludeLintKeys respectively.
- sbt.internal.LintUnused#lintUnusedTask
- sbt.internal.LintUnused#lintUnusedFunc
Therefore, in the test, we had better to use lint***Filter instead of ***LintKeys.
Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks @xirc!

@eed3si9n eed3si9n merged commit 2f7cc6e into sbt:develop Oct 18, 2020
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.

2 participants