mirror of
				https://github.com/NotAShelf/nvf.git
				synced 2025-11-03 20:22:21 +00:00 
			
		
		
		
	language/svelte: migrate to conform/nvim-lint
This commit is contained in:
		
					parent
					
						
							
								0db226be84
							
						
					
				
			
			
				commit
				
					
						bc76ced636
					
				
			
		
					 1 changed files with 36 additions and 44 deletions
				
			
		| 
						 | 
					@ -9,9 +9,9 @@
 | 
				
			||||||
  inherit (lib.modules) mkIf mkMerge;
 | 
					  inherit (lib.modules) mkIf mkMerge;
 | 
				
			||||||
  inherit (lib.lists) isList;
 | 
					  inherit (lib.lists) isList;
 | 
				
			||||||
  inherit (lib.meta) getExe;
 | 
					  inherit (lib.meta) getExe;
 | 
				
			||||||
 | 
					  inherit (lib.generators) mkLuaInline;
 | 
				
			||||||
  inherit (lib.types) enum either listOf package str;
 | 
					  inherit (lib.types) enum either listOf package str;
 | 
				
			||||||
  inherit (lib.nvim.lua) expToLua;
 | 
					  inherit (lib.nvim.lua) expToLua;
 | 
				
			||||||
  inherit (lib.nvim.languages) diagnosticsToLua;
 | 
					 | 
				
			||||||
  inherit (lib.nvim.types) mkGrammarOption diagnostics;
 | 
					  inherit (lib.nvim.types) mkGrammarOption diagnostics;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  cfg = config.vim.languages.svelte;
 | 
					  cfg = config.vim.languages.svelte;
 | 
				
			||||||
| 
						 | 
					@ -39,52 +39,38 @@
 | 
				
			||||||
  formats = {
 | 
					  formats = {
 | 
				
			||||||
    prettier = {
 | 
					    prettier = {
 | 
				
			||||||
      package = pkgs.nodePackages.prettier;
 | 
					      package = pkgs.nodePackages.prettier;
 | 
				
			||||||
      nullConfig = ''
 | 
					 | 
				
			||||||
        table.insert(
 | 
					 | 
				
			||||||
          ls_sources,
 | 
					 | 
				
			||||||
          null_ls.builtins.formatting.prettier.with({
 | 
					 | 
				
			||||||
            command = "${cfg.format.package}/bin/prettier",
 | 
					 | 
				
			||||||
          })
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
      '';
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    biome = {
 | 
					    biome = {
 | 
				
			||||||
      package = pkgs.biome;
 | 
					      package = pkgs.biome;
 | 
				
			||||||
      nullConfig = ''
 | 
					 | 
				
			||||||
        table.insert(
 | 
					 | 
				
			||||||
          ls_sources,
 | 
					 | 
				
			||||||
          null_ls.builtins.formatting.biome.with({
 | 
					 | 
				
			||||||
            command = "${cfg.format.package}/bin/biome",
 | 
					 | 
				
			||||||
          })
 | 
					 | 
				
			||||||
        )
 | 
					 | 
				
			||||||
      '';
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # TODO: specify packages
 | 
					  # TODO: specify packages
 | 
				
			||||||
  defaultDiagnosticsProvider = ["eslint_d"];
 | 
					  defaultDiagnosticsProvider = ["eslint_d"];
 | 
				
			||||||
  diagnosticsProviders = {
 | 
					  diagnosticsProviders = {
 | 
				
			||||||
    eslint_d = {
 | 
					    eslint_d = let
 | 
				
			||||||
      package = pkgs.eslint_d;
 | 
					      pkg = pkgs.eslint_d;
 | 
				
			||||||
      nullConfig = pkg: ''
 | 
					    in {
 | 
				
			||||||
        table.insert(
 | 
					      package = pkg;
 | 
				
			||||||
          ls_sources,
 | 
					      config = {
 | 
				
			||||||
          null_ls.builtins.diagnostics.eslint_d.with({
 | 
					        cmd = getExe pkg;
 | 
				
			||||||
            command = "${getExe pkg}",
 | 
					        # HACK: change if nvim-lint gets a dynamic enable thing
 | 
				
			||||||
            condition = function(utils)
 | 
					        parser = mkLuaInline ''
 | 
				
			||||||
              return utils.root_has_file({
 | 
					          function(output, bufnr, cwd)
 | 
				
			||||||
                "eslint.config.js",
 | 
					            local markers = { "eslint.config.js", "eslint.config.mjs",
 | 
				
			||||||
                "eslint.config.mjs",
 | 
					              ".eslintrc", ".eslintrc.json", ".eslintrc.js", ".eslintrc.yml", }
 | 
				
			||||||
                ".eslintrc",
 | 
					            for _, filename in ipairs(markers) do
 | 
				
			||||||
                ".eslintrc.json",
 | 
					              local path = vim.fs.join(cwd, filename)
 | 
				
			||||||
                ".eslintrc.js",
 | 
					              if vim.loop.fs_stat(path) then
 | 
				
			||||||
                ".eslintrc.yml",
 | 
					                return require("lint.linters.eslint_d").parser(output, bufnr, cwd)
 | 
				
			||||||
              })
 | 
					              end
 | 
				
			||||||
            end,
 | 
					            end
 | 
				
			||||||
          })
 | 
					
 | 
				
			||||||
        )
 | 
					            return {}
 | 
				
			||||||
      '';
 | 
					          end
 | 
				
			||||||
 | 
					        '';
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
in {
 | 
					in {
 | 
				
			||||||
| 
						 | 
					@ -153,16 +139,22 @@ in {
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (mkIf cfg.format.enable {
 | 
					    (mkIf cfg.format.enable {
 | 
				
			||||||
      vim.lsp.null-ls.enable = true;
 | 
					      vim.formatter.conform-nvim = {
 | 
				
			||||||
      vim.lsp.null-ls.sources.svelte-format = formats.${cfg.format.type}.nullConfig;
 | 
					        enable = true;
 | 
				
			||||||
 | 
					        setupOpts.formatters_by_ft.svelte = [cfg.format.type];
 | 
				
			||||||
 | 
					        setupOpts.formatters.${cfg.format.type} = {
 | 
				
			||||||
 | 
					          command = getExe cfg.format.package;
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (mkIf cfg.extraDiagnostics.enable {
 | 
					    (mkIf cfg.extraDiagnostics.enable {
 | 
				
			||||||
      vim.lsp.null-ls.enable = true;
 | 
					      vim.diagnostics.nvim-lint = {
 | 
				
			||||||
      vim.lsp.null-ls.sources = diagnosticsToLua {
 | 
					        enable = true;
 | 
				
			||||||
        lang = "svelte";
 | 
					        linters_by_ft.svelte = cfg.extraDiagnostics.types;
 | 
				
			||||||
        config = cfg.extraDiagnostics.types;
 | 
					        linters =
 | 
				
			||||||
        inherit diagnosticsProviders;
 | 
					          mkMerge (map (name: {${name} = diagnosticsProviders.${name}.config;})
 | 
				
			||||||
 | 
					            cfg.extraDiagnostics.types);
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  ]);
 | 
					  ]);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue