You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix and disallow all snake_case style warnings #25531
C-assignedThere is someone working on resolving the issueE-less-complexStraightforward. Recommended for a new contributor.I-cleanupNo impact; the issue is one of maintainability or tidiness.
How should I translate camelCase methods (of webidl) to snake_case? I found js_name attribute in wasm-bindgen (#[wasm_bindgen(js_name = jsOftenUsesCamelCase)]). Is there some other way, maybe specific to servo that I am missing out?
That must be why ignore_snake_case was on in the first place. Maybe we want just the autogenerated method names from the webidl to be exempt from this, somehow?
error: an inner attribute is not permitted in this context
--> /mnt/sda1/Documents/webpages/rust/servo/target/debug/build/script-34e34b4c91111f3b/out/RegisterBindings.rs:1:1
|
1 | #![allow(non_snake_case)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
error: an inner attribute is not permitted in this context
--> /mnt/sda1/Documents/webpages/rust/servo/target/debug/build/script-34e34b4c91111f3b/out/UnionTypes.rs:3:1
|
3 | #![allow(non_snake_case)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.
warning: method `Constructor` should have a snake case name
--> components/script/dom/audiobuffer.rs:93:12
|
93 | pub fn Constructor(
| ^^^^^^^^^^^ help: convert the identifier to snake case (notice the capitalization): `constructor`
warning: variable `txPower` should have a snake case name
--> components/script/dom/bluetoothadvertisingevent.rs:59:9
|
59 | txPower: Option<i8>,
| ^^^^^^^ help: convert the identifier to snake case: `tx_power`
txPower actually should have a snake case name, and tx_power is the correct suggestion, if I understand Servo's style correctly. Constructor's a word the codegen is putting in a trait, so it should probably be exempt?
Yes, I think so too. There are a large number of variables and functions that come under the warnings. I guess most of the variables` names need to be changed whereas the functions are put in by the codegen and should be exempt.
I can't figure out where the actual Constructor name comes from in the code generator, so go ahead and add #[allow(non_snake_case)] for each instance.
Only for the constructors? (because there are hundreds of warnings, constructors alone are more than a hundred I guess 😅 )
(I'll probably have to write a script to do so)
For non-constructor methods of traits, you can probably add #[allow(non_snake_case)] right before the impl FooMethods for Foo to avoid lots of those warnings.
C-assignedThere is someone working on resolving the issueE-less-complexStraightforward. Recommended for a new contributor.I-cleanupNo impact; the issue is one of maintainability or tidiness.
Activity
highfive commentedon Jan 15, 2020
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the
#servochannel in IRC.If you intend to work on this issue, then add
@highfive: assign meto your comment, and I'll assign this to you. 😄kunalmohan commentedon Jan 15, 2020
@highfive: assign me
highfive commentedon Jan 15, 2020
Hey @kunalmohan! Thanks for your interest in working on this issue. It's now assigned to you!
kunalmohan commentedon Jan 16, 2020
How should I translate camelCase methods (of webidl) to snake_case? I found
js_nameattribute inwasm-bindgen(#[wasm_bindgen(js_name = jsOftenUsesCamelCase)]). Is there some other way, maybe specific to servo that I am missing out?pshaughn commentedon Jan 16, 2020
That must be why ignore_snake_case was on in the first place. Maybe we want just the autogenerated method names from the webidl to be exempt from this, somehow?
jdm commentedon Jan 16, 2020
Yes, we can apply that attribute to specific modules or trait implementations when necessary, I suppose. We can start by making use of the
ignored_warningsargument toCGImportsin CodegenRust.py - try adding it to the list in https://github.com/servo/servo/blob/master/components/script/dom/bindings/codegen/CodegenRust.py#L1958, and then for any generated files still causing trouble look for uses likeservo/components/script/dom/bindings/codegen/CodegenRust.py
Line 2465 in 90b0a7f
kunalmohan commentedon Jan 17, 2020
Adding
'non_snake_case'to the listservo/components/script/dom/bindings/codegen/CodegenRust.py
Lines 1958 to 1965 in 1de9290
doesn't seem to reduce any warnings.
Adding it to
servo/components/script/dom/bindings/codegen/CodegenRust.py
Line 2473 in 1de9290
and
servo/components/script/dom/bindings/codegen/CodegenRust.py
Line 7564 in 1de9290
gave the respective errors-
jdm commentedon Jan 17, 2020
Can you give a few examples of some of the warnings?
jdm commentedon Jan 17, 2020
One other possibility is changing this line to
self.cgRoot = CGList(CGGeneric('#![allow(non_snake_case)]'), cgThings)kunalmohan commentedon Jan 17, 2020
pshaughn commentedon Jan 17, 2020
txPower actually should have a snake case name, and tx_power is the correct suggestion, if I understand Servo's style correctly. Constructor's a word the codegen is putting in a trait, so it should probably be exempt?
kunalmohan commentedon Jan 17, 2020
Yes, I think so too. There are a large number of variables and functions that come under the warnings. I guess most of the variables` names need to be changed whereas the functions are put in by the codegen and should be exempt.
jdm commentedon Jan 17, 2020
I can't figure out where the actual
Constructorname comes from in the code generator, so go ahead and add#[allow(non_snake_case)]for each instance.kunalmohan commentedon Jan 17, 2020
This isn't working: python
TypeError(I guess, because of the if block which changes cgThings type)servo/components/script/dom/bindings/codegen/CodegenRust.py
Lines 6335 to 6344 in 1de9290
So I tried
which again gave the error
error: an inner attribute is not permitted in this contextkunalmohan commentedon Jan 17, 2020
Only for the constructors? (because there are hundreds of warnings, constructors alone are more than a hundred I guess 😅 )
(I'll probably have to write a script to do so)
jdm commentedon Jan 17, 2020
For non-constructor methods of traits, you can probably add
#[allow(non_snake_case)]right before theimpl FooMethods for Footo avoid lots of those warnings.Auto merge of #25547 - kunalmohan:25531-SnakeCase, r=jdm
Auto merge of #25547 - kunalmohan:25531-SnakeCase, r=jdm
Auto merge of #25547 - kunalmohan:25531-SnakeCase, r=jdm
Auto merge of #25547 - kunalmohan:25531-SnakeCase, r=jdm
Auto merge of #25547 - kunalmohan:25531-SnakeCase, r=jdm