-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into features/#182-inject-py-regexp-into-wildcard
- Loading branch information
Showing
9 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...main/kotlin/com/jetbrains/snakecharm/inspections/SmkMisuseUsageIOFlagMethodsInspection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.jetbrains.snakecharm.inspections | ||
|
||
import com.intellij.codeInspection.LocalInspectionToolSession | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import com.jetbrains.python.psi.PyCallExpression | ||
import com.jetbrains.python.psi.PyReferenceExpression | ||
import com.jetbrains.snakecharm.SnakemakeBundle | ||
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.IO_FLAG_2_SUPPORTED_SECTION | ||
import com.jetbrains.snakecharm.lang.psi.SmkFile | ||
import com.jetbrains.snakecharm.lang.psi.SmkRuleOrCheckpointArgsSection | ||
|
||
class SmkMisuseUsageIOFlagMethodsInspection : SnakemakeInspection() { | ||
override fun buildVisitor( | ||
holder: ProblemsHolder, | ||
isOnTheFly: Boolean, | ||
session: LocalInspectionToolSession | ||
) = object : SnakemakeInspectionVisitor(holder, session) { | ||
|
||
private fun getSupportedSectionIfMisuse( | ||
flagCallName: String, | ||
section: SmkRuleOrCheckpointArgsSection | ||
): List<String> { | ||
val supportedSections = IO_FLAG_2_SUPPORTED_SECTION[flagCallName] | ||
if (supportedSections != null) { | ||
if (section.sectionKeyword !in supportedSections) { | ||
return supportedSections | ||
} | ||
} | ||
// check N/A here | ||
return emptyList() | ||
} | ||
|
||
override fun visitSmkRuleOrCheckpointArgsSection(st: SmkRuleOrCheckpointArgsSection) { | ||
|
||
if (st.containingFile !is SmkFile) { | ||
return | ||
} | ||
|
||
val argList = st.argumentList ?: return | ||
argList.arguments | ||
.filterIsInstance<PyCallExpression>() | ||
.forEach { callExpr -> | ||
val callee = callExpr.callee | ||
if (callee is PyReferenceExpression) { | ||
// We don't need qualified refs here (e.g. like `foo.boo.ancient`) | ||
val callName = when (callee.qualifier) { | ||
null -> callee.referencedName | ||
else -> null | ||
} | ||
|
||
if (callName != null) { | ||
val supportedSectionIfMisuse = getSupportedSectionIfMisuse(callName, st) | ||
if (supportedSectionIfMisuse.isNotEmpty()) { | ||
holder.registerProblem( | ||
callExpr, | ||
SnakemakeBundle.message( | ||
"INSP.NAME.misuse.usage.io.flag.methods.warning.message", | ||
callName, | ||
st.sectionKeyword!!, | ||
supportedSectionIfMisuse.sorted().joinToString { "'$it'"} | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/resources/inspectionDescriptions/SmkMisuseUsageIOFlagMethodsInspection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
Input/Output flags (e.g. ancient(..), protected(..), directory(..), etc) not supported by all rule sections. This inspection warns about such flags misuse. | ||
</body> | ||
</html> |
88 changes: 88 additions & 0 deletions
88
...sources/features/highlighting/inspections/misuse_usage_io_flag_methods_inspection.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
Feature: Inspection for methods from snakemake library | ||
|
||
Scenario Outline: Incorrect using ancient/protected/directory methods | ||
Given a snakemake project | ||
Given I open a file "foo.smk" with text | ||
""" | ||
<rule_like> NAME: | ||
<section>: <method><arg_list> | ||
""" | ||
And SmkMisuseUsageIOFlagMethodsInspection inspection is enabled | ||
Then I expect inspection warning on <<method><arg_list>> in <<section>: <method><arg_list>> with message | ||
""" | ||
'<method>' isn't supported in '<section>' section, expected in sections: <expected>. | ||
""" | ||
When I check highlighting warnings | ||
Examples: | ||
| rule_like | section | method | arg_list | expected | | ||
| rule | input | directory | ('') | 'output' | | ||
| rule | input | pipe | ('') | 'output' | | ||
| rule | input | protected | ('') | 'benchmark', 'log', 'output' | | ||
| rule | log | temp | ('') | 'input', 'output' | | ||
| rule | input | dynamic | ('') | 'output' | | ||
| rule | input | touch | ('') | 'output' | | ||
| rule | input | repeat | ('') | 'benchmark' | | ||
| rule | input | report | ('') | 'output' | | ||
| rule | output | ancient | ('') | 'input' | | ||
| rule | output | unpack | ('') | 'input' | | ||
| checkpoint | input | directory | ('') | 'output' | | ||
| checkpoint | input | pipe | ('') | 'output' | | ||
| checkpoint | input | protected | ('') | 'benchmark', 'log', 'output' | | ||
| checkpoint | log | temp | ('') | 'input', 'output' | | ||
| checkpoint | input | dynamic | ('') | 'output' | | ||
| checkpoint | input | touch | ('') | 'output' | | ||
| checkpoint | input | repeat | ('') | 'benchmark' | | ||
| checkpoint | input | report | ('') | 'output' | | ||
| checkpoint | output | ancient | ('') | 'input' | | ||
| checkpoint | output | unpack | ('') | 'input' | | ||
|
||
Scenario Outline: Correct using ancient/protected/directory methods | ||
Given a snakemake project | ||
Given I open a file "foo.smk" with text | ||
""" | ||
<rule_like> NAME: | ||
<section>: <method> | ||
""" | ||
And SmkMisuseUsageIOFlagMethodsInspection inspection is enabled | ||
Then I expect no inspection warnings | ||
When I check highlighting warnings | ||
Examples: | ||
| rule_like | section | method | | ||
| rule | input | ancient('') | | ||
| rule | input | temp('') | | ||
| rule | input | unpack('') | | ||
| rule | output | directory('') | | ||
| rule | output | pipe('') | | ||
| rule | output | protected('') | | ||
| rule | output | dynamic('') | | ||
| rule | output | touch('') | | ||
| rule | output | report('') | | ||
| rule | benchmark | repeat('') | | ||
| rule | benchmark | protected('') | | ||
| checkpoint | input | ancient('') | | ||
| checkpoint | input | temp('') | | ||
| checkpoint | input | unpack('') | | ||
| checkpoint | output | directory('') | | ||
| checkpoint | output | pipe('') | | ||
| checkpoint | output | protected('') | | ||
| checkpoint | output | dynamic('') | | ||
| checkpoint | output | touch('') | | ||
| checkpoint | output | report('') | | ||
| checkpoint | benchmark | repeat('') | | ||
| checkpoint | benchmark | protected('') | | ||
|
||
|
||
Scenario Outline: Complex cases not be confused | ||
Given a snakemake project | ||
Given I open a file "foo.smk" with text | ||
""" | ||
<rule_like> NAME: | ||
<section>: <method> | ||
""" | ||
And SmkMisuseUsageIOFlagMethodsInspection inspection is enabled | ||
Then I expect no inspection warnings | ||
When I check highlighting warnings | ||
Examples: | ||
| rule_like | section | method | | ||
| rule | output | foo.ancient('') | | ||
| rule | output | ancient.foo('') | |