When swift-format is run with an offset range starting at 1 or greater, the formatter applies general formatting but does not apply any rule-based formatting.
Example
.swift-format:
{
"rules": {
"NoParensAroundConditions": true,
"DoNotUseSemicolons": true
}
}
input:
/// Some String....
if (a = 0) { NSLog("print: \(a)");}
Environment variable for convenience:
export CODE="/// Some String....\n if (a = 0) { NSLog(\"print: \\(a)\");}"
And expected result:
/// Some String....
if a = 0 { NSLog("print: \(a)") }
These commands produce the expected result:
echo $CODE | swift-format format - --configuration .swift-format
echo $CODE | swift-format format - --configuration .swift-format --offsets 0:999
But the following commands do not:
echo $CODE | swift-format format - --configuration .swift-format --offsets 1:999
echo $CODE | swift-format format - --configuration .swift-format --offsets 0:1 --offsets 1:999
Actual output:
/// Some String....
if (a = 0) { NSLog("print: \(a)"); }
Although the sliced input beginning at offset 1 still forms valid Swift syntax (// Some String....), rule-based formatting are not applied, while other non-rule formatting is applied correctly.
When
swift-formatis run with an offset range starting at 1 or greater, the formatter applies general formatting but does not apply any rule-based formatting.Example
.swift-format:{ "rules": { "NoParensAroundConditions": true, "DoNotUseSemicolons": true } }input:
Environment variable for convenience:
And expected result:
These commands produce the expected result:
But the following commands do not:
Actual output:
Although the sliced input beginning at offset 1 still forms valid Swift syntax (
// Some String....), rule-based formatting are not applied, while other non-rule formatting is applied correctly.