From d94b28d6ff5d15c8f8b63592a7bc8e87088bb91e Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Wed, 15 Nov 2023 18:30:33 +0100 Subject: [PATCH] ruff: add module ruff is Python linter and code formatter, written in Rust. See . --- modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/ruff.nix | 45 +++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/ruff/default.nix | 1 + tests/modules/programs/ruff/expected.toml | 8 ++++ tests/modules/programs/ruff/ruff.nix | 23 ++++++++++++ 7 files changed, 86 insertions(+) create mode 100644 modules/programs/ruff.nix create mode 100644 tests/modules/programs/ruff/default.nix create mode 100644 tests/modules/programs/ruff/expected.toml create mode 100644 tests/modules/programs/ruff/ruff.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index d8841156f..052c23a68 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 e49e7e8bf..ced8e9510 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 000000000..e1490089a --- /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 6fbd09bc8..497f363cc 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 000000000..c4d61acc0 --- /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 000000000..8c42d2be1 --- /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 000000000..26654d550 --- /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} + ''; +}