Coverage for src/su6_plugin_svelte_check/cli.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-17 14:04 +0200

1""" 

2This module contains an example of both methods of adding commands to su6. 

3""" 

4from pathlib import Path 

5 

6from su6.plugins import PluginConfig, register, run_tool 

7 

8from .find_project_root import find_project_root 

9 

10 

11@register 

12class SvelteCheckPluginConfig(PluginConfig): 

13 """ 

14 Config without state, loads [tool.su6.demo] from pyproject.toml into self. 

15 """ 

16 

17 strict: bool = False 

18 tsconfig: str = "./tsconfig.json" 

19 

20 

21config = SvelteCheckPluginConfig() 

22 

23 

24@register(add_to_all=True) 

25def svelte_check(strict: bool = None, tsconfig: str = None) -> int: 

26 """ 

27 Register a top-level command. 

28 

29 @register works without () 

30 """ 

31 config.update(strict=strict, tsconfig=tsconfig) 

32 # svelte-check --tsconfig ./tsconfig.json --threshold error 

33 root, _ = find_project_root(("node_modules",)) 

34 executable = str(root / "node_modules/svelte-check/bin/svelte-check") 

35 

36 args = [] 

37 if config.strict: 

38 args.append("--fail-on-warnings") 

39 else: 

40 args.extend(["--threshold", "error"]) 

41 

42 if Path(config.tsconfig).exists(): 

43 args.extend(["--tsconfig", config.tsconfig]) 

44 

45 return run_tool(executable, *args)