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

feat(rust_style): Rust-style naming convention rule #1323

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

c-antin
Copy link

@c-antin c-antin commented Sep 15, 2024

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 one creates 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.

See #1322.

@CLAassistant
Copy link

CLAassistant commented Sep 15, 2024

CLA assistant check
All committers have signed the CLA.

);
}
_ => {
self.check_pat(value, ctx);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?is ctx valid everywhere, because it is passed to nested entities, see todo line 538?

("__fooBar_baz__", false), //not snake
("__fooBarBaz__", false), //camel
("Sha3_224", false), //not snake
("SHA3_224", true), //screaming snake; todo: ?should this be true?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?according to camelcase.rs SHA3_224 is valid UpperCamelCase?

@@ -0,0 +1,1922 @@
// Copyright 2018-2024 the Deno authors + c-antin. All rights reserved. MIT license.
// based on camelcase.rs
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare first commit with last commit for useful diff, because rust_style.rs is based on camelcase.rs

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
Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1325


class PascalCaseClass {}

import { camelCased } from "external-module.js"; //valid, because one has no control over the identifier
Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1325

for ident in idents {
self.check_ident_snake_cased_or_screaming_snake_cased(
&ident.range(),
IdentToCheck::variable_or_constant(ident.to_id().0),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?should global assign of camelCase variables be valid, because one has no control over the identifier?
if so, we should remove fn assign_expr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants