Skip to content

Commit bc5f145

Browse files
authored
fix empty glint config (#227)
* allow empty package * allow empty package for glint config * fix * fix * fix
1 parent 630c894 commit bc5f145

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/main/kotlin/com/emberjs/gts/GlintExternalAnnotator.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.intellij.lang.annotation.AnnotationHolder
1616
import com.intellij.lang.javascript.integration.JSAnnotationError
1717
import com.intellij.lang.javascript.linter.*
1818
import com.intellij.lang.javascript.psi.JSFile
19+
import com.intellij.openapi.components.Service
1920
import com.intellij.openapi.components.State
2021
import com.intellij.openapi.components.Storage
2122
import com.intellij.openapi.options.OptionsBundle
@@ -66,8 +67,7 @@ data class GlintState(
6667
private val myPackageRef: NodePackageRef = NodePackageRef.create(myTemplateLintPackage)
6768

6869
override fun withLinterPackage(packageRef: NodePackageRef): GlintState {
69-
val constantPackage = packageRef.constantPackage
70-
?: throw AssertionError(this.javaClass.simpleName + " does not support non-constant package refs")
70+
val constantPackage = packageRef.constantPackage ?: return DEFAULT
7171

7272
return copy(myTemplateLintPackage = constantPackage)
7373
}
@@ -93,6 +93,7 @@ data class GlintState(
9393
}
9494

9595

96+
@Service(Service.Level.PROJECT)
9697
@State(name = "GlintConfiguration", storages = [Storage("emberLinters/glint.xml")])
9798
class GlintConfiguration(project: Project) : JSLinterConfiguration<GlintState>(project) {
9899
private val myPackage: JSLinterPackage = JSLinterPackage(project, "@glint/core")
@@ -103,7 +104,10 @@ class GlintConfiguration(project: Project) : JSLinterConfiguration<GlintState>(p
103104
override fun loadPrivateSettings(state: GlintState): GlintState {
104105
this.myPackage.readOrDetect()
105106
val constantPackage = myPackage.getPackage().constantPackage
106-
?: throw AssertionError("glint does not support non-constant node package refs")
107+
108+
if (constantPackage == null) {
109+
return defaultState
110+
}
107111

108112
return state.copy(
109113
myInterpreterRef = this.myPackage.interpreter,
@@ -245,4 +249,4 @@ class GlintExternalAnnotator : JSLinterExternalAnnotator<GlintState>(true) {
245249
override fun getInspectionClass(): Class<out JSLinterInspection> {
246250
return GlintInspection::class.java
247251
}
248-
}
252+
}

src/main/kotlin/com/emberjs/hbs/linter/ember-template-lint/TemplateLintConfiguration.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ class TemplateLintConfiguration(project: Project) : JSLinterConfiguration<Templa
1616
override fun loadPrivateSettings(state: TemplateLintState): TemplateLintState {
1717
this.myPackage.readOrDetect()
1818

19+
val constantPackage = this.myPackage.getPackage().constantPackage
20+
21+
if (constantPackage == null) {
22+
return defaultState
23+
}
24+
1925
return state.copy(
2026
myInterpreterRef = this.myPackage.interpreter,
21-
myTemplateLintPackage = this.myPackage.getPackage().constantPackage
27+
myTemplateLintPackage = constantPackage
2228
)
2329
}
2430

src/main/kotlin/com/emberjs/hbs/linter/ember-template-lint/TemplateLintState.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import com.intellij.lang.javascript.linter.JSNpmLinterState
66

77
data class TemplateLintState(
88
private val myInterpreterRef: NodeJsInterpreterRef,
9-
private val myTemplateLintPackage: NodePackage?,
9+
private val myTemplateLintPackage: NodePackage,
1010
val isRunOnSave: Boolean,
1111
) : JSNpmLinterState<TemplateLintState> {
1212

13-
private val myPackageRef: NodePackageRef? = myTemplateLintPackage?.let { NodePackageRef.create(it) }
13+
private val myPackageRef: NodePackageRef = myTemplateLintPackage.let { NodePackageRef.create(it) }
1414

1515
override fun withLinterPackage(packageRef: NodePackageRef): TemplateLintState {
16-
val constantPackage = packageRef.constantPackage
17-
?: throw AssertionError(this.javaClass.simpleName + " does not support non-constant package refs")
16+
val constantPackage = packageRef.constantPackage ?: return DEFAULT
1817

1918
return copy(myTemplateLintPackage = constantPackage)
2019
}
@@ -24,12 +23,12 @@ data class TemplateLintState(
2423
}
2524

2625
override fun getNodePackageRef(): NodePackageRef {
27-
return this.myPackageRef!!
26+
return this.myPackageRef
2827
}
2928

3029
val templateLintPackage: NodePackage
3130
get() {
32-
return this.myTemplateLintPackage!!
31+
return this.myTemplateLintPackage
3332
}
3433

3534
companion object {

src/main/resources/META-INF/plugin.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@
182182
<annotator language="Handlebars" implementationClass="com.emberjs.gts.HbLintAnnotator"/>
183183
<annotator language="HTML" implementationClass="com.emberjs.gts.HbLintAnnotator"/>
184184
<projectService serviceImplementation="TemplateLintConfiguration"/>
185-
<projectService serviceImplementation="com.emberjs.gts.GlintConfiguration"/>
186185
<projectService serviceImplementation="TemplateLintConfigFileChangeTracker"/>
187186
<projectService serviceImplementation="TemplateLintUnsavedConfigFileManager"/>
188187
<projectService serviceImplementation="com.emberjs.glint.GlintTypeScriptService"/>

0 commit comments

Comments
 (0)