Skip to content

Feature: logger - #21

Merged
3lvis merged 2 commits into
masterfrom
feature/logger
Oct 8, 2015
Merged

3lvis merged 2 commits into
masterfrom
feature/logger

Conversation

@3lvis

@3lvis 3lvis commented Oct 8, 2015

Copy link
Copy Markdown
Owner

Logs networking errors

========== Networking Error ==========

Error 3840: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

Path: http://httpbin.org/posdddddt

Response: <NSHTTPURLResponse: 0x7f8e19f28920> { URL: http://httpbin.org/posdddddt } { status code: 404, headers {
    "Access-Control-Allow-Credentials" = true;
    "Access-Control-Allow-Origin" = "*";
    Connection = "keep-alive";
    "Content-Length" = 233;
    "Content-Type" = "text/html";
    Date = "Thu, 08 Oct 2015 12:52:58 GMT";
    Server = nginx;
} }

Params: {
    password = password;
    username = jameson;
}

Data: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>


Request: <NSMutableURLRequest: 0x7f8e19f0f8d0> { URL: http://httpbin.org/posdddddt }

================= ~ ==================

3lvis added a commit that referenced this pull request Oct 8, 2015
@3lvis
3lvis merged commit a40e8bc into master Oct 8, 2015
@3lvis
3lvis deleted the feature/logger branch October 8, 2015 12:59
3lvis added a commit that referenced this pull request Sep 16, 2026
0.15.0 answers all three issues this adoption raised. The 149 violations that
had no fix in 0.14.0 are gone: multiline_call_arguments and multiline_conditions
correct now that width is the formatter's alone, and opening_brace takes
ignore_multiline_function_signatures, which is the shape a wrapped signature
could never satisfy before (#19, #20). no_single_use_void_functions no longer
flags public clearCache, whose callers are in other people's projects (#21), so
the rule comes back into the set.

The configuration loses what 0.15.0 deleted: requires_single_line, the eight
count rules, nesting and cyclomatic_complexity. Naming a rule that no longer
exists is naming nothing.

Linting needs no Xcode, so its job moves to ubuntu-latest in swift:6.3.2-noble,
the shape tienda-ios already runs. The toolchain image is what makes Linux work
at all: oida's SourceKit rules and its swift-format handoff both resolve through
it. The macOS runner stays for build, test and the warnings gate.

195 violations down to 48, suite 180/180 green.
3lvis added a commit that referenced this pull request Sep 16, 2026
* Lint with oida, and take the reformat its --fix produces

oida (github.com/kolonialno/oida-swift) is our own linter: fifteen rules decide
the shape of every argument list, and the ones this repository opts into are in
.oida.yml. bin/lint fetches the pinned release, checksums it and runs it, then
hands the files to swift-format, which owns every indent.

There is no baseline. A standing violation would be silent under one, and this
repository adopted oida to find what it says rather than to record that it once
said something — so the tree goes to zero and stays there.

This commit is the mechanical half: what --fix produces, 438 violations down to
278. The suite is 180/180 green against go-httpbin, so the reformat changed
shape and nothing else. The remainder is hand work, and the gate goes on once
it is at zero.

* One tool formats, and it is the one that lints

bin/lint already hands the corrected files to swift-format, so the standalone
swift-format CI job and the swift-format pre-commit hook were running it a
second time. The hook now calls bin/lint --staged and CI calls bin/lint --check.

.swift-format stays: swift-format still owns every indent, it is just reached
through oida now, which is what keeps the tree and Xcode's Format File agreeing.

* Every XCTFail says what was expected, and the mechanical violations go

XCTFail() with no message tells whoever reads the failure nothing the test name
did not already say, so all seventeen now name the expectation: "a GET to a path
that does not exist must fail", "the image should come back from the file cache".

The rest is mechanical. Trailing commas dropped from collection literals. Two
force-unwrapped `"...".data(using: .utf8)!` become `Data("...".utf8)`, which
cannot fail and so needs no unwrap. `arc4random()` becomes
`UInt32.random(in: .min ... .max)`. Two test classes lose the underscore their
filename put in their name.

438 violations down to 238, suite 180/180 green.

* The MARK banners go, and a declaration stands off what follows it

Eleven `// MARK: -` banners named what the declarations under them already
named, so they are gone. A doc comment that sat above two ordinary comments
moves down onto the declaration it documents, where it is read as one.

The rest is spacing: a stored property now stands off the function under it.

238 violations down to 220, suite 180/180 green.

* A force unwrap is either an invariant worth stating or a nil worth handling

Seventeen force unwraps and three force casts, each taken on its own terms.

Handled, because the value can genuinely be absent: a macOS image with no TIFF
representation now returns nil, which the signature already allowed; a folder
name that will not parse as a URL throws or returns nil rather than trapping;
five `"...".data(using: .utf8)!` become `Data("...".utf8)`, which cannot fail.

Stated, because the absence would be our fault rather than a caller's: a bundled
image that is missing is a packaging fault, so Image.find says so and traps with
the name it looked for. Two justified with a scoped disable: the URL reaching the
HTTPURLResponse convenience initializer has already been parsed by composedURL,
and the three generic casts are each guarded by the type test above them.

In tests a nil is a failed test, so those take XCTUnwrap.

220 violations down to 206, suite 180/180 green.

* A templated fake path answers what it captured, and matching reads as three steps

FakeRequest.find carried an exact lookup and the templated-path walk in one body,
at complexity 14. It is now three: find tries the exact path then hands over,
templated walks the candidates, and captures answers what one placeholder path
took from a lookup — or nil where the two describe different paths. The body
substitution both halves needed is String.replacing(_:).

A `for` whose body was one `if` takes a `where` clause.

no_single_use_void_functions is left out of the rule set, with the reason in
.oida.yml: nine of the ten it finds here are a library's own seams and one is
documented public API, whose callers are in other people's projects
(kolonialno/oida-swift#21). Inlining the tenth does not even compile — it is the
hop that makes an actor-isolated write legal from a nonisolated closure.

206 violations down to 195, suite 180/180 green.

* oida 0.15.0, and linting moves to Linux

0.15.0 answers all three issues this adoption raised. The 149 violations that
had no fix in 0.14.0 are gone: multiline_call_arguments and multiline_conditions
correct now that width is the formatter's alone, and opening_brace takes
ignore_multiline_function_signatures, which is the shape a wrapped signature
could never satisfy before (#19, #20). no_single_use_void_functions no longer
flags public clearCache, whose callers are in other people's projects (#21), so
the rule comes back into the set.

The configuration loses what 0.15.0 deleted: requires_single_line, the eight
count rules, nesting and cyclomatic_complexity. Naming a rule that no longer
exists is naming nothing.

Linting needs no Xcode, so its job moves to ubuntu-latest in swift:6.3.2-noble,
the shape tienda-ios already runs. The toolchain image is what makes Linux work
at all: oida's SourceKit rules and its swift-format handoff both resolve through
it. The macOS runner stays for build, test and the warnings gate.

195 violations down to 48, suite 180/180 green.

* The documents say what is

Thirty-nine places where the prose said what something was rather than what it
is. A few read better for it: "If your file is not located in the main bundle you
have to specify using the bundle parameters" is now "A file outside the main
bundle takes the bundle parameter"; "makes no assumption about the error body's
shape" is "treats the error body as opaque"; the `.ephemeral` paragraph, carried
in from Apple's own documentation, says what it keeps in RAM instead of what it
declines to write.

Two uses of "simply" go, which was the whole of document_avoids_retired_words.

Every relative link still resolves.

* The formatter and the linter agree about a trailing comma

swift-format adds a trailing comma to a multi-line collection literal by default
and oida's trailing_comma forbids one, so bin/lint --fix wrote fifteen commas
that bin/lint --check then rejected — stably, since a second --fix changed
nothing. tienda-ios has always set this key, which is why it reports none.

multiElementCollectionTrailingCommas: false is the half that makes both
directions agree; mandatory_comma: true alone leaves seven, because the
formatter adds the comma in most multi-line literals rather than all of them.

Filed as kolonialno/oida-swift#34. --fix is idempotent now.

* oida 0.16.0, and the configuration loses what went with it

0.16.0 takes 209 rules to 89, and 25 of the names this configuration carried are
among them — the SwiftLint opt-in menu, the whitespace rules swift-format
already reports, and the preferences that pick one of two correct spellings.
trailing_comma goes with them, which closes #34: layout is the formatter's, so
multiElementCollectionTrailingCommas decides alone and oida holds no opinion to
disagree with.

file_header and force_unwrapping left too. The scoped disable on the
HTTPURLResponse initializer goes with force_unwrapping, and its comment stays:
why that unwrap is safe is worth reading whether or not a rule asks.

--fix is idempotent, suite 180/180 green, and the tree is at 9 —
no_single_use_void_functions, all of it.

* The log file is written where the log line is recorded

appendToLogFile had one caller, in the same file, as its last statement — the
jump bought the reader nothing and its guards read the same inside record.

The other two same-file cases stay. removeContinuation is an actor-isolation hop
whose caller is a nonisolated termination handler, and inlining it fails to
compile. logCompletion is fifty-five lines with three early exits, called from a
function that carries on afterwards; folding it turns those exits into nested
conditionals and makes complete do three jobs.

Suite 180/180 green.

* The eight that stay say why, and the tree is at zero

Each carries a scoped disable and the reason above it. Six are seams: the cancel
path reached from the verbs, and the cache store's set, write, clear and sweep,
each reached from Networking and three of them driven directly by tests. Folding
any of them pushes a store's internals into its consumer.

Two are same-file and still stay. logCompletion is fifty lines of logging behind
a name, with three early exits the caller must never inherit — returning from
complete would skip emit and the result. removeContinuation is the hop that makes
an actor-isolated write legal from a nonisolated termination handler, and
inlining it fails to compile.

clear() takes a block disable rather than :next, so its doc comment stays on the
declaration it documents.

bin/lint --check is clean, --fix is idempotent, suite 180/180 green. The gate is
hard from here: any new violation fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant