helpers icon indicating copy to clipboard operation
helpers copied to clipboard

Markdown code blocks are reflowed

Open sonniki opened this issue 10 months ago • 1 comments

    [tool.poetry.dependencies]
    ...
    pytest-timeout = "*"
    ...

turns into

    [tool.poetry.dependencies] ... pytest-timeout = "\*" ...
  amp==1.1.4
  async_solipsism==0.3
  beautifulsoup4==4.11.1
  botocore==1.24.37
  cvxopt==1.3.0
  cvxpy==1.2.0
  dill==0.3.4
  environs==9.5.0
  ...

turns into

    amp==1.1.4 async_solipsism==0.3 beautifulsoup4==4.11.1 botocore==1.24.37
  cvxopt==1.3.0 cvxpy==1.2.0 dill==0.3.4 environs==9.5.0 ...

See docs/work_tools/all.devops_docker.how_to_guide.md after linting

sonniki avatar Feb 06 '25 14:02 sonniki

I would

  1. Understand which steps is responsible for this
  2. Check on Internet if there is a way to disable this unwanted behavior
  3. If there is no way to do it, we can add a step to automatically revert those changes (it shouldn't be too difficult)

gpsaggese avatar Feb 12 '25 14:02 gpsaggese

@sandeepthalapanane this is a Linter bug fix issue. Some useful links for debugging Linter:

sonniki avatar Apr 10 '25 19:04 sonniki

The usual flow is

  1. Create unit tests to reproduce the problem (the general Linter test file is linters/test/test_amp_dev_scripts.py although it would be best to put the unit tests in the test file for the specific Linter step that's causing the problem)
  2. Fix the bug
  3. Confirm with unit tests from step (1) that the problem is fixed

sonniki avatar Apr 10 '25 19:04 sonniki

The issue is because of the Prettier library. The Prettier is not treating the block as fenced.

One solution is we can skip Prettier formatting for specific code blocks by adding a <!-- prettier-ignore --> comment immediately above the markdown block. For ref, see the official Prettier docs here:
https://prettier.io/docs/en/ignore.html

Example:

<!-- prettier-ignore -->
```markdown
[tool.poetry.dependencies]
...
pytest-timeout = "*"
...

sandeepthalapanane avatar Apr 11 '25 19:04 sandeepthalapanane

This solution is fine if nothing else works, but just wondering, do we know why it's happening with these code blocks but not the others?

sonniki avatar Apr 11 '25 19:04 sonniki

Let's create examples to make sure we understand what is the problem. Adding the ignore is not a bad idea.

gpsaggese avatar Apr 13 '25 23:04 gpsaggese

I attempted to lint the below example with and without the markdown code block. It seems to be treating the markdown code fencing as another markdown, and the text inside the fence block is being formatted as a paragraph. The linter script passes --prose-wrap argument to Prettier. It reflows any lines that are not fenced code or bullet lists into a single wrapped paragraph. When markdown is not used, Prettier is considering it as a fenced block and stops formatting.

```markdown
[tool.poetry.dependencies]
...
pytest-timeout = "*"
...
[tool.poetry.dependencies]
...
pytest-timeout = "*"
...

sandeepthalapanane avatar Apr 14 '25 18:04 sandeepthalapanane

So the conclusion is that we'll turn "```markdown" into "```text" (for example), and problem solved?

sonniki avatar Apr 14 '25 19:04 sonniki

So the conclusion is that we'll turn "markdown" into "text" (for example), and problem solved?

Yes, this is one solution, or adding ignore is another solution. Let me know which solution to implement.

sandeepthalapanane avatar Apr 14 '25 20:04 sandeepthalapanane

So the conclusion is that we'll turn "markdown" into "text" (for example), and problem solved?

The "text" solution and <!-- prettier-ignore --> are both working. Would you like me to add the test case in dev_scripts_helpers/documentation/test/test_dockerized_prettier.py?

sandeepthalapanane avatar Apr 15 '25 19:04 sandeepthalapanane

I would go for the "text" solution, and make this a test in linters.

@sandeepthalapanane as a note in general, you don't have to confirm all of your decisions. In many cases you can use your best judgement to come up with a course of action, file a PR with implementation and assign us as reviewers - then we will take a look and go from there. If it's something more complex, that would require a lot of time and effort to implement, then getting approval beforehand makes more sense, but then try to propose solutions rather than ask questions.

sonniki avatar Apr 15 '25 19:04 sonniki

Done

sonniki avatar Apr 16 '25 19:04 sonniki