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

Infer formatter from file extension by default #1593

Open
olebedev opened this issue Nov 17, 2024 · 0 comments
Open

Infer formatter from file extension by default #1593

olebedev opened this issue Nov 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@olebedev
Copy link

Follow up issue to this twitter conversation we had with @domenkozar the other day.

Below is initial example that caught my attention by duplication of a file extension and formatter, they are essentially the same thing, but typed twice.

{ pkgs, lib, config, ... }: {
  files = {
    "foo.json".json = {
      foo = "bar";
    };
    "dir/foo.txt".text = "foo";
  };
}

I suggest to create a default heuristic so we infer formatters from the file extension and fall back to explicit definition when necessary. For example:

{ pkgs, lib, config, ... }: {
  files = {
    # Formatters inferred
    "foo.json" = {
      foo = "bar";
    };
    "dir/foo.txt"= "foo";

    # Formatter defined within configuration object, hence the `files` module 
    # must support polymorphism
    "crates/foo/Cargo.lock" = {
      content = { ... };
      formatter = "json";
    };
  };
}

I think it is doable to create a map between the supported formatters and file extensions. By this, we keep cognitive load low and don't cut off total control when it's needed.

@olebedev olebedev added the enhancement New feature or request label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant