markdownlint icon indicating copy to clipboard operation
markdownlint copied to clipboard

Enforce non-wrapping (#317)

Open mrmanc opened this issue 5 years ago • 23 comments
trafficstars

Description

I’ve added configuration to MD01~2~3 to switch it to enforce not wrapping to allow us to enforce a consistent approach. This is described in https://cirosantilli.com/markdown-style-guide/#option-wrap-no

I’m not a ruby dev but this seems to work, but please let me know where I’ve not followed convention or where there are tricks to make things read better.

I’ve created the test cases I can think of. I’m not happy with adding to overlines as these are not lines that are ‘over’. Perhaps this should be renamed something line violation_lines?

I also think there’s a fair bit of duplication in this function now, and some in the file in general around extracting line numbers for various things. I tried extracting a helper function in the test but this didn’t work. I was wondering about adding some more functionality to doc.rb but wanted to check with others first.

Related Issues

Fixes #317.

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation (non-breaking change that does not add functionality but updates documentation)
  • [ ] Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • [x] I have read the CONTRIBUTING document.
  • [x] Wrote good commit messages
  • [x] Feature branch is up-to-date with master, if not - rebase it
  • [x] Added tests for all new/changed functionality, including tests for positive and negative scenarios
  • [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences

mrmanc avatar Jun 18 '20 17:06 mrmanc

huh, I dunno why travis never kicked in. Since I'm going to squash your commits together anyway, could you squash and forcepush to see if travis will kick in?

jaymzh avatar Jun 19 '20 18:06 jaymzh

Please don’t merge—I’m going to continue work in this PR to refine the new style option and add further styles, as per DavidAnson/markdownlint/issues/298.

My rough plan is to follow these steps as separate commits

  • [x] change existing wrapped to strict
  • [ ] change not_wrapped to single
  • [ ] add stern option as per the NodeJS version
  • [ ] continue to add other options as per DavidAnson/markdownlint/issues/298 (including sentence) one per commit

Following this, I hope to add to the NodeJS version to make the two rules consistent.

mrmanc avatar Jul 06 '20 13:07 mrmanc

I dislike "strict" and "stern" - how is a mere mortal supposed to tell these apart? Without reference the docs I'll never remember which is which and I was involved in this PR. I would argue:

  • wrapped
  • sentence
  • not_wrapped

Are the right names. If we want to make aliases to have compat with the NodeJS version that's fine, but lets make these options less opaque.

jaymzh avatar Jul 06 '20 17:07 jaymzh

Are the right names. If we want to make aliases to have compat with the NodeJS version that's fine, but lets make these options less opaque.

Sure, that’s a nice compromise—I’ll look at changing this to support the NodeJS options compatible.

@DavidAnson Hope you don’t mind me tagging you in, but I’d rather discuss this in one place as a group rather than going back and forth 😃 Does this suit you—having values such as wrapped and not_wrapped with aliases to ensure compatibility with your version? I imagine you care about the compatibility in both directions. There could be aliases either side, or we could try to find one canonical set of values (and make sure things are backwards compatible).

mrmanc avatar Jul 06 '20 18:07 mrmanc

@mrmanc you can set a PR as draft, then it cannot be merged by accident.

See the blog post on the topic.

jonasbn avatar Jul 06 '20 18:07 jonasbn

Per my comment, I think there are at least six different modes this rule can operate in. My proposed names are not perfect and I’m happy to discuss others or alias them as suggested! That said, I’d like to understand how the three proposed names above map to the six modes I list and the current functioning of this rule in Ruby. Which specific behaviors are being suggested?

DavidAnson avatar Jul 06 '20 19:07 DavidAnson

Related reading:

DavidAnson avatar Jul 06 '20 19:07 DavidAnson

@mrmanc you can set a PR as draft, then it cannot be merged by accident.

Thanks—good advice, but (unless I’ve been missing something) annoyingly you can only do it at the point of creation. I didn’t intend this to be as long-running as it is, so I didn’t create it that way. I’d love a way to retrospectively mark a PR as draft! 😄

mrmanc avatar Jul 06 '20 21:07 mrmanc

I’d like to understand how the three proposed names above map to the six modes I list and the current functioning of this rule in Ruby

(comment removed as I later noticed https://github.com/DavidAnson/markdownlint/issues/298#issuecomment-654438412, and will digest that tomorrow as I’m signing off for tonight).

mrmanc avatar Jul 06 '20 21:07 mrmanc

Gah I put this response on the wrong ticket. Moving here

Sorry missed that comment

  • space (default, first space after 80) - I don't think this should be a thing at all. Either you want it to fit on a terminal screen at 80 chars or you don't.
  • strict (nothing beyond 80) - Sure, I'd call this wrapped
  • stern (only beyond 80 if no spaces) - Probably shouldn't be a separate mode, but instead an option like exempt_single_word => true - should default to true. That said - is there every any reason NOT to allow this? I can't imagine, but sure, we can make it optional. But it's an orthogonal option.
  • single (no wrapping, single line - NEW) - yup, I'd call not_wrapped
  • sentence (break after period, etc - NEW) - yup
  • semantic (https://sembr.org/, UNSUPPORTED for now) - yup.

So in other words, I'd have wrapped, not_wrapped, sentence, semantic as modes, with a separate option for exempt_single_word.

As to semantic, I guess the only real rules we can enforce there is that you always break after a sentence (just like with sentence) but we allow breaks inbetween sentences.... we certainly can't know where semantic breaks should be inside a sentence.

jaymzh avatar Jul 06 '20 21:07 jaymzh

What I think you’ll find is that the first option, what I called “space” and what you don’t want at all is the default behavior in the Ruby (and therefore Node) implementation.

DavidAnson avatar Jul 06 '20 22:07 DavidAnson

You are absolutely right. That... I've literally NEVER seen a linter do that. That's such a strange implementation.

Well we can't break the default behavior without a major version, so instead lets do this.

Modes:

  • space - First space past 80 chars. Current default. Plan to deprecate.
  • wrapped - 80 chars, like any other linter. aliased to strict for NodeJs compat. Maybe to be the future default.
  • not_wrapped - No wrapping - every para is a single line.
  • sentence - Must break at every sentence, and no mid-sentence breaks
  • semantic - Must break at every sentence, allows mid-sentence breaks.

Other options:

  • code_blocks - same as today, enforce on codeblocks
  • tables - same as today, enforce on tables
  • exempt_single_words - Exempt single worlds.

?

jaymzh avatar Jul 06 '20 23:07 jaymzh

@mrmanc you can set a PR as draft, then it cannot be merged by accident.

Thanks—good advice, but (unless I’ve been missing something) annoyingly you can only do it at the point of creation. [...] I’d love a way to retrospectively mark a PR as draft! 😄

That is actually possible now :)

waldyrious avatar Jul 07 '20 09:07 waldyrious

That is actually possible now :)

Amazing! Thanks for the pointer @waldyrious—I totally hadn’t spotted that change creep in. I work with an on-prem GH Enterprise Server most of the time, and so I suffer feature latency.

mrmanc avatar Jul 07 '20 11:07 mrmanc

Just a note to say I appreciate it’s been a while, but I haven’t forgotten or given up on this. I still plan to pick this up when I get some time to write code (which I am looking forward to).

mrmanc avatar Aug 11 '20 19:08 mrmanc

hey @mrmanc - ping?

jaymzh avatar Jan 25 '21 00:01 jaymzh

Argh… thanks for the ping. Sorry for the radio silence. Although I haven’t been able to find time to focus on this, I still want to get it done… and hope to be able to find time soon.

mrmanc avatar Feb 09 '21 19:02 mrmanc

@mrmanc did this die on the vine?

stephencweiss avatar Apr 02 '22 16:04 stephencweiss

@stephencweiss Yes, pretty much. I have tried to get started a couple of times and ended up getting distracted with Ruby version installation issues. Happy for someone else to pick it up, but I’m not ruling out getting around to it.

mrmanc avatar Apr 03 '22 19:04 mrmanc

@mrmanc - I recommend using rbenv or rvm to make virtual ruby installs rather than mucking with ruby installs directly.

jaymzh avatar Apr 05 '22 16:04 jaymzh

Thanks @jaymzh—I was using rbenv in this case… it was using ruby-install I think that I had the issues.

mrmanc avatar Apr 07 '22 17:04 mrmanc

ping, @mrmanc - just checking in again

jaymzh avatar May 17 '22 23:05 jaymzh

ping again @mrmanc

jaymzh avatar Sep 30 '22 02:09 jaymzh

Closing over a year since last activity.

jaymzh avatar Sep 06 '23 21:09 jaymzh