Skip to content

Commit 5734690

Browse files
committed
feat(analyze): add collection of unused keywords and variables on the CLI
Add support for collecting unused keyword and variable diagnostics when running `robotcode analyze code` from the command line. The feature can be enabled in `robot.toml`: ```toml [tool.robotcode-analyze.code] collect-unused = true ``` or controlled directly per invocation: ```bash robotcode analyze code --collect-unused robotcode analyze code --no-collect-unused ```
1 parent 6ef90f1 commit 5734690

File tree

10 files changed

+226
-145
lines changed

10 files changed

+226
-145
lines changed

docs/03_reference/cli.md

Lines changed: 80 additions & 65 deletions
Large diffs are not rendered by default.

docs/03_reference/config.md

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ Selects the Default profile if no profile is given at command line.
155155

156156
Examples:
157157
```toml
158-
default_profiles = "default"
158+
default-profiles = "default"
159159
```
160160

161161
```toml
162-
default_profiles = ["default", "Firefox"]
162+
default-profiles = ["default", "Firefox"]
163163
```
164164

165165
## doc
@@ -507,9 +507,9 @@ in the `all` mode.
507507
**passed:** remove data only from keywords in passed
508508
test cases and suites
509509

510-
**for:** remove passed iterations from for loops
510+
**for:** remove passed iterations from FOR loops
511511

512-
**while:** remove passed iterations from while loops
512+
**while:** remove passed iterations from WHILE loops
513513

514514
**wuks:** remove all but the last failing keyword
515515
inside `BuiltIn.Wait Until Keyword Succeeds`
@@ -604,7 +604,6 @@ Add documentation to tags matching the given
604604
pattern. Documentation is shown in `Test Details` and
605605
also as a tooltip in `Statistics by Tag`. Pattern can
606606
use `*`, `?` and `[]` as wildcards like --test.
607-
Documentation can contain formatting like --doc.
608607

609608
Examples:
610609

@@ -893,7 +892,7 @@ corresponds to the `-P --pythonpath path *` option of _libdoc_
893892
Type: `bool | Flag | None`
894893

895894
Do not print the path of the generated output file
896-
to the console. New in RF 4.0.
895+
to the console.
897896

898897
corresponds to the `--quiet` option of _libdoc_
899898

@@ -906,7 +905,7 @@ JSON spec files. RAW means preserving the original
906905
documentation format and HTML means converting
907906
documentation to HTML. The default is RAW with XML
908907
spec files and HTML with JSON specs and when using
909-
the special LIBSPEC format. New in RF 4.0.
908+
the special LIBSPEC format.
910909

911910
corresponds to the `-s --specdocformat RAW|HTML` option of _libdoc_
912911

@@ -1438,9 +1437,9 @@ in the `all` mode.
14381437
**passed:** remove data only from keywords in passed
14391438
test cases and suites
14401439

1441-
**for:** remove passed iterations from for loops
1440+
**for:** remove passed iterations from FOR loops
14421441

1443-
**while:** remove passed iterations from while loops
1442+
**while:** remove passed iterations from WHILE loops
14441443

14451444
**wuks:** remove all but the last failing keyword
14461445
inside `BuiltIn.Wait Until Keyword Succeeds`
@@ -1513,7 +1512,6 @@ Add documentation to tags matching the given
15131512
pattern. Documentation is shown in `Test Details` and
15141513
also as a tooltip in `Statistics by Tag`. Pattern can
15151514
use `*`, `?` and `[]` as wildcards like --test.
1516-
Documentation can contain formatting like --doc.
15171515

15181516
Examples:
15191517

@@ -1802,7 +1800,6 @@ Type: `bool | Flag | None`
18021800
Processes output also if the top level suite is
18031801
empty. Useful e.g. with --include/--exclude when it
18041802
is not an error that there are no matches.
1805-
Use --skiponfailure when starting execution instead.
18061803

18071804
corresponds to the `--processemptysuite` option of _rebot_
18081805

@@ -1839,9 +1836,9 @@ in the `all` mode.
18391836
**passed:** remove data only from keywords in passed
18401837
test cases and suites
18411838

1842-
**for:** remove passed iterations from for loops
1839+
**for:** remove passed iterations from FOR loops
18431840

1844-
**while:** remove passed iterations from while loops
1841+
**while:** remove passed iterations from WHILE loops
18451842

18461843
**wuks:** remove all but the last failing keyword
18471844
inside `BuiltIn.Wait Until Keyword Succeeds`
@@ -1989,7 +1986,6 @@ Add documentation to tags matching the given
19891986
pattern. Documentation is shown in `Test Details` and
19901987
also as a tooltip in `Statistics by Tag`. Pattern can
19911988
use `*`, `?` and `[]` as wildcards like --test.
1992-
Documentation can contain formatting like --doc.
19931989

19941990
Examples:
19951991

@@ -2114,9 +2110,9 @@ in the `all` mode.
21142110
**passed:** remove data only from keywords in passed
21152111
test cases and suites
21162112

2117-
**for:** remove passed iterations from for loops
2113+
**for:** remove passed iterations from FOR loops
21182114

2119-
**while:** remove passed iterations from while loops
2115+
**while:** remove passed iterations from WHILE loops
21202116

21212117
**wuks:** remove all but the last failing keyword
21222118
inside `BuiltIn.Wait Until Keyword Succeeds`
@@ -2286,7 +2282,6 @@ Add documentation to tags matching the given
22862282
pattern. Documentation is shown in `Test Details` and
22872283
also as a tooltip in `Statistics by Tag`. Pattern can
22882284
use `*`, `?` and `[]` as wildcards like --test.
2289-
Documentation can contain formatting like --doc.
22902285

22912286
Examples:
22922287

@@ -2628,6 +2623,20 @@ Examples:
26282623
exit_code_mask = "error|warn"
26292624
```
26302625

2626+
## tool.robotcode-analyze.code.collect-unused
2627+
2628+
Type: `bool | None`
2629+
2630+
Enables collection of unused keyword and unused variable diagnostics.
2631+
By default this is disabled. Set to `true` to report unused keywords and variables.
2632+
2633+
Examples:
2634+
2635+
```toml
2636+
[tool.robotcode-analyze.code]
2637+
collect_unused = true
2638+
```
2639+
26312640
## tool.robotcode-analyze.code.exit-code-mask
26322641

26332642
Type: `list[Literal['error', 'warn', 'warning', 'info', 'information', 'hint', 'all']] | None`
@@ -2739,6 +2748,20 @@ Type: `CodeConfig | None`
27392748

27402749
Extend the code analysis configuration.
27412750

2751+
## tool.robotcode-analyze.extend-code.collect-unused
2752+
2753+
Type: `bool | None`
2754+
2755+
Enables collection of unused keyword and unused variable diagnostics.
2756+
By default this is disabled. Set to `true` to report unused keywords and variables.
2757+
2758+
Examples:
2759+
2760+
```toml
2761+
[tool.robotcode-analyze.code]
2762+
collect_unused = true
2763+
```
2764+
27422765
## tool.robotcode-analyze.extend-code.exit-code-mask
27432766

27442767
Type: `list[Literal['error', 'warn', 'warning', 'info', 'information', 'hint', 'all']] | None`
@@ -2927,6 +2950,37 @@ analyze the library search order in a file specified with
29272950
so you can define a global order here. Just make sure to call the `Set Library Search Order`
29282951
keyword somewhere in your robot file or internally in your library.
29292952

2953+
## tool.robotcode-analyze.load-library-timeout
2954+
2955+
Type: `int | None`
2956+
2957+
Specifies the timeout in seconds for loading (importing) libraries and variable files during
2958+
analysis. Increase this if your libraries perform heavy initialization (network calls, large
2959+
dependency graphs, model loading, etc.).
2960+
2961+
Must be > 0 when set. If you omit this key, RobotCode will instead look for the environment
2962+
variable `ROBOTCODE_LOAD_LIBRARY_TIMEOUT`; otherwise it will use the internal default `10`.
2963+
2964+
Examples:
2965+
2966+
```toml
2967+
[tool.robotcode-analyze]
2968+
# Fast fail if libraries normally import in < 2s
2969+
load_library_timeout = 5
2970+
```
2971+
2972+
```toml
2973+
[tool.robotcode-analyze]
2974+
# Allow heavy bootstrap (e.g. Selenium + large resource trees)
2975+
load_library_timeout = 30
2976+
```
2977+
2978+
```toml
2979+
[tool.robotcode-analyze]
2980+
# Omit to use default
2981+
# load_library_timeout = 15
2982+
```
2983+
29302984
## tool.robotcode-analyze.modifiers
29312985

29322986
Type: `ModifiersConfig | None`
@@ -3118,48 +3172,3 @@ option is specified.
31183172
corresponds to the `-x --xunit file` option of _robot_
31193173

31203174

3121-
## tool.robotcode-analyze.global-library-search-order
3122-
3123-
Type: `list[str] | None`
3124-
3125-
Specifies a global search order for libraries and resources used during static analysis.
3126-
This helps disambiguate keywords with identical names coming from multiple sources.
3127-
RobotCode cannot infer dynamic changes done at runtime via `Set Library Search Order`, so
3128-
define a deterministic order here if needed.
3129-
3130-
Examples:
3131-
3132-
```toml
3133-
[tool.robotcode-analyze]
3134-
global_library_search_order = ["MyLib", "BuiltIn", "Collections"]
3135-
```
3136-
3137-
## tool.robotcode-analyze.load-library-timeout
3138-
3139-
Type: `int | None`
3140-
3141-
Specifies the timeout in seconds for loading (importing) libraries and variable files during analysis. Increase this if your libraries perform heavy initialization (network calls, large dependency graphs, model loading, etc.).
3142-
3143-
Must be > 0 when set. If you omit this key, RobotCode will instead look for the environment variable `ROBOTCODE_LOAD_LIBRARY_TIMEOUT`; otherwise it will use the internal default `10`.
3144-
3145-
Examples:
3146-
3147-
```toml
3148-
[tool.robotcode-analyze]
3149-
# Fast fail if libraries normally import in < 2s
3150-
load_library_timeout = 5
3151-
```
3152-
3153-
```toml
3154-
[tool.robotcode-analyze]
3155-
# Allow heavy bootstrap (e.g. Selenium + large resource trees)
3156-
load_library_timeout = 30
3157-
```
3158-
3159-
```toml
3160-
[tool.robotcode-analyze]
3161-
# Omit to use default
3162-
# load_library_timeout = 15
3163-
```
3164-
3165-

0 commit comments

Comments
 (0)