Skip to content
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

Fix and disallow all snake_case style warnings #25531

Closed
jdm opened this issue Jan 15, 2020 · 16 comments
Closed

Fix and disallow all snake_case style warnings #25531

jdm opened this issue Jan 15, 2020 · 16 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Jan 15, 2020

https://github.com/servo/servo/blame/5c7a4db5f4e374dee287d403d90c7bc0e07ac9d0/components/script/lib.rs#L12 was added several years ago. We should remove it and fix the existing violations that have been added to the code in that time.

@highfive
Copy link

@highfive highfive commented Jan 15, 2020

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jan 15, 2020

@highfive: assign me

@highfive highfive added the C-assigned label Jan 15, 2020
@highfive
Copy link

@highfive highfive commented Jan 15, 2020

Hey @kunalmohan! Thanks for your interest in working on this issue. It's now assigned to you!

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jan 16, 2020

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?

@pshaughn
Copy link
Member

@pshaughn pshaughn commented 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
Copy link
Member Author

@jdm jdm commented 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_warnings argument to CGImports in 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 like

return CGImports(CGList(unionStructs, "\n\n"),
and add it if necessary.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jan 17, 2020

Adding 'non_snake_case' to the list

ignored_warnings = [
'non_camel_case_types',
'non_upper_case_globals',
'unused_imports',
'unused_variables',
'unused_assignments',
'unused_mut',
]

doesn't seem to reduce any warnings.
Adding it to

and
], config=config, ignored_warnings=[])

gave the respective errors-

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.
@jdm
Copy link
Member Author

@jdm jdm commented Jan 17, 2020

Can you give a few examples of some of the warnings?

@jdm
Copy link
Member Author

@jdm jdm commented Jan 17, 2020

One other possibility is changing this line to self.cgRoot = CGList(CGGeneric('#![allow(non_snake_case)]'), cgThings)

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jan 17, 2020

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`
@pshaughn
Copy link
Member

@pshaughn pshaughn commented 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
Copy link
Collaborator

@kunalmohan kunalmohan commented 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
Copy link
Member Author

@jdm jdm commented Jan 17, 2020

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.

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jan 17, 2020

One other possibility is changing this line to self.cgRoot = CGList(CGGeneric('#![allow(non_snake_case)]'), cgThings)

This isn't working: python TypeError (I guess, because of the if block which changes cgThings type)

cgThings = CGWrapper(CGNamespace(toBindingNamespace(descriptor.name),
cgThings, public=True),
post='\n')
if reexports:
reexports = ', '.join(map(lambda name: reexportedName(name), reexports))
cgThings = CGList([CGGeneric('pub use self::%s::{%s};' % (toBindingNamespace(descriptor.name), reexports)),
cgThings], '\n')
self.cgRoot = cgThings

So I tried

if reexports:
            reexports = ', '.join(map(lambda name: reexportedName(name), reexports))
            cgThings = CGList([CGGeneric('#![allow(non_snake_case)]'), CGGeneric('pub use self::%s::{%s};' % (toBindingNamespace(descriptor.name), reexports)),
                               cgThings], '\n')
        else:
            cgThings = CGList([CGGeneric('#![allow(non_snake_case)]'), cgThings], '\n')

        self.cgRoot = cgThings

which again gave the error error: an inner attribute is not permitted in this context

@kunalmohan
Copy link
Collaborator

@kunalmohan kunalmohan commented Jan 17, 2020

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)

@jdm
Copy link
Member Author

@jdm jdm commented Jan 17, 2020

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.

bors-servo added a commit that referenced this issue Jan 19, 2020
Modify `script` to prevent further violations of snake_case

<!-- Please describe your changes on the following line: -->
Remove `#![allow(non_snake_case)]` from `script/lib.rs` and add `#[allow(non_snake_case)]` at each instance of violation.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25531  (GitHub issue number if applicable)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this issue Jan 20, 2020
Modify `script` to prevent further violations of snake_case

<!-- Please describe your changes on the following line: -->
Remove `#![allow(non_snake_case)]` from `script/lib.rs` and add `#[allow(non_snake_case)]` at each instance of violation.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25531  (GitHub issue number if applicable)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this issue Jan 20, 2020
Modify `script` to prevent further violations of snake_case

<!-- Please describe your changes on the following line: -->
Remove `#![allow(non_snake_case)]` from `script/lib.rs` and add `#[allow(non_snake_case)]` at each instance of violation.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25531  (GitHub issue number if applicable)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
bors-servo added a commit that referenced this issue Jan 20, 2020
Modify `script` to prevent further violations of snake_case

<!-- Please describe your changes on the following line: -->
Remove `#![allow(non_snake_case)]` from `script/lib.rs` and add `#[allow(non_snake_case)]` at each instance of violation.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25531  (GitHub issue number if applicable)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.