Skip to content

Docs: new guides section isn't being linted #4857

Closed

Description

@helderco

We lint the code snippets in the SDK guides, but the new Guides section uses a different path for the snippets that isn't being included in that linting. This is creating some inconsistency in code formatting.

With the playground embeds though, it's no longer a direct reference between the snippet file and what you see on the page. I assume the playground embeds are created from the snippets, @vikram-dagger please correct me if I'm wrong.

Activity

  1. added
    area/documentation
    on Mar 29, 2023
  2. vikram-dagger commented on Mar 30, 2023

    @vikram-dagger
    Contributor

    We lint the code snippets in the SDK guides,

    Can you please point me to this code?

    With the playground embeds though, it's no longer a direct reference between the snippet file and what you see on the page. I assume the playground embeds are created from the snippets, @vikram-dagger please correct me if I'm wrong.

    Correct, documented at https://github.com/dagger/dagger/blob/main/docs/STYLE_GUIDE.md#api-playground-embeds

  3. helderco commented on Mar 30, 2023

    @helderco
    ContributorAuthor

    Can you please point me to this code?

    Sure!

    // NodeJS
    eg.Go(func() error {
    nodeSnippets := c.Directory().
    WithDirectory("/", workdir.Directory("docs/current/sdk/nodejs/snippets"))
    _, err = c.Container().
    From("node:16-alpine").
    WithWorkdir("/src").
    WithMountedDirectory("/src", nodeSnippets).
    WithExec([]string{"yarn", "install"}).
    WithExec([]string{"yarn", "lint"}).
    ExitCode(gctx)
    return err
    })
    // Go is already linted by engine:lint
    // Python is already linted by sdk:python:lint

    In Python:

    eg.Go(func() error {
    path := "docs/current/sdk/python/snippets"
    workdir := util.Repository(c)
    snippets := c.Directory().
    WithDirectory("/", workdir.Directory(path))
    _, err = base.
    WithMountedDirectory(fmt.Sprintf("/%s", path), snippets).
    WithExec([]string{"poe", "lint-docs"}).
    ExitCode(gctx)
    return err
    })

    Where poe lint-docs is:

    [tool.poe.env.DOCS_SNIPPETS]
    default = "../../docs/current/sdk/python/snippets"

    [tool.poe.tasks.lint-docs]
    ref = "lint ${DOCS_SNIPPETS}"

    Note: I actually started to fix this locally but didn't finish, to deal with other priorities.

    Go seems fine because the linting is done for all go files in the repo:

    repo := util.RepositoryGoCodeOnly(c)
    _, err = c.Container().
    From("golangci/golangci-lint:v1.51").
    WithMountedDirectory("/app", repo).
    WithWorkdir("/app").
    WithExec([]string{"golangci-lint", "run", "-v", "--timeout", "5m"}).
    ExitCode(ctx)

    Maybe we should do the same for the others. In Python, the linter has slightly different rules for docs, but that should be fine if their path is preserved.

  4. helderco commented on Mar 30, 2023

    @helderco
    ContributorAuthor

    With the playground embeds though, it's no longer a direct reference between the snippet file and what you see on the page. I assume the playground embeds are created from the snippets, @vikram-dagger please correct me if I'm wrong.

    Correct, documented at https://github.com/dagger/dagger/blob/main/docs/STYLE_GUIDE.md#api-playground-embeds

    Nice, I forgot about that. 🙂

    From that guide:

    Currently supported file extensions are .go, .ts, .js, .python.

    First of all, the extension for python is wrong (.py). Secondly, snippets for nodejs have been using .mjs. Is that supported? Or even .mts?

  5. vikram-dagger commented on Mar 31, 2023

    @vikram-dagger
    Contributor

    With the playground embeds though, it's no longer a direct reference between the snippet file and what you see on the page. I assume the playground embeds are created from the snippets, @vikram-dagger please correct me if I'm wrong.

    Correct, documented at https://github.com/dagger/dagger/blob/main/docs/STYLE_GUIDE.md#api-playground-embeds

    Nice, I forgot about that. 🙂

    From that guide:

    Currently supported file extensions are .go, .ts, .js, .python.

    First of all, the extension for python is wrong (.py). Secondly, snippets for nodejs have been using .mjs. Is that supported? Or even .mts?

    .py and .mjs are both supported. .mts is not. I've updated the guide with this info - thanks for pointing it out! #4874

  6. gerhard commented on Mar 31, 2023

    @gerhard
    Contributor

    Is linting the snippets in docs sufficient to ensure that they run successfully?

    Linting is the right way of catching programmatic and stylistic errors, but not testing that the code actually runs. Maybe linting is enough for now, but I am pretty sure that we want some type of integration tests that would show failures - maybe in GitHub Actions - when the code fails. Running these snippets and ensuring that they all exit with 0 would be sufficient.


    I know that my comment is not on topic. I am mostly continuing a conversation that we started with @vikram-dagger on March 28th, 2023.

  7. helderco commented on Mar 31, 2023

    @helderco
    ContributorAuthor

    Yes, two separate things. Linting is fast and easy, brings more consistency to the examples and helps us follow good practices for users to copy.

    As for tests, that was discussed but don't remember when or where. What I remember is that Andrea (I think) alluded that it was a burden on CI (time and cost continually increasing when adding more docs) and maintainability (keeping tests up to date with the code).

    On maintainability, with CUE it was a bit easier since it's declarative, now it's a much harder problem with the multiple languages. As for simply running a script and checking exit code, it's not that simple. For example, many guides use external services that need to be set up with proper keys (GCR, AWS...).

    So I believe consensus (at least for now) is that it's not worth to automatically test the documentation snippets.

  8. mircubed commented on Apr 3, 2023

    @mircubed
    Contributor

    @vikram-dagger can we close this issue?

  9. helderco commented on Apr 3, 2023

    @helderco
    ContributorAuthor

    It's not done.

  10. helderco commented on Jun 30, 2023

    @helderco
    ContributorAuthor

    This was fixed in #5351

  11. helderco commented on Jun 30, 2023

    @helderco
    ContributorAuthor

    I realized Node.js isn't fixed yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions