Repository navigation
Add modes to :split-keypairs-over-multiple-lines - #430
sirmspencer wants to merge 1 commit into
Conversation
c2287bc to
c87e7cc
Compare
|
Thank you for the PR. My first impression is that the |
|
I can think on the names. There might not be need to mixed and multiline to be two things. It still skips the rest of the maps. So if you are manually making intentional multi line maps like in 2 columns they stay. I can kind of see how Our team is going to use Using length is an option, but i think that fits more in the broader discussion on code width rules. We could certainly add a |
89ba26c to
4928bbd
Compare
|
I went ahead and took my own suggestion. The (now) single new mode should be much more clear on its intention. |
|
Could you give an example of how this change to the setting affects various different keypair-like structures? |
Did you see the included examples file? https://github.com/weavejester/cljfmt/pull/430/changes#diff-f1452dc72ce6d80c4028b230a90a323659918b0102235c4808075679951673e9R1 |
|
Ah, no, I didn't. Let's use the following keywords:
Next, use the existing project file structure. So put the tests in the core tests. Move the docs to the base |
|
I can use those names. I was assuming you would have questions on the file splits. The core_test file is 3500 lines of code, its getting hard to find tests in. |
afaecc0 to
8bf8c69
Compare
|
Splitting up core-test isn't unreasonable, but we should limit that to another PR. For some reason GraalVM is no longer downloading in the CI script, so let me see if the URL was moved or something. edit: I see you've already investigated the broken CI and pushed a fix. I've merged that PR. Thanks! |
8bf8c69 to
bf11750
Compare
| (case mode | ||
| (true :all) true | ||
| :only-multiline (multiline? zloc) | ||
| false))) |
There was a problem hiding this comment.
Since keypair-split-mode already converts true to :all, could we write this as:
(or (= mode :all)
(and (= mode :only-multiline) (multiline? zloc)))There was a problem hiding this comment.
yes, sorry, i usually catch these.
The option now takes a mode: :all for every map, :only-multiline for any map that spans more than one line. Splitting large maps is also no longer quadratic in the keypair count. :split-keypairs-over-multiple-lines? is deprecated and maps to :all. The command line flag gains a mode argument and keeps its old forms.
bf11750 to
f9de484
Compare
Why
:split-keypairs-over-multiple-lineswas a boolean: either every map got onekeypair per line, or none did. That is too coarse in practice. A map written
on a single line is usually deliberate and reads fine, whereas a map that
already spans several lines is where inconsistent keypair placement actually
costs readability. A project wanting the rule only for those cases had no way
to express it.
Approach
The option now takes a mode rather than a boolean:
:all:only-multiline:noneSplitting is now decided per map rather than per map entry, since
:only-multilineneeds a decision about the map as a whole before any of itskeys are considered.
Performance
split-map-keypairslooks more complex than theinsert-newline-leftitreplaces, because it absorbs work that used to live in the predicate beside it.
That predicate identified keys with
index-of, which counts by walking leftfrom every element it is called on, so the scan grew with the square of the
keypair count. Inserting the newline was never the expensive part.
Times to split a single map under
:all, comparing the index based scanagainst this one. Measured on the JVM, one timed run after two warmup passes:
Compatibility
:split-keypairs-over-multiple-lines?is deprecated. It continues to work,mapping to
:all, and emits a deprecation warning.The command line flag is unchanged for existing callers. Passing it with no
argument still means
:all, and--no-split-keypairs-over-multiple-linesstill disables the rule. It additionally accepts a mode, given either as
--split-keypairs-over-multiple-lines only-multilineor--split-keypairs-over-multiple-lines=only-multiline.