Skip to content

Commit

Permalink
Validate --app is set correctly for new projects
Browse files Browse the repository at this point in the history
1. If inferred from project name, make sure the name is valid application name the same as `mix new` does.
2. If `--app` is set explicitly, make sure it follows naming rules for `mix new`.
  • Loading branch information
KronicDeth committed Mar 26, 2023
1 parent d3733f1 commit 99743c8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/org/elixir_lang/new_project_wizard/Step.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ class Step(parent: NewProjectWizardLanguageStep) : AbstractNewProjectWizardStep(
textField()
.bindText(mixNewAppProperty)
.horizontalAlign(HorizontalAlign.FILL)
.validationOnApply {
if (mixNewApp.isNullOrBlank()) {
val name = this@Step.name

if (!name.matches(APPLICATION_NAME_REGEX)) {
error(
"Application name ust start with a lowercase ASCII letter, followed by " +
"lowercase ASCII letters, numbers, or underscores, got: \"${name}\"" +
". The application name is inferred from the path, if you'd like to" +
" explicitly name the application set --app"
)
} else {
null
}
} else {
if (!mixNewApp.matches(APPLICATION_NAME_REGEX)) {
error(
"Application name ust start with a lowercase ASCII letter, followed by " +
"lowercase ASCII letters, numbers, or underscores."
)
} else {
null
}
}
}
}.bottomGap(BottomGap.SMALL)
row("--module") {
textField()
Expand Down Expand Up @@ -191,6 +216,7 @@ private val ANY_SDK_FILTER: ((Sdk) -> Boolean) = { true }
private val ANY_SDK_TYPE_FILTER: ((SdkTypeId) -> Boolean) = { true }
private val ANY_SUGGESTED_SDK_FILTER: ((SdkListItem.SuggestedItem) -> Boolean) = { true }
private val NEW_SDK_CALLBACK_DEFAULT: ((Sdk) -> Unit) = {}
private val APPLICATION_NAME_REGEX: Regex = Regex("[a-z]([a-z0-9_])*")

fun Row.elixirSdkComboBox(context: WizardContext, sdkProperty: ObservableMutableProperty<Sdk?>): Cell<JdkComboBox> {
val sdksModel = ProjectSdksModel()
Expand Down

0 comments on commit 99743c8

Please sign in to comment.