-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New linter for complex conditional expressions #2676
base: main
Are you sure you want to change the base?
Conversation
I don't think I'm more comfortable calling Defining the metric for "complexity" here is going to be quite hard -- are there other languages that have implemented something similar, or is there some CS literature we can turn to for some more generic definitions? |
You are correct that this is a difficult question, but I don't think we need to have a consensus definition of what counts as "complex" conditional because that's an inherently subjective notion. The only thing we need to figure out is a good default (the same way we did for cyclocomp linter). And, since this is a configurable linter, even if we adopt a threshold that users feel is too restrictive, they can easily change this in config. I think the current default of lint(
text = "if (a && b || c) NULL",
linters = complex_conditional_linter(2)
)
#> ℹ No lints found. So the question for us to resolve is what should be the default threshold? I would vote for Here is an example from our codebase: if (inherits(e, "lint") && (is.na(e$line) || !nzchar(e$line) || e$message == "unexpected end of input")) {
...
} which lints with this new linter and can be modified something along these lines: is_expression_valid <- (is.na(e$line) || !nzchar(e$line) || e$message == "unexpected end of input")
if (inherits(e, "lint") && is_expression_valid) {
...
} P.S. As for linters in other programming languages, I can't think of any (neither |
I don't understand why the |
What happens when you run From my understanding the script replaces all line numbers by 2^31 - 1 during --- edit: Ah, the file name is the problem. Rename the test file and it should work. |
@AshesITR Thanks!! That was it. Changing the filename fixed the issue. |
closes #1830
Draft PR for early feedback.
Examples
Created on 2024-11-01 with reprex v2.1.1