-
Notifications
You must be signed in to change notification settings - Fork 180
feat(rust_style): Rust-style naming convention rule #1323
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
Open
c-antin
wants to merge
7
commits into
denoland:main
Choose a base branch
from
c-antin:rust_style
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6bed57d
feat(rust_style): copy `camelcase`
c-antin 0523911
feat(rust_style): basic rust-style naming rule
c-antin 11f4b5c
feat(rust_style): allow SCREAMING_SNAKE_CASE for static props and con…
c-antin fa9e8bb
fix(rust_style): added doc test cases and discovered #1187
c-antin e1fa0aa
feat(rust_style): consistency
c-antin 3e66987
feat(rust_style): allow UpperCamelCase function JSX components
c-antin 08405ed
feat(rust_style): check class props + methods
c-antin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| Enforces the use of Rust-style naming conventions, see | ||
| https://rust-lang.github.io/api-guidelines/naming.html | ||
|
|
||
| Consistency in a code base is key for readability and maintainability. This rule | ||
| is useful for deno projects that call rust functions via FFI. It attempts to | ||
| unify naming conventions and enforces declarations and object property names | ||
| which you create to be\ | ||
| in UpperCamelCase/PascalCase for classes, types, interfaces,\ | ||
| in snake_case for functions, methods, variables\ | ||
| and in SCREAMING_SNAKE_CASE for static class properties and constants. | ||
|
|
||
| Of note: | ||
|
|
||
| - `_` is allowed at the start or end of a variable | ||
| - All uppercase variable names (e.g. constants) may have `_` in their name | ||
| - If you have to use a camelCase key in an object for some reasons, wrap it in | ||
| quotation mark | ||
| - This rule also applies to variables imported or exported via ES modules, but | ||
| not to object properties of those variables | ||
|
|
||
| ### Invalid: | ||
|
|
||
| ```typescript | ||
| let firstName = "Ichigo"; | ||
| const obj1 = { lastName: "Hoshimiya" }; | ||
| const obj2 = { firstName }; | ||
|
|
||
| function doSomething() {} | ||
| function foo({ camelCase = "default value" }) {} | ||
|
|
||
| class snake_case_class {} | ||
| class camelCaseClass {} | ||
| class Also_Not_Valid_Class {} | ||
|
|
||
| export * as camelCased from "mod.ts"; | ||
|
|
||
| enum snake_case_enum { | ||
| snake_case_variant, | ||
| } | ||
|
|
||
| enum camelCasedEnum { | ||
| camelCasedVariant, | ||
| } | ||
|
|
||
| type snake_case_type = { some_property: number }; | ||
|
|
||
| type camelCasedType = { someProperty: number }; | ||
|
|
||
| interface snake_case_interface { | ||
| some_property: number; | ||
| } | ||
|
|
||
| interface camelCasedInterface { | ||
| someProperty: number; | ||
| } | ||
| ``` | ||
|
|
||
| ### Valid: | ||
|
|
||
| ```typescript | ||
| let first_name = "Ichigo"; | ||
| const FIRST_NAME = "Ichigo"; | ||
| const __my_private_variable = "Hoshimiya"; | ||
| const my_private_variable_ = "Hoshimiya"; | ||
| const obj1 = { "lastName": "Hoshimiya" }; // if an object key is wrapped in quotation mark, then it's valid | ||
| const obj2 = { "firstName": firstName }; | ||
| const { lastName } = obj1; //valid, because one has no control over the identifier | ||
| const { lastName: last_name } = obj; | ||
|
|
||
| function do_something() {} // function declarations must be snake_case but... | ||
| doSomething(); // ...camel_case function calls are allowed | ||
| function foo({ camelCase: snake_case = "default value" }) {} | ||
|
|
||
| class PascalCaseClass {} | ||
|
|
||
| import { camelCased } from "external-module.js"; //valid, because one has no control over the identifier | ||
|
||
| import { camelCased as not_camel_cased } from "external-module.js"; | ||
| export * as not_camel_cased from "mod.ts"; | ||
|
|
||
| enum PascalCaseEnum { | ||
| PascalCaseVariant, | ||
| } | ||
|
|
||
| type PascalCaseType = { some_property: number }; | ||
|
|
||
| interface PascalCaseInterface { | ||
| some_property: number; | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: #1187 changed this behavior, but camelcase.md did not get updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1325