keep-sorted icon indicating copy to clipboard operation
keep-sorted copied to clipboard

Feature Request: skip_last_lines (in addition to skip_lines=x)

Open aranair opened this issue 9 months ago • 1 comments

When running keep-sorted in our ruby code base, we have the following syntax that wraps arrays

# keep-sorted start
SOME_ARRAY = %w[
  AAA
  BBB
  CCC
].freeze
# keep-sorted end

We are unable to nest the # keep-sorted start/end within the array because of the %w. E.g. this is incorrect

SOME_ARRAY = %w[
  # keep-sorted start
  AAA
  BBB
  CCC
  # keep-sorted end
].freeze

What we're doing as somewhat of a workaround, which we believe is effectively sorting the last row ].freeze as well (which would be incorrect)

# keep-sorted start skip_lines=1 block=yes
SOME_ARRAY = %w[
  AAA
  BBB
  CCC
].freeze
# keep-sorted end

The feature request is to add a syntax that allows something like this:

# keep-sorted start skip_lines=1 skip_last_lines=1 block=yes
SOME_ARRAY = %w[
  AAA
  BBB
  CCC
].freeze
# keep-sorted end

aranair avatar Apr 04 '25 13:04 aranair

I like the idea! I'd generally like to avoid adding one-off options for everything though. A couple thoughts

  • Is there some other array creation syntax in ruby that would let you nest the keep-sorted directives inside the braces?
  • I wonder if this could perhaps just be part of the same skip_lines option, except we use negative numbers to indicate an offset from the end statement. skip_lines=1,-1

JeffFaer avatar Apr 18 '25 20:04 JeffFaer