apify / apify-docs

This project is the home of Apify's documentation.
https://docs.apify.com
Apache License 2.0
29 stars 76 forks source link

Lint code examples #864

Open mtrunkat opened 8 months ago

mtrunkat commented 8 months ago

Every code example should be linted (+editorconfig applied) to follow Apify code formatting guidelines.

B4nan commented 8 months ago

I've actually enabled eslint on code blocks last week via #861, so this should be done already (for js/json/ts code blocks at least)

Note that this introduces a new problem, we often don't have fully valid code in the code blocks so as part of that PR I had to move some JSON code blocks to json5 which is more loose (but I think it is not syntax highlighted, which might be fixable, want to look into that soon).

+editorconfig applied

I don't think that would be possible, not without too much hustle. If we want that, the code blocks should be moved to regular code files with proper extension and included in the markdown (as we do with some examples in crawlee). Using this approach would also unlock any other kind of linting, including whatever we want to use on python code.

mtrunkat commented 8 months ago

@B4nan - Oh, cool! Let's keep this open to make sure we add Python. But JS is a huge step.

vdusek commented 8 months ago

Hi, sorry for the late answer, I had to overlook this.

We use Ruff for the Python projects (which is both linter & formatter). I did a quick research and unfortunately, neither linting nor code formatting of markdown code blocks is supported, yet. Here is the open issue - https://github.com/astral-sh/ruff/issues/3792.

In the opened issue someone links the PR https://github.com/astral-sh/ruff/pull/9030. However, it only adds support for linting & formatting the code blocks inside Python docstrings, not code blocks in markdown documents.