Skip to content

Commit

Permalink
Fix crash when indentSize isn't set to an Int. (#1486)
Browse files Browse the repository at this point in the history
* Fix crash when indentSize isn't set to an Int.

* Check for both null as the type in the same line

* Add test + changelog

* Update changelog and test description

Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
  • Loading branch information
bhoflack and paul-dingemans authored Jun 3, 2022
1 parent 7aa7b6e commit 650ce55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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-RC2` 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 @@ -49,6 +49,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

0 comments on commit 650ce55

Please sign in to comment.