Closed coriolinus closed 5 years ago
Nice suggestion! This is more or less how I planned to expand the reverse-string analyzer, just need to learn how to effectively traverse syn
AST.
Also I would try to avoid mutable AnalysisOutput
and use builder pattern with every build function as a separate lint, but these are details.
just need to learn how to effectively traverse syn AST.
Looks pretty straightforward: just iterate through the File.items
. Detecting whether there are use
statements could be done like
let has_use = file.items.iter().any(|item| if let Item::Use(_) = item) { true } else { false});
I would try to avoid mutable AnalysisOutput and use builder pattern
Up to you. I think that in this case, using a mutable AnalysisOutput
will result in less code, which is therefore easier to read and write, but I agree that it's a detail up to the implementer.
Thanks, will look into it later tonight
The analyzer currently matches full ASTs:
https://github.com/exercism/rust-analyzer/blob/004154cad987142a227a54fb9e3f86bc0de4ec1d/src/analyzers/reverse_string/mod.rs#L53-L64
This works, but is inflexible: it is currently impossible to suggest both implementing the bonus test and also removing
use
statements. We could refactor for greater flexibility by writing this more like a linter.Detailed proposal:
LINTS: Vec<dyn Fn(&File, &mut AnalysisOutput) -> Result<()>>
Populate this list with functions which look for particular features of the input file. For example:
use
statements, and add a suggestion that those aren't necessary in Rust 2018unicode_segmentation
crate, and suggest that this would be an easy way to implement the bonus featurereverse
function (ignoring the variable name) with the ideal output, and approve if it is optimalThese functions have the option to return an error, aborting the parse, but generally they should be OK.
Analyze
implementation such that by default, it has a basic "refer to mentor" output. Every lint in theLINTS
list is run, possibly modifying the output. If any lint returns anErr
, the break out of the lints iteration and return an appropriate error.AnalysisOutput
.PreparedOutput
stuff, which should no longer be needed or used.I believe that this architecture would be sufficient to close #5.