diff --git a/modules/misc/news.nix b/modules/misc/news.nix index d8841156..052c23a6 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1302,6 +1302,13 @@ in A new module is available: 'programs.granted'. ''; } + + { + time = "2023-11-22T22:42:16+00:00"; + message = '' + A new module is available: 'programs.ruff'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index e49e7e8b..ced8e951 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -190,6 +190,7 @@ let ./programs/rofi.nix ./programs/rtorrent.nix ./programs/rtx.nix + ./programs/ruff.nix ./programs/sagemath.nix ./programs/sbt.nix ./programs/scmpuff.nix diff --git a/modules/programs/ruff.nix b/modules/programs/ruff.nix new file mode 100644 index 00000000..e1490089 --- /dev/null +++ b/modules/programs/ruff.nix @@ -0,0 +1,45 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.ruff; + + settingsFormat = pkgs.formats.toml { }; + +in { + meta.maintainers = [ hm.maintainers.GaetanLepage ]; + + options.programs.ruff = { + enable = mkEnableOption + "ruff, an extremely fast Python linter and code formatter, written in Rust"; + + package = mkPackageOption pkgs "ruff" { }; + + settings = mkOption { + type = settingsFormat.type; + example = lib.literalExpression '' + { + line-length = 100; + per-file-ignores = { "__init__.py" = [ "F401" ]; }; + lint = { + select = [ "E4" "E7" "E9" "F" ]; + ignore = [ ]; + }; + } + ''; + description = '' + Ruff configuration. + For available settings see . + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."ruff/ruff.toml".source = + settingsFormat.generate "ruff.toml" cfg.settings; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 6fbd09bc..497f363c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -133,6 +133,7 @@ import nmt { ./modules/programs/rio ./modules/programs/ripgrep ./modules/programs/rtx + ./modules/programs/ruff ./modules/programs/sagemath ./modules/programs/sbt ./modules/programs/scmpuff diff --git a/tests/modules/programs/ruff/default.nix b/tests/modules/programs/ruff/default.nix new file mode 100644 index 00000000..c4d61acc --- /dev/null +++ b/tests/modules/programs/ruff/default.nix @@ -0,0 +1 @@ +{ ruff-program = ./ruff.nix; } diff --git a/tests/modules/programs/ruff/expected.toml b/tests/modules/programs/ruff/expected.toml new file mode 100644 index 00000000..8c42d2be --- /dev/null +++ b/tests/modules/programs/ruff/expected.toml @@ -0,0 +1,8 @@ +line-length = 100 + +[lint] +ignore = [] +select = ["E4", "E7", "E9", "F"] + +[per-file-ignores] +"__init__.py" = ["F401"] diff --git a/tests/modules/programs/ruff/ruff.nix b/tests/modules/programs/ruff/ruff.nix new file mode 100644 index 00000000..26654d55 --- /dev/null +++ b/tests/modules/programs/ruff/ruff.nix @@ -0,0 +1,23 @@ +{ ... }: + +{ + programs.ruff = { + enable = true; + + settings = { + line-length = 100; + per-file-ignores = { "__init__.py" = [ "F401" ]; }; + lint = { + select = [ "E4" "E7" "E9" "F" ]; + ignore = [ ]; + }; + }; + }; + + test.stubs.ruff = { }; + + nmt.script = '' + assertFileExists home-files/.config/ruff/ruff.toml + assertFileContent home-files/.config/ruff/ruff.toml ${./expected.toml} + ''; +}