From 121fb2f4ba60db3db671612f05cad2aa63165745 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 25 Nov 2026 23:49:25 +0000 Subject: [PATCH] Keep Swift range operators in the fingerprint. ..< and ... were dropped as punctuation, so a half-open range and a closed range scored 1.0. They now stay, as >= and != do. Proved by test_a_different_swift_range_lowers_the_score. The suite is 93 passed. Co-authored-by: Robert C. Martin --- README.md | 2 +- src/dryer/astnorm.py | 2 ++ tests/test_swift.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12de678..26e7901 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ DUPLICATE score=0.89 | Python | functions and methods | functions nested inside another function | | Swift | functions and methods with a body, computed properties, and file-level closures | initializers, subscripts, protocol requirements, and closures or functions nested inside another form | -A Swift computed property includes a SwiftUI `body`. A method on a struct, class, enum, or extension is a candidate, and so is a protocol method that has a default body. A protocol requirement does not. A closure written inside a function stays in that function. A closure bound with `let` or `var` at file scope is its own candidate, as a top-level arrow function is in TypeScript. Argument labels stay, because in Swift they are part of the call. `>=` and `!=` stay. Locals, field names, and literals, including `nil`, do not. An interpolated string keeps the interpolation. +A Swift computed property includes a SwiftUI `body`. A method on a struct, class, enum, or extension is a candidate, and so is a protocol method that has a default body. A protocol requirement does not. A closure written inside a function stays in that function. A closure bound with `let` or `var` at file scope is its own candidate, as a top-level arrow function is in TypeScript. Argument labels stay, because in Swift they are part of the call. `>=`, `!=`, `...`, and `..<` stay. Locals, field names, and literals, including `nil`, do not. An interpolated string keeps the interpolation. Clojure reader conditionals keep the `:clj` branch, as dry4clj does. Syntax-quote is kept as a `syntax-quote` form rather than expanded. diff --git a/src/dryer/astnorm.py b/src/dryer/astnorm.py index b5891c0..d7b863f 100644 --- a/src/dryer/astnorm.py +++ b/src/dryer/astnorm.py @@ -117,6 +117,8 @@ _OPERATORS = { ":=", "=>", "?", + "...", + "..<", } _CALLS = { diff --git a/tests/test_swift.py b/tests/test_swift.py index 8e97692..9dd633b 100644 --- a/tests/test_swift.py +++ b/tests/test_swift.py @@ -105,6 +105,19 @@ def test_a_different_swift_operator_lowers_the_score(tmp_path): ) < 1.0 +def test_a_different_swift_range_lowers_the_score(tmp_path): + assert _scored( + tmp_path, + "func alpha(xs: Int) -> Bool {\n return xs..<1\n}\n", + "func beta(items: Int) -> Bool {\n return items..<2\n}\n", + ) == 1.0 + assert _scored( + tmp_path, + "func alpha(xs: Int) -> Bool {\n return xs..<1\n}\n", + "func beta(items: Int) -> Bool {\n return items...1\n}\n", + ) < 1.0 + + def test_a_swift_argument_label_is_part_of_the_call(tmp_path): assert _scored( tmp_path,