Skip to content

Commit

Permalink
Merge pull request #29 from olivernybroe/fix-blade
Browse files Browse the repository at this point in the history
Fix foreach inspection running on blade files
  • Loading branch information
olivernybroe authored Nov 9, 2020
2 parents 7344147 + 8c38d03 commit 268deb0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# collections-intellij Changelog

## [Unreleased]
### Fixed
- Ignore foreach to collection in blade files

## [0.0.1-EAP.7]
### Added
- Added closure to arrow function inside collection

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

pluginGroup = dev.nybroe.collector
pluginName_ = Collector
pluginVersion = 0.0.1-EAP.7
pluginVersion = 0.0.1-EAP.8
pluginSinceBuild = 193
pluginUntilBuild =

platformType = IU
platformVersion = 2020.2.3
platformDownloadSources = true
# Get latest version from https://plugins.jetbrains.com/plugin/6610-php/versions
platformPlugins = com.jetbrains.php:202.7660.42
platformPlugins = com.jetbrains.php:202.7660.42, com.jetbrains.php.blade:202.7319.5

# Opt-out flag for bundling Kotlin standard library.
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.nybroe.collector.blade

import com.intellij.codeInspection.InspectionSuppressor
import com.intellij.codeInspection.SuppressQuickFix
import com.intellij.psi.PsiElement
import com.jetbrains.php.blade.psi.BladePsiDirectiveParameter
import com.jetbrains.php.blade.psi.BladePsiLanguageInjectionHost
import com.jetbrains.php.blade.psi.BladePsiPhpBlock
import com.jetbrains.php.blade.psi.BladeTokenTypes
import dev.nybroe.collector.inspections.ForeachToCollectionInspection

class BladePhpInspectionSuppressor : InspectionSuppressor {
companion object {
private val SUPPRESSED_PHP_INSPECTIONS = listOf(ForeachToCollectionInspection().id)
}

override fun isSuppressedFor(element: PsiElement, toolId: String): Boolean {
if (element !is BladePsiLanguageInjectionHost) {
return false
}

if (element is BladePsiPhpBlock) {
return false
}

if (element is BladePsiDirectiveParameter && element.directiveElementType === BladeTokenTypes.PHP_DIRECTIVE) {
return false
}

return SUPPRESSED_PHP_INSPECTIONS.contains(toolId)
}

override fun getSuppressActions(element: PsiElement?, toolId: String): Array<SuppressQuickFix> {
return SuppressQuickFix.EMPTY_ARRAY
}
}
8 changes: 8 additions & 0 deletions src/main/resources/META-INF/blade.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<lang.inspectionSuppressor
language="Blade"
implementationClass="dev.nybroe.collector.blade.BladePhpInspectionSuppressor"
/>
</extensions>
</idea-plugin>
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<id>dev.nybroe.collector</id>
<name>Collector</name>
<vendor email="[email protected]" url="https://nybroe.dev">Oliver Nybroe</vendor>

<!-- Product and plugin compatibility requirements -->
<!-- https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html -->
<depends>com.intellij.modules.platform</depends>
<depends>com.jetbrains.php</depends>
<depends optional="true" config-file="blade.xml">com.jetbrains.php.blade</depends>

<extensions defaultExtensionNs="com.intellij">
<localInspection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ internal class ForeachToCollectionInspectionTest : InspectionTest() {
fun testForeachStringInterpolationWithPropertyAccess() {
doTest("foreach-string-interpolation-with-property-access")
}

fun testForeachBladeDirectives() {
doNotMatchTest("foreach-blade-directive.blade")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@foreach ($items as $item)
<li>{{ $item }}</li>
@endforeach

0 comments on commit 268deb0

Please sign in to comment.