Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/little-things-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@biomejs/biome": patch
---

Fixed [#6371](https://github.com/biomejs/biome/issues/6371).
[useNamingConvention](https://biomejs.dev/linter/rules/use-naming-convention/) now checks the string case of objects' property shorthand.
15 changes: 11 additions & 4 deletions crates/biome_js_analyze/src/lint/style/use_naming_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ use biome_js_semantic::{CanBeImportedExported, SemanticModel};
use biome_js_syntax::{
AnyJsClassMember, AnyJsObjectMember, AnyJsVariableDeclaration, AnyTsTypeMember, JsFileSource,
JsIdentifierBinding, JsLiteralExportName, JsLiteralMemberName, JsMethodModifierList,
JsModuleItemList, JsPrivateClassMemberName, JsPropertyModifierList, JsSyntaxKind,
JsSyntaxToken, JsVariableDeclarator, JsVariableKind, Modifier, TsDeclarationModule,
TsIdentifierBinding, TsIndexSignatureModifierList, TsLiteralEnumMemberName,
TsMethodSignatureModifierList, TsPropertySignatureModifierList, TsTypeParameterName,
JsModuleItemList, JsPrivateClassMemberName, JsPropertyModifierList,
JsShorthandPropertyObjectMember, JsSyntaxKind, JsSyntaxToken, JsVariableDeclarator,
JsVariableKind, Modifier, TsDeclarationModule, TsIdentifierBinding,
TsIndexSignatureModifierList, TsLiteralEnumMemberName, TsMethodSignatureModifierList,
TsPropertySignatureModifierList, TsTypeParameterName,
binding_ext::{AnyJsBindingDeclaration, AnyJsIdentifierBinding},
};
use biome_rowan::{
Expand Down Expand Up @@ -1002,6 +1003,7 @@ declare_node_union! {
pub AnyIdentifierBindingLike =
JsIdentifierBinding |
JsLiteralMemberName |
JsShorthandPropertyObjectMember |
JsPrivateClassMemberName |
JsLiteralExportName |
TsIdentifierBinding |
Expand All @@ -1013,6 +1015,7 @@ impl AnyIdentifierBindingLike {
match self {
Self::JsIdentifierBinding(binding) => binding.name_token(),
Self::JsLiteralMemberName(member_name) => member_name.value(),
Self::JsShorthandPropertyObjectMember(member_name) => member_name.name()?.value_token(),
Self::JsPrivateClassMemberName(member_name) => member_name.id_token(),
Self::JsLiteralExportName(export_name) => export_name.value(),
Self::TsIdentifierBinding(binding) => binding.name_token(),
Expand All @@ -1038,6 +1041,7 @@ impl TryFrom<&AnyIdentifierBindingLike> for AnyJsIdentifierBinding {
Ok(Self::TsTypeParameterName(binding.clone()))
}
AnyIdentifierBindingLike::JsLiteralMemberName(_)
| AnyIdentifierBindingLike::JsShorthandPropertyObjectMember(_)
| AnyIdentifierBindingLike::JsPrivateClassMemberName(_)
| AnyIdentifierBindingLike::JsLiteralExportName(_) => Err(()),
}
Expand Down Expand Up @@ -1358,6 +1362,9 @@ impl Selector {
None
}
}
AnyIdentifierBindingLike::JsShorthandPropertyObjectMember(_) => {
Some(Kind::ObjectLiteralProperty.into())
}
AnyIdentifierBindingLike::JsPrivateClassMemberName(member_name) => {
Self::from_class_member(&member_name.parent::<AnyJsClassMember>()?)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: invalidLocalVariable.js
snapshot_kind: text
---
# Input
```js
Expand Down Expand Up @@ -147,3 +146,18 @@ invalidLocalVariable.js:12:11 lint/style/useNamingConvention FIXABLE ━━━


```

```
invalidLocalVariable.js:15:9 lint/style/useNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i This object property name should be in camelCase.

13 │ console.log(a_var);
14 │ return {
> 15 │ a_var // comment
│ ^^^^^
16 │ };
17 │ }


```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SERVICE_NAME = "my-service" as const;

const SERVICE = {
SERVICE_NAME,
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: invalidPorpertyShorthyand.ts
---
# Input
```ts
const SERVICE_NAME = "my-service" as const;

const SERVICE = {
SERVICE_NAME,
} as const;

```

# Diagnostics
```
invalidPorpertyShorthyand.ts:4:3 lint/style/useNamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i This object property name should be in camelCase.

3 │ const SERVICE = {
> 4 │ SERVICE_NAME,
│ ^^^^^^^^^^^^
5 │ } as const;
6 │


```

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.