Skip to content
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
47 changes: 47 additions & 0 deletions .githooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh
readonly INVALID_OUTPUT_FILE_ERROR_CODE=-1
fn_create_output_file() {
TYPE=$(echo "$1" | tr '[:upper:]' '[:lower:]')
BASE_DIR="./build/reports/detekt"
if [ "$TYPE" = "library" ]; then
echo "$BASE_DIR/detekt-library-$(date +%s).log"
elif [ "$TYPE" = "plugin" ]; then
echo "$BASE_DIR/detekt-plugin-$(date +%s).log"
else
echo "Invalid TYPE. Please provide either 'library' or 'plugin'"
exit $INVALID_OUTPUT_FILE_ERROR_CODE
fi
}

fn_run_detekt() {
TYPE=$(echo "$1" | tr '[:upper:]' '[:lower:]')
echo "Running $TYPE detekt check..."
GRADLE_TASK="detekt"
if [ "$TYPE" = "library" ]; then
GRADLE_TASK="detektMetadataCommonMain"
fi
OUTPUT_FILE=$(fn_create_output_file "$TYPE")

./gradlew "$GRADLE_TASK" > "$OUTPUT_FILE"
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
cat "$OUTPUT_FILE"
rm "$OUTPUT_FILE"
echo "********************************************"
echo " Detekt failed "
echo " Please fix the above issues before pushing "
echo "********************************************"
exit $EXIT_CODE
fi
rm "$OUTPUT_FILE"
}


fn_main() {
fn_run_detekt "library"
fn_run_detekt "plugin"

exit 0
}

fn_main
14 changes: 14 additions & 0 deletions .githooks/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
fn_main() {
echo "Running pre-push hook"
echo "Running tests..."
./gradlew cleanAllTests allTests
if [ $? -ne 0 ]; then
echo "Tests failed. Aborting push."
exit 1
fi
echo "Tests passed. Pushing..."
exit 0
}

fn_main
7 changes: 6 additions & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ jobs:
job-id: ${{ matrix.os }}
arguments: releaseLinux

- name: Running Detekt
- name: Running Detekt on svg-to-compose
shell: bash
run: |
./gradlew detektMetadataCommonMain

- name: Running Detekt on svg-to-compose-gradle-plugin
shell: bash
run: |
./gradlew detekt

- name: Verify unit tests
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion app.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=2.1.0
VERSION=2.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ private enum class StrokeDashDrawDirection(
}

fun StrokeDashArray.createDashedPathForRect(
x: Int,
y: Int,
x: Float,
y: Float,
width: Int,
height: Int,
strokeWidth: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class SvgRectNode(
val baseDimension = root.viewportHeight
height.toIntOrNull(baseDimension) ?: error("Invalid height '$height'")
}
val x: Int? by attribute<SvgLength?, Int?> { x ->
val x: Float? by attribute<SvgLength?, Float?> { x ->
val root = rootParent as SvgRootNode
val baseDimension = root.viewportWidth
x?.toIntOrNull(baseDimension)
x?.toFloatOrNull(baseDimension)
}
val y: Int? by attribute<SvgLength?, Int?> { y ->
val y: Float? by attribute<SvgLength?, Float?> { y ->
val root = rootParent as SvgRootNode
val baseDimension = root.viewportHeight
y?.toIntOrNull(baseDimension)
y?.toFloatOrNull(baseDimension)
}
val rx: Double? by attribute()
val ry: Double? by attribute()
Expand Down Expand Up @@ -68,8 +68,8 @@ fun SvgRectNode.asNode(
private fun SvgRectNode.createPath(isMinified: Boolean): ImageVectorNode.NodeWrapper {
val xCornerSize = rx ?: ry ?: 0.0
val yCornerSize = ry ?: rx ?: 0.0
val x = x ?: 0
val y = y ?: 0
val x = x ?: 0f
val y = y ?: 0f
val strokeDashArray = strokeDashArray

return ImageVectorNode.NodeWrapper(
Expand All @@ -89,8 +89,8 @@ private fun SvgRectNode.createPath(isMinified: Boolean): ImageVectorNode.NodeWra

private fun SvgRectNode.createDashedRect(
strokeDashArray: StrokeDashArray,
x: Int,
y: Int,
x: Float,
y: Float,
isMinified: Boolean,
): List<PathNodes> {
warn(
Expand All @@ -108,8 +108,8 @@ private fun SvgRectNode.createDashedRect(
}

private fun SvgRectNode.createRegularRect(
x: Int,
y: Int,
x: Float,
y: Float,
isMinified: Boolean,
) = listOf(
pathNode(command = PathCommand.MoveTo) {
Expand All @@ -135,8 +135,8 @@ private fun SvgRectNode.createRegularRect(
)

private fun SvgRectNode.createRoundedCornerRect(
x: Int,
y: Int,
x: Float,
y: Float,
xCornerSize: Double,
yCornerSize: Double,
isMinified: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class SvgRectNodeTests : BaseSvgTest() {
val attributes = mutableMapOf("x" to "10", "y" to "20", "width" to "30", "height" to "40")
val rect = SvgRectNode(root, attributes)

assertEquals(expected = 10, actual = rect.x)
assertEquals(expected = 20, actual = rect.y)
assertEquals(expected = 10f, actual = rect.x)
assertEquals(expected = 20f, actual = rect.y)
assertEquals(expected = 30, actual = rect.width)
assertEquals(expected = 40, actual = rect.height)
}
Expand Down
Loading