There is an annotation to disable the “snake case” lint:
#[allow(non_snake_case)]
fn FunnyFunctionName(){
let Y = 2.4;
...
}
but that is a little crude in it’s application. (It is invalid, for example, to use the annotation directly on a local variable within the function.)
Proposal
Add two new annotations, non_snake_case_fn
, non_snake_case_var
(or even three: non_snake_case_fn
, non_snake_case_let
, non_snake_case_param
). These can be used to turn off the “snake case” lint (or lints) in specific cases.
Motivation
In a few cases I find it reasonable to use non-snake-case names: when copying equations from a scientific/mathematical article (sometimes referencing an external work is much easier than documenting everything in the code), when using acronyms (in this case it’s debatable whether or not the acronyms should be converted to lower case). And sometimes odd other cases (though mostly temporary).
Usually, however, these are localised exceptions from the norm, and I’d like to use standard names elsewhere, hence #[allow(non_snake_case)]
is a bit of a blunt tool.
Examples
Use of an acronym in a function name:
[#allow(non_snake_case_fn)]
fn special_func_ABC(...) {...}
I’m not even sure if the above should be allowed by default (so long as the first letter is lower-case and every capital letter follows an underscore or another capital letter).
A function using more mathematical syntax for variable names:
[#allow(non_snake_case_var)]
fn compute(x: f64) -> f64 {
let X1 = ...;
let a = ...;
let Z = ...;
...
}
Alternatives
The status quo: all or nothing (apply [#allow(non_snake_case)]
at the function/module/project level).