From ddafcae0caac92650ad0dae5305352d99e581e96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 23 Oct 2026 14:43:12 +0200 Subject: [PATCH 01/12] chore: start work on flir rules --- tools/flir-rule.yml.mustache | 66 +++++++++++++++++ tools/generate-flir-rules.R | 135 +++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 tools/flir-rule.yml.mustache create mode 100644 tools/generate-flir-rules.R diff --git a/tools/flir-rule.yml.mustache b/tools/flir-rule.yml.mustache new file mode 100644 index 0000000000..9c9f0d970e --- /dev/null +++ b/tools/flir-rule.yml.mustache @@ -0,0 +1,66 @@ +{{#rules}} +{{^is_first_rule}} +--- +{{/is_first_rule}} +id: igraph-{{when}}-{{fn}}-{{old_name}} +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: +{{#names_to_rewrite_regex}} + - # passed by name + has: { field: name, kind: identifier, regex: '{{{names_to_rewrite_regex}}}' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '{{{function_regex}}}' } +{{/names_to_rewrite_regex}} + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: {{position}}, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '{{{names_blocking_position_regex}}}' } } + inside: + kind: call + has: { field: function, regex: '{{{function_regex}}}' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } +{{#position_after_pipe}} + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: {{position_after_pipe}}, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '{{{names_blocking_position_regex}}}' } } + inside: + kind: call + has: { field: function, regex: '{{{function_regex}}}' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +{{/position_after_pipe}} +fix: {{new_name}} = ~~V~~ +message: igraph {{when}} requires `{{new_name}}` of `{{fn}}()` to be passed by its full name. +{{/rules}} diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R new file mode 100644 index 0000000000..8231b5c06b --- /dev/null +++ b/tools/generate-flir-rules.R @@ -0,0 +1,135 @@ +#!/usr/bin/env Rscript +# +# Generate flir rules from the argument-migration registry (tools/migrations/). +# +# For each registry entry, writes one file `migrate--.yml` holding one +# rule per old positional slot that moved behind `...`. Each rule matches the +# argument R would have bound to that old formal and rewrites it to +# ` = `, in three cases: +# +# - passed by its old name, or by an abbreviation unique under `old`; +# - passed as the k-th unnamed argument of a call that is not piped; +# - passed as the (k-1)-th unnamed argument of a call on the right of `|>`, or +# of `%>%` without a `.` placeholder. +# +# The positional cases only fire when the binding is decidable from syntax: no +# named argument that could take one of the old formals 1..k, no empty slot, no +# `...`. Every other call is left to the runtime recovery. See +# https://github.com/igraph/rigraph/issues/2933. +# +# Usage: +# Rscript tools/generate-flir-rules.R [out_dir] [fn ...] +# +# `out_dir` defaults to inst/flir/rules. By default, rules are written for every +# function in the registry; list function names after `out_dir` to write rules +# for those functions only, e.g. +# Rscript tools/generate-flir-rules.R out/ sample_gnp degree +# +# The YAML lives in tools/flir-rule.yml.mustache, rendered with whisker. + +source(file.path("tools", "generate-migrations.R")) + +# The names R binds to the formal `name` among `formals`: the full name, plus +# every abbreviation of it no other formal claims. `pmatch()` is called on each +# abbreviation alone: on a vector it would match them jointly, as in a call, and +# the exact match would take `name` away from the shorter ones. +names_that_bind_to <- function(name, formals) { + abbreviations <- substring(name, 1, seq_len(nchar(name))) + matched <- vapply(abbreviations, pmatch, integer(1), formals) + abbreviations[matched %in% match(name, formals)] +} + +# Every abbreviation of every name in `names`, the full names included. +all_abbreviations_of <- function(names) { + unique(unlist(lapply(names, function(name) { + substring(name, 1, seq_len(nchar(name))) + }))) +} + +# A regex matching any of the names `x` in full, dots escaped. +regex_exactly_matching_any_of <- function(x) { + paste0("^(", paste(gsub(".", "[.]", x, fixed = TRUE), collapse = "|"), ")$") +} + +# A regex matching the function part of a call to `fn`, bare or `igraph::`. +regex_matching_call_to <- function(fn) { + paste0("^(igraph:::?)?", gsub(".", "[.]", fn, fixed = TRUE), "$") +} + +# The values the template fills in for the rule moving `old_name` to +# `new_name`. +template_values_for_rule <- function(entry, old_name, new_name) { + position <- match(old_name, entry$old) + # Writing the new name over itself would change nothing yet lint forever. + names_to_rewrite <- setdiff(names_that_bind_to(old_name, entry$old), new_name) + # A named argument that may bind to one of the old formals up to `position` + # shifts the unnamed ones, so the positional branches must not fire. + names_blocking_position <- all_abbreviations_of(entry$old[seq_len(position)]) + list( + when = entry$when, + fn = entry$fn, + function_regex = regex_matching_call_to(entry$fn), + old_name = old_name, + new_name = new_name, + names_to_rewrite_regex = if (length(names_to_rewrite)) { + regex_exactly_matching_any_of(names_to_rewrite) + } else { + FALSE + }, + names_blocking_position_regex = regex_exactly_matching_any_of( + names_blocking_position + ), + position = position, + # On the right of a pipe the first formal is filled by the left-hand side. + position_after_pipe = if (position > 1L) position - 1L else FALSE + ) +} + +# The rule file for one registry entry: one rule per old formal that moved +# behind `...`. +render_rule_file <- function(entry, template) { + rules <- Map( + function(old_name, new_name) { + template_values_for_rule(entry, old_name, new_name) + }, + entry$recover_old, + entry$recover_new + ) + for (i in seq_along(rules)) { + rules[[i]]$is_first_rule <- i == 1L + } + whisker::whisker.render(template, list(rules = unname(rules))) +} + +generate_flir_rules <- function(registry_path, out_dir, fns = NULL) { + migrations <- load_migrations(registry_path) + if (length(fns)) { + unknown <- setdiff(fns, names(migrations)) + if (length(unknown)) { + stop("Not in the registry: ", paste(unknown, collapse = ", "), call. = FALSE) + } + migrations <- migrations[fns] + } + template <- paste( + readLines(file.path("tools", "flir-rule.yml.mustache")), + collapse = "\n" + ) + dir.create(out_dir, recursive = TRUE, showWarnings = FALSE) + for (entry in migrations) { + if (!length(entry$recover_old)) { + next + } + path <- file.path( + out_dir, + sprintf("migrate-%s-%s.yml", entry$when, entry$fn) + ) + writeLines(render_rule_file(entry, template), path, sep = "") + message("wrote ", path) + } +} + +if (sys.nframe() == 0L && !interactive()) { + args <- commandArgs(trailingOnly = TRUE) + out_dir <- if (length(args)) args[[1]] else file.path("inst", "flir", "rules") + generate_flir_rules(migration_registry_files(), out_dir, args[-1]) +} From c43d1428b1f5b770b8ad94d1a57255c4681a8d00 Mon Sep 17 00:00:00 2001 From: maelle Date: Fri, 23 Oct 2026 12:52:59 +0000 Subject: [PATCH 02/12] chore: Auto-update from GitHub Actions Run: https://github.com/igraph/rigraph/actions/runs/39955525764 --- tools/generate-flir-rules.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index 8231b5c06b..d4aad8bcf7 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -106,7 +106,11 @@ generate_flir_rules <- function(registry_path, out_dir, fns = NULL) { if (length(fns)) { unknown <- setdiff(fns, names(migrations)) if (length(unknown)) { - stop("Not in the registry: ", paste(unknown, collapse = ", "), call. = FALSE) + stop( + "Not in the registry: ", + paste(unknown, collapse = ", "), + call. = FALSE + ) } migrations <- migrations[fns] } From c3b7521012c104d87e6177edddc6c6f43ec0a2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 23 Oct 2026 14:53:12 +0200 Subject: [PATCH 03/12] custom delimiters --- tools/flir-rule.yml.mustache | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/tools/flir-rule.yml.mustache b/tools/flir-rule.yml.mustache index 9c9f0d970e..27453f4ac9 100644 --- a/tools/flir-rule.yml.mustache +++ b/tools/flir-rule.yml.mustache @@ -1,26 +1,27 @@ -{{#rules}} -{{^is_first_rule}} +{{=<< >>=}} +<<#rules>> +<<^is_first_rule>> --- -{{/is_first_rule}} -id: igraph-{{when}}-{{fn}}-{{old_name}} +<> +id: igraph-<>-<>-<> language: r severity: warning rule: kind: argument has: { field: value, pattern: $V } any: -{{#names_to_rewrite_regex}} +<<#names_to_rewrite_regex>> - # passed by name - has: { field: name, kind: identifier, regex: '{{{names_to_rewrite_regex}}}' } + has: { field: name, kind: identifier, regex: '<<& names_to_rewrite_regex>>' } inside: kind: arguments inside: kind: call - has: { field: function, regex: '{{{function_regex}}}' } -{{/names_to_rewrite_regex}} + has: { field: function, regex: '<<& function_regex>>' } +<> - # passed by position not: { has: { field: name, kind: identifier } } - nthChild: { position: {{position}}, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + nthChild: { position: <>, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } inside: kind: arguments not: @@ -29,20 +30,20 @@ rule: - has: { kind: comma, follows: { regex: '^\($' } } - has: { kind: comma, precedes: { regex: '^\)$' } } - has: { kind: argument, has: { kind: dots } } - - has: { kind: argument, has: { field: name, regex: '{{{names_blocking_position_regex}}}' } } + - has: { kind: argument, has: { field: name, regex: '<<& names_blocking_position_regex>>' } } inside: kind: call - has: { field: function, regex: '{{{function_regex}}}' } + has: { field: function, regex: '<<& function_regex>>' } not: inside: kind: binary_operator field: rhs has: { field: operator, regex: '^(\|>|%>%)$' } not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } -{{#position_after_pipe}} +<<#position_after_pipe>> - # passed by position after a pipe not: { has: { field: name, kind: identifier } } - nthChild: { position: {{position_after_pipe}}, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + nthChild: { position: <>, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } inside: kind: arguments not: @@ -52,15 +53,15 @@ rule: - has: { kind: comma, precedes: { regex: '^\)$' } } - has: { kind: argument, has: { kind: dots } } - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } - - has: { kind: argument, has: { field: name, regex: '{{{names_blocking_position_regex}}}' } } + - has: { kind: argument, has: { field: name, regex: '<<& names_blocking_position_regex>>' } } inside: kind: call - has: { field: function, regex: '{{{function_regex}}}' } + has: { field: function, regex: '<<& function_regex>>' } inside: kind: binary_operator field: rhs has: { field: operator, regex: '^(\|>|%>%)$' } -{{/position_after_pipe}} -fix: {{new_name}} = ~~V~~ -message: igraph {{when}} requires `{{new_name}}` of `{{fn}}()` to be passed by its full name. -{{/rules}} +<> +fix: <> = ~~V~~ +message: igraph <> requires `<>` of `<>()` to be passed by its full name. +<> From f838362d2960942ca298b1a65594a29f76a8c7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Fri, 23 Oct 2026 14:59:40 +0200 Subject: [PATCH 04/12] better names --- tools/flir-rule.yml.mustache | 16 ++++++++-------- tools/generate-flir-rules.R | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/flir-rule.yml.mustache b/tools/flir-rule.yml.mustache index 27453f4ac9..bc208539b0 100644 --- a/tools/flir-rule.yml.mustache +++ b/tools/flir-rule.yml.mustache @@ -10,15 +10,15 @@ rule: kind: argument has: { field: value, pattern: $V } any: -<<#names_to_rewrite_regex>> +<<#regex_matching_old_name_spellings>> - # passed by name - has: { field: name, kind: identifier, regex: '<<& names_to_rewrite_regex>>' } + has: { field: name, kind: identifier, regex: '<<& regex_matching_old_name_spellings>>' } inside: kind: arguments inside: kind: call - has: { field: function, regex: '<<& function_regex>>' } -<> + has: { field: function, regex: '<<& regex_matching_function_name>>' } +<> - # passed by position not: { has: { field: name, kind: identifier } } nthChild: { position: <>, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } @@ -30,10 +30,10 @@ rule: - has: { kind: comma, follows: { regex: '^\($' } } - has: { kind: comma, precedes: { regex: '^\)$' } } - has: { kind: argument, has: { kind: dots } } - - has: { kind: argument, has: { field: name, regex: '<<& names_blocking_position_regex>>' } } + - has: { kind: argument, has: { field: name, regex: '<<& regex_matching_names_blocking_position>>' } } inside: kind: call - has: { field: function, regex: '<<& function_regex>>' } + has: { field: function, regex: '<<& regex_matching_function_name>>' } not: inside: kind: binary_operator @@ -53,10 +53,10 @@ rule: - has: { kind: comma, precedes: { regex: '^\)$' } } - has: { kind: argument, has: { kind: dots } } - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } - - has: { kind: argument, has: { field: name, regex: '<<& names_blocking_position_regex>>' } } + - has: { kind: argument, has: { field: name, regex: '<<& regex_matching_names_blocking_position>>' } } inside: kind: call - has: { field: function, regex: '<<& function_regex>>' } + has: { field: function, regex: '<<& regex_matching_function_name>>' } inside: kind: binary_operator field: rhs diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index d4aad8bcf7..155baff8d1 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -61,22 +61,22 @@ regex_matching_call_to <- function(fn) { template_values_for_rule <- function(entry, old_name, new_name) { position <- match(old_name, entry$old) # Writing the new name over itself would change nothing yet lint forever. - names_to_rewrite <- setdiff(names_that_bind_to(old_name, entry$old), new_name) + old_name_spellings <- setdiff(names_that_bind_to(old_name, entry$old), new_name) # A named argument that may bind to one of the old formals up to `position` # shifts the unnamed ones, so the positional branches must not fire. names_blocking_position <- all_abbreviations_of(entry$old[seq_len(position)]) list( when = entry$when, fn = entry$fn, - function_regex = regex_matching_call_to(entry$fn), + regex_matching_function_name = regex_matching_call_to(entry$fn), old_name = old_name, new_name = new_name, - names_to_rewrite_regex = if (length(names_to_rewrite)) { - regex_exactly_matching_any_of(names_to_rewrite) + regex_matching_old_name_spellings = if (length(old_name_spellings)) { + regex_exactly_matching_any_of(old_name_spellings) } else { FALSE }, - names_blocking_position_regex = regex_exactly_matching_any_of( + regex_matching_names_blocking_position = regex_exactly_matching_any_of( names_blocking_position ), position = position, From c80b77b59f9049285c64aaf545be215e6467debe Mon Sep 17 00:00:00 2001 From: maelle Date: Fri, 23 Oct 2026 14:54:31 +0000 Subject: [PATCH 05/12] chore: Auto-update from GitHub Actions Run: https://github.com/igraph/rigraph/actions/runs/39957587362 --- tools/generate-flir-rules.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index 155baff8d1..ac7bcf848c 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -61,7 +61,10 @@ regex_matching_call_to <- function(fn) { template_values_for_rule <- function(entry, old_name, new_name) { position <- match(old_name, entry$old) # Writing the new name over itself would change nothing yet lint forever. - old_name_spellings <- setdiff(names_that_bind_to(old_name, entry$old), new_name) + old_name_spellings <- setdiff( + names_that_bind_to(old_name, entry$old), + new_name + ) # A named argument that may bind to one of the old formals up to `position` # shifts the unnamed ones, so the positional branches must not fire. names_blocking_position <- all_abbreviations_of(entry$old[seq_len(position)]) From f4200e013c6b51f44f2c4518379c88a70bef3ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 11:41:12 +0100 Subject: [PATCH 06/12] add explanation --- tools/flir-rule.yml.mustache | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/flir-rule.yml.mustache b/tools/flir-rule.yml.mustache index bc208539b0..5a139c5246 100644 --- a/tools/flir-rule.yml.mustache +++ b/tools/flir-rule.yml.mustache @@ -1,4 +1,10 @@ {{=<< >>=}} +<> <<#rules>> <<^is_first_rule>> --- From 903a1d5336241cfbf1974dcfad803f6f511104bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 11:46:02 +0100 Subject: [PATCH 07/12] clarify --- tools/generate-flir-rules.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index ac7bcf848c..a39a1dbc52 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -13,8 +13,23 @@ # of `%>%` without a `.` placeholder. # # The positional cases only fire when the binding is decidable from syntax: no -# named argument that could take one of the old formals 1..k, no empty slot, no -# `...`. Every other call is left to the runtime recovery. See +# named argument that could take one of the old formals 1..k (k being the +# position of the rule's formal in `old`), no empty slot, no `...`. Take the rule +# for `mode` of `degree()`, whose old formals were `graph, v, mode, loops, +# normalized`: `mode` comes third, so k = 3, and the rule looks for the argument +# R binds to `mode` as the third unnamed one. None of these calls lets it say +# which one that is: +# +# - `degree(g, v = 1:3, "out", TRUE)`: the third unnamed argument is `TRUE`, +# but `v =` takes the second formal, so `mode` gets `"out"` and `TRUE` goes +# to `loops`; +# - `degree(g, , "out")`: `mode` gets `"out"`, though `"out"` is only the +# second unnamed argument written, because the empty slot stands for `v`; +# - `degree(g, ..., "out")`, inside a wrapper: how many arguments `...` holds +# is only known at run time: with none, `"out"` goes to `v`; with one, +# `mode` gets `"out"`; with two or more, `mode` gets one of them. +# +# Every other call is left to the runtime recovery. See # https://github.com/igraph/rigraph/issues/2933. # # Usage: From 7943fc23e7d39cbca347ae501977421aeba4e6a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 12:21:50 +0100 Subject: [PATCH 08/12] clarify --- tools/generate-flir-rules.R | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index a39a1dbc52..ddbab73b8a 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -14,11 +14,11 @@ # # The positional cases only fire when the binding is decidable from syntax: no # named argument that could take one of the old formals 1..k (k being the -# position of the rule's formal in `old`), no empty slot, no `...`. Take the rule -# for `mode` of `degree()`, whose old formals were `graph, v, mode, loops, -# normalized`: `mode` comes third, so k = 3, and the rule looks for the argument -# R binds to `mode` as the third unnamed one. None of these calls lets it say -# which one that is: +# position of the rule's formal in `old`), no empty slot, no `...`. Take the +# rule for `mode` of `degree()`, whose old formals were `graph, v, mode, loops, +# normalized`: `mode` comes third, so k = 3, and the rule looks for the +# argument R binds to `mode` as the third unnamed one. None of these calls lets +# it say which one that is: # # - `degree(g, v = 1:3, "out", TRUE)`: the third unnamed argument is `TRUE`, # but `v =` takes the second formal, so `mode` gets `"out"` and `TRUE` goes @@ -45,13 +45,19 @@ source(file.path("tools", "generate-migrations.R")) # The names R binds to the formal `name` among `formals`: the full name, plus -# every abbreviation of it no other formal claims. `pmatch()` is called on each -# abbreviation alone: on a vector it would match them jointly, as in a call, and -# the exact match would take `name` away from the shorter ones. +# every abbreviation of it no other formal claims. `duplicates.ok = TRUE` makes +# `pmatch()` match each abbreviation on its own: by default it would match them +# jointly, as in a call, and the exact match would take `name` away from the +# shorter ones. For `mode` of `degree()`: +# +# formals <- c("graph", "v", "mode", "loops", "normalized") +# abbreviations <- c("m", "mo", "mod", "mode") +# pmatch(abbreviations, formals) # NA NA NA 3 +# pmatch(abbreviations, formals, duplicates.ok = TRUE) # 3 3 3 3 names_that_bind_to <- function(name, formals) { abbreviations <- substring(name, 1, seq_len(nchar(name))) - matched <- vapply(abbreviations, pmatch, integer(1), formals) - abbreviations[matched %in% match(name, formals)] + bound_to_formal <- pmatch(abbreviations, formals, duplicates.ok = TRUE) + abbreviations[bound_to_formal %in% match(name, formals)] } # Every abbreviation of every name in `names`, the full names included. From 47f51f162bc89e482df8f6afdafbca4360a4ac1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 12:33:21 +0100 Subject: [PATCH 09/12] use function --- tools/generate-flir-rules.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index ddbab73b8a..96557569aa 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -54,8 +54,16 @@ source(file.path("tools", "generate-migrations.R")) # abbreviations <- c("m", "mo", "mod", "mode") # pmatch(abbreviations, formals) # NA NA NA 3 # pmatch(abbreviations, formals, duplicates.ok = TRUE) # 3 3 3 3 +# +# For `clique_size_counts()`, whose old formals share prefixes, `m` and `ma` +# are ambiguous and are left out: +# +# formals <- c("graph", "min", "max", "maximal") +# names_that_bind_to("min", formals) # "mi" "min" +# names_that_bind_to("max", formals) # "max" +# names_that_bind_to("maximal", formals) # "maxi" "maxim" "maxima" "maximal" names_that_bind_to <- function(name, formals) { - abbreviations <- substring(name, 1, seq_len(nchar(name))) + abbreviations <- all_abbreviations_of(name) bound_to_formal <- pmatch(abbreviations, formals, duplicates.ok = TRUE) abbreviations[bound_to_formal %in% match(name, formals)] } From ad4b33b51d0ec64b586718bce593f72408dfc443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 12:48:07 +0100 Subject: [PATCH 10/12] example --- tools/generate-flir-rules.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/generate-flir-rules.R b/tools/generate-flir-rules.R index 96557569aa..13effb3540 100644 --- a/tools/generate-flir-rules.R +++ b/tools/generate-flir-rules.R @@ -95,7 +95,14 @@ template_values_for_rule <- function(entry, old_name, new_name) { new_name ) # A named argument that may bind to one of the old formals up to `position` - # shifts the unnamed ones, so the positional branches must not fire. + # shifts the unnamed ones, so the positional branches must not fire. For + # `mode` of `degree()`, in third position: in `degree(g, v = 1:3, "out")`, + # `"out"` binds to `mode` though it is only the second unnamed argument. + # Any spelling of `graph`, `v` or `mode` blocks: + # + # old <- c("graph", "v", "mode", "loops", "normalized") + # all_abbreviations_of(old[seq_len(3)]) + # # "g" "gr" "gra" "grap" "graph" "v" "m" "mo" "mod" "mode" names_blocking_position <- all_abbreviations_of(entry$old[seq_len(position)]) list( when = entry$when, From d7a49310b6e1483d0ec70fdeda4fb206d72d6dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 12:59:35 +0100 Subject: [PATCH 11/12] add examples --- tools/flir-demo/README.md | 29 +++ tools/flir-demo/calls.R | 49 +++++ .../migrate-3.0.0-clique_size_counts.yml | 166 +++++++++++++++++ .../flir-demo/rules/migrate-3.0.0-degree.yml | 173 ++++++++++++++++++ .../rules/migrate-3.0.0-sample_gnp.yml | 115 ++++++++++++ .../rules/migrate-3.0.0-simplify.yml | 57 ++++++ 6 files changed, 589 insertions(+) create mode 100644 tools/flir-demo/README.md create mode 100644 tools/flir-demo/calls.R create mode 100644 tools/flir-demo/rules/migrate-3.0.0-clique_size_counts.yml create mode 100644 tools/flir-demo/rules/migrate-3.0.0-degree.yml create mode 100644 tools/flir-demo/rules/migrate-3.0.0-sample_gnp.yml create mode 100644 tools/flir-demo/rules/migrate-3.0.0-simplify.yml diff --git a/tools/flir-demo/README.md b/tools/flir-demo/README.md new file mode 100644 index 0000000000..caf2d90f45 --- /dev/null +++ b/tools/flir-demo/README.md @@ -0,0 +1,29 @@ +# flir migration rules on sample calls + +*Handbook: [`architecture/r-layer/conventions/`](/handbook/architecture/r-layer/conventions/README.md) is the node this folder serves.* + +`calls.R` holds old-style calls to `degree()`, `sample_gnp()`, `simplify()` and `clique_size_counts()`, +each with a comment saying what the rules should do with it. +`rules/` holds the rules `tools/generate-flir-rules.R` writes for those four functions. + +To see the rules at work, rewrite `calls.R` in place from the repository root and read the diff: + +```r +flir::fix( + "tools/flir-demo/calls.R", + linters = list.files("tools/flir-demo/rules", full.names = TRUE) +) +``` + +```sh +git diff tools/flir-demo/calls.R +git checkout tools/flir-demo/calls.R +``` + +`flir::lint()` with the same arguments lists the matches without changing the file. + +After a change to the generator or its template, regenerate the rules before running flir again: + +```sh +Rscript tools/generate-flir-rules.R tools/flir-demo/rules degree sample_gnp simplify clique_size_counts +``` diff --git a/tools/flir-demo/calls.R b/tools/flir-demo/calls.R new file mode 100644 index 0000000000..0e624e4217 --- /dev/null +++ b/tools/flir-demo/calls.R @@ -0,0 +1,49 @@ +# Old-style calls to igraph functions whose arguments moved behind `...` in +# igraph 3.0.0. Each comment says what the rules should do with the call. + +library(igraph) +library(magrittr) + +g <- make_ring(10) + +# degree(): old formals graph, v, mode, loops, normalized + +# by position: mode, loops and normalized all get named +degree(g, V(g), "out", FALSE, TRUE) +# by position, only mode +degree(g, 1:3, "in") +# by an abbreviation of the old name +degree(g, mo = "out", lo = FALSE) +# already new style: left alone +degree(g, mode = "out") +# piped: the graph comes from the left-hand side +g |> degree(V(g), "out") +g %>% degree(V(g), "out") +# magrittr with a `.` placeholder: the graph is not first, so positions are +# as written +g %>% degree(., V(.), "out") + +# Left to the runtime recovery, not rewritten by position: +# a named argument shifts the unnamed ones +degree(g, v = 1:3, "out", TRUE) +# an empty slot +degree(g, , "out") +# `...` of a wrapper +my_degree <- function(...) degree(g, ..., "out") + +# sample_gnp(): old formals n, p, directed, loops +sample_gnp(10, 0.2, TRUE, FALSE) +sample_gnp(10, 0.2, dir = TRUE) + +# simplify(): old formals graph, remove.multiple, remove.loops, edge.attr.comb +# edge.attr.comb is renamed edge_attr_combine +simplify(g, TRUE, TRUE, "first") +simplify(g, edge.attr.comb = "sum") +igraph::simplify(g, edge.attr = "sum") + +# clique_size_counts(): old formals graph, min, max, maximal +clique_size_counts(g, 2, 4, TRUE) +# `mi` binds to min, `max` to max, `maxi` to maximal +clique_size_counts(g, mi = 2, max = 4, maxi = TRUE) +# `ma` is ambiguous between max and maximal: an error in R, left alone +clique_size_counts(g, ma = 4) diff --git a/tools/flir-demo/rules/migrate-3.0.0-clique_size_counts.yml b/tools/flir-demo/rules/migrate-3.0.0-clique_size_counts.yml new file mode 100644 index 0000000000..007c90262f --- /dev/null +++ b/tools/flir-demo/rules/migrate-3.0.0-clique_size_counts.yml @@ -0,0 +1,166 @@ +id: igraph-3.0.0-clique_size_counts-min +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(mi)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 2, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|m|mi|min)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 1, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|m|mi|min)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: min = ~~V~~ +message: igraph 3.0.0 requires `min` of `clique_size_counts()` to be passed by its full name. +--- +id: igraph-3.0.0-clique_size_counts-max +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|m|mi|min|ma|max)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 2, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|m|mi|min|ma|max)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: max = ~~V~~ +message: igraph 3.0.0 requires `max` of `clique_size_counts()` to be passed by its full name. +--- +id: igraph-3.0.0-clique_size_counts-maximal +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(maxi|maxim|maxima)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 4, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|m|mi|min|ma|max|maxi|maxim|maxima|maximal)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|m|mi|min|ma|max|maxi|maxim|maxima|maximal)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?clique_size_counts$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: maximal = ~~V~~ +message: igraph 3.0.0 requires `maximal` of `clique_size_counts()` to be passed by its full name. diff --git a/tools/flir-demo/rules/migrate-3.0.0-degree.yml b/tools/flir-demo/rules/migrate-3.0.0-degree.yml new file mode 100644 index 0000000000..56471f0e41 --- /dev/null +++ b/tools/flir-demo/rules/migrate-3.0.0-degree.yml @@ -0,0 +1,173 @@ +id: igraph-3.0.0-degree-mode +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(m|mo|mod)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|v|m|mo|mod|mode)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 2, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|v|m|mo|mod|mode)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: mode = ~~V~~ +message: igraph 3.0.0 requires `mode` of `degree()` to be passed by its full name. +--- +id: igraph-3.0.0-degree-loops +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(l|lo|loo|loop)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 4, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|v|m|mo|mod|mode|l|lo|loo|loop|loops)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|v|m|mo|mod|mode|l|lo|loo|loop|loops)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: loops = ~~V~~ +message: igraph 3.0.0 requires `loops` of `degree()` to be passed by its full name. +--- +id: igraph-3.0.0-degree-normalized +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(n|no|nor|norm|norma|normal|normali|normaliz|normalize)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 5, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|v|m|mo|mod|mode|l|lo|loo|loop|loops|n|no|nor|norm|norma|normal|normali|normaliz|normalize|normalized)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 4, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|v|m|mo|mod|mode|l|lo|loo|loop|loops|n|no|nor|norm|norma|normal|normali|normaliz|normalize|normalized)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?degree$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: normalized = ~~V~~ +message: igraph 3.0.0 requires `normalized` of `degree()` to be passed by its full name. diff --git a/tools/flir-demo/rules/migrate-3.0.0-sample_gnp.yml b/tools/flir-demo/rules/migrate-3.0.0-sample_gnp.yml new file mode 100644 index 0000000000..1c6dfa6a91 --- /dev/null +++ b/tools/flir-demo/rules/migrate-3.0.0-sample_gnp.yml @@ -0,0 +1,115 @@ +id: igraph-3.0.0-sample_gnp-directed +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(d|di|dir|dire|direc|direct|directe)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?sample_gnp$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(n|p|d|di|dir|dire|direc|direct|directe|directed)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?sample_gnp$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 2, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(n|p|d|di|dir|dire|direc|direct|directe|directed)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?sample_gnp$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: directed = ~~V~~ +message: igraph 3.0.0 requires `directed` of `sample_gnp()` to be passed by its full name. +--- +id: igraph-3.0.0-sample_gnp-loops +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(l|lo|loo|loop)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?sample_gnp$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 4, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(n|p|d|di|dir|dire|direc|direct|directe|directed|l|lo|loo|loop|loops)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?sample_gnp$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(n|p|d|di|dir|dire|direc|direct|directe|directed|l|lo|loo|loop|loops)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?sample_gnp$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: loops = ~~V~~ +message: igraph 3.0.0 requires `loops` of `sample_gnp()` to be passed by its full name. diff --git a/tools/flir-demo/rules/migrate-3.0.0-simplify.yml b/tools/flir-demo/rules/migrate-3.0.0-simplify.yml new file mode 100644 index 0000000000..86865b9886 --- /dev/null +++ b/tools/flir-demo/rules/migrate-3.0.0-simplify.yml @@ -0,0 +1,57 @@ +id: igraph-3.0.0-simplify-edge.attr.comb +language: r +severity: warning +rule: + kind: argument + has: { field: value, pattern: $V } + any: + - # passed by name + has: { field: name, kind: identifier, regex: '^(e|ed|edg|edge|edge[.]|edge[.]a|edge[.]at|edge[.]att|edge[.]attr|edge[.]attr[.]|edge[.]attr[.]c|edge[.]attr[.]co|edge[.]attr[.]com|edge[.]attr[.]comb)$' } + inside: + kind: arguments + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?simplify$' } + - # passed by position + not: { has: { field: name, kind: identifier } } + nthChild: { position: 4, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|r|re|rem|remo|remov|remove|remove[.]|remove[.]m|remove[.]mu|remove[.]mul|remove[.]mult|remove[.]multi|remove[.]multip|remove[.]multipl|remove[.]multiple|remove[.]l|remove[.]lo|remove[.]loo|remove[.]loop|remove[.]loops|e|ed|edg|edge|edge[.]|edge[.]a|edge[.]at|edge[.]att|edge[.]attr|edge[.]attr[.]|edge[.]attr[.]c|edge[.]attr[.]co|edge[.]attr[.]com|edge[.]attr[.]comb)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?simplify$' } + not: + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } + not: { has: { field: rhs, kind: call, has: { kind: arguments, has: { kind: argument, has: { field: value, kind: identifier, regex: '^[.]$' } } } } } + - # passed by position after a pipe + not: { has: { field: name, kind: identifier } } + nthChild: { position: 3, ofRule: { kind: argument, not: { has: { field: name, kind: identifier } } } } + inside: + kind: arguments + not: + any: + - has: { kind: comma, follows: { kind: comma } } + - has: { kind: comma, follows: { regex: '^\($' } } + - has: { kind: comma, precedes: { regex: '^\)$' } } + - has: { kind: argument, has: { kind: dots } } + - has: { kind: argument, has: { field: value, kind: identifier, regex: '^[._]$' } } + - has: { kind: argument, has: { field: name, regex: '^(g|gr|gra|grap|graph|r|re|rem|remo|remov|remove|remove[.]|remove[.]m|remove[.]mu|remove[.]mul|remove[.]mult|remove[.]multi|remove[.]multip|remove[.]multipl|remove[.]multiple|remove[.]l|remove[.]lo|remove[.]loo|remove[.]loop|remove[.]loops|e|ed|edg|edge|edge[.]|edge[.]a|edge[.]at|edge[.]att|edge[.]attr|edge[.]attr[.]|edge[.]attr[.]c|edge[.]attr[.]co|edge[.]attr[.]com|edge[.]attr[.]comb)$' } } + inside: + kind: call + has: { field: function, regex: '^(igraph:::?)?simplify$' } + inside: + kind: binary_operator + field: rhs + has: { field: operator, regex: '^(\|>|%>%)$' } +fix: edge_attr_combine = ~~V~~ +message: igraph 3.0.0 requires `edge_attr_combine` of `simplify()` to be passed by its full name. From 1b70f7161402f6210b06bd8338fb97bc7b701a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 3 Nov 2026 13:36:03 +0100 Subject: [PATCH 12/12] show example --- tools/flir-demo/calls.R | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/flir-demo/calls.R b/tools/flir-demo/calls.R index 0e624e4217..82e8585f8c 100644 --- a/tools/flir-demo/calls.R +++ b/tools/flir-demo/calls.R @@ -9,19 +9,19 @@ g <- make_ring(10) # degree(): old formals graph, v, mode, loops, normalized # by position: mode, loops and normalized all get named -degree(g, V(g), "out", FALSE, TRUE) +degree(g, V(g), mode = "out", loops = FALSE, normalized = TRUE) # by position, only mode -degree(g, 1:3, "in") +degree(g, 1:3, mode = "in") # by an abbreviation of the old name -degree(g, mo = "out", lo = FALSE) +degree(g, mode = "out", loops = FALSE) # already new style: left alone degree(g, mode = "out") # piped: the graph comes from the left-hand side -g |> degree(V(g), "out") -g %>% degree(V(g), "out") +g |> degree(V(g), mode = "out") +g %>% degree(V(g), mode = "out") # magrittr with a `.` placeholder: the graph is not first, so positions are # as written -g %>% degree(., V(.), "out") +g %>% degree(., V(.), mode = "out") # Left to the runtime recovery, not rewritten by position: # a named argument shifts the unnamed ones @@ -32,18 +32,18 @@ degree(g, , "out") my_degree <- function(...) degree(g, ..., "out") # sample_gnp(): old formals n, p, directed, loops -sample_gnp(10, 0.2, TRUE, FALSE) -sample_gnp(10, 0.2, dir = TRUE) +sample_gnp(10, 0.2, directed = TRUE, loops = FALSE) +sample_gnp(10, 0.2, directed = TRUE) # simplify(): old formals graph, remove.multiple, remove.loops, edge.attr.comb # edge.attr.comb is renamed edge_attr_combine -simplify(g, TRUE, TRUE, "first") -simplify(g, edge.attr.comb = "sum") -igraph::simplify(g, edge.attr = "sum") +simplify(g, TRUE, TRUE, edge_attr_combine = "first") +simplify(g, edge_attr_combine = "sum") +igraph::simplify(g, edge_attr_combine = "sum") # clique_size_counts(): old formals graph, min, max, maximal -clique_size_counts(g, 2, 4, TRUE) +clique_size_counts(g, min = 2, max = 4, maximal = TRUE) # `mi` binds to min, `max` to max, `maxi` to maximal -clique_size_counts(g, mi = 2, max = 4, maxi = TRUE) +clique_size_counts(g, min = 2, max = 4, maximal = TRUE) # `ma` is ambiguous between max and maximal: an error in R, left alone clique_size_counts(g, ma = 4)