Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indented codeblocks throw off all future codeblocks #28

Open
Earlopain opened this issue Dec 12, 2023 · 6 comments · May be fixed by #30
Open

Indented codeblocks throw off all future codeblocks #28

Earlopain opened this issue Dec 12, 2023 · 6 comments · May be fixed by #30

Comments

@Earlopain
Copy link
Contributor

rubocop.yml

require:
  - rubocop-md

AllCops:
  TargetRubyVersion: 3.2
  NewCops: disable

grafik
grafik

test.md since I still don't know how to properly escape markdown here.

I'll try to check this out myself if that's fine with you @palkan, but in case I don't manage like last time I'll let you know. That good?

@palkan
Copy link
Collaborator

palkan commented Dec 12, 2023

I'll try to check this out myself if that's fine with you @palkan, but in case I don't manage like last time I'll let you know. That good?

Yeah, sounds good. Feel free to reach out / submit a draft PR if you encounter any struggles

@palkan
Copy link
Collaborator

palkan commented Dec 12, 2023

What would you consider a solution here? Since we lint MD files by "converting" them into Ruby files, the Layout/InitialIndentation is an expected behaviour (though annoying, for sure). Probably, we can un-indent code blocks during pre-processing and restore them back in the end; the question is how to distinguish between valid (within lists) and invalid indentation.

@Earlopain
Copy link
Contributor Author

Is this extension supposed to care about the indentation of codeblocks themselves in the first place? If I put my codeblock 10 spaces to the right then all I really care about is that the code inside is properly indented relative to that. Anything else feels out of scope, to me at least.

One thing I feel that would be a big help here is by using rubocops 3rd party template support that got added in 1.45. rubocop/rubocop#10839
It allows extensions like this one to process non-rb files and preprocess them appropriately. Basically what is already happening now but "officially sanctioned". Autocomplete like this would be easier to implement I believe, without the comment workaround going on right now.

Would you be open to exploring that? It is pretty involved for this issue and probably more work that necessary. Just want to get your feelings on this, perhaps for something in the future.

@palkan
Copy link
Collaborator

palkan commented Dec 12, 2023

using rubocops 3rd party template support that got added in 1.45.

Oh, haven't seen this; awesome! Yeah, we should migrate to this new API.

@Earlopain
Copy link
Contributor Author

Great to hear! I think I'll try to start with that as I feel it will make fixing this as a second step easier. I feel like nobody has complainted about this issue yet so you can take a bit of time for this.

@Earlopain Earlopain linked a pull request Dec 12, 2023 that will close this issue
9 tasks
@Ravlen
Copy link

Ravlen commented Jun 10, 2024

Coming here as I tested this to link our 2k+ markdown doc files, and see the same issue.

@palkan Re: Probably, we can un-indent code blocks during pre-processing and restore them back in the end; the question is how to distinguish between valid (within lists) and invalid indentation.

My suggestion would be to count the number of spaces before the start of the code block, and trim that amount until the end of the code block. So:

List item:

- ```ruby
  valid, trim 2 characters from every line.
  ```

- Nest some more:

  - ```ruby
    valid, trim 4 from every line
    ```

  - ```ruby
      invalid indentation, trim 4 from every line, but this line still ends up with 2 extra spaces
    ```

After trimming:

List item:

```ruby
valid, trim 2 characters from every line.
```

- Nest some more:

```ruby
valid, trim 4 from every line
```

```ruby
  invalid indentation, trim 4 from every line, but this line still ends up with 2 extra spaces
```

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 a pull request may close this issue.

3 participants