Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when indentSize isn't set to an Int. #1486

Merged
merged 4 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ An AssertJ style API for testing KtLint rules ([#1444](https://github.com/pinter
- Fix formatting of a property delegate with a dot-qualified-expression `indent` ([#1340](https://github.com/pinterest/ktlint/ssues/1340))
- Keep formatting of for-loop in sync with default IntelliJ formatter (`indent`) and a newline in the expression in a for-statement should not force to wrap it `wrapping` ([#1350](https://github.com/pinterest/ktlint/issues/1350))
- Fix indentation of property getter/setter when the property has an initializer on a separate line `indent` ([#1335](https://github.com/pinterest/ktlint/issues/1335))
- When `.editorconfig` setting `indentSize` is set to value `tab` then return the default tab width as value for `indentSize` ([#1485](https://github.com/pinterest/ktlint/issues/1485))



### Changed
- Update Kotlin development version to `1.7.0-RC` and Kotlin version to `1.6.21`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ public object DefaultEditorConfigProperties {
defaultValue = IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth,
propertyMapper = { property, _ ->
when {
property == null -> IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth
property.isUnset -> -1
property?.isUnset == true -> -1
property?.getValueAs<Int>() == null ->
IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth
else -> property.getValueAs()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ class UsesEditorConfigPropertiesTest {
assertThat(actual).isEqualTo(-1)
}

@Test
fun `Issue 1485 - Given that editor config property indent_size is set to value 'tab' then return tabWidth as value via the getEditorConfigValue of the node`() {
val testAstNode: ASTNode = DummyHolderElement("some-text")
testAstNode.putUserData(
KtLint.EDITOR_CONFIG_PROPERTIES_USER_DATA_KEY,
createPropertyWithValue(
DefaultEditorConfigProperties.indentSizeProperty,
"tab"
)
)
val actual = PropertyValueTester().testValue(testAstNode, DefaultEditorConfigProperties.indentSizeProperty)

assertThat(actual).isEqualTo(IndentConfig.DEFAULT_INDENT_CONFIG.tabWidth)
}

@Test
fun `Given that editor config property indent_size is not set then return the default tabWidth as value via the getEditorConfigValue of the node`() {
val testAstNode: ASTNode = DummyHolderElement("some-text")
Expand Down