Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into lint/1656
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasweng committed Jan 26, 2024
2 parents 99eb2ed + 49aa1ee commit 26d6e52
Show file tree
Hide file tree
Showing 31 changed files with 496 additions and 607 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

- Fix [#1508](https://github.com/biomejs/biome/issues/1508) by excluding deleted files from being processed. Contributed by @ematipico

- Fix [#1173](https://github.com/biomejs/biome/issues/1173). Fix the formatting of a single instruction with commented in a control flow body to ensure consistency. Contributed by @mdm317

### Configuration

### Editors

#### Bug fixes

- Fix a regression where ignored files where formatted in the editor. Contributed by @ematipico

### Formatter

#### Bug fixes
Expand Down Expand Up @@ -60,7 +66,7 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
```
Contributed by @ematipico

- Add rule [noSortedClasses](https://biomejs.dev/linter/rules/use-sorted-classes), to sort CSS utility classes:
- Add rule [useSortedClasses](https://biomejs.dev/linter/rules/use-sorted-classes), to sort CSS utility classes:

```diff
- <div class="px-2 foo p-4 bar" />
Expand All @@ -70,8 +76,12 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

#### Bug fixes

- Fix [#1651](https://github.com/biomejs/biome/issues/1651). [noVar](https://biomejs.dev/linter/rules/no-var/) now ignores TsGlobalDeclaration. Contributed by @vasucp1207

- Fix [#1640](https://github.com/biomejs/biome/issues/1640). [useEnumInitializers](https://biomejs.dev/linter/rules/use-enum-initializers) code action now generates valid code when last member has a comment but no comma. Contributed by @kalleep

- Fix [#1653](https://github.com/biomejs/biome/issues/1653). Handle a shorthand value in `useForOf` to avoid the false-positive case. Contributed by @togami2864

- Fix [#1656](https://github.com/biomejs/biome/issues/1656). [useOptionalChain](https://biomejs.dev/linter/rules/use-optional-chain/) code action now correctly handles logical and chains where methods with the same name are invoked with different arguments:
```diff
- tags·&&·tags.includes('a')·&&·tags.includes('b')
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/service/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tracing::Instrument;
/// Returns the name of the global named pipe used to communicate with the
/// server daemon
fn get_pipe_name() -> String {
format!(r"\\.\pipe\rome-service-{}", biome_service::VERSION)
format!(r"\\.\pipe\biome-service-{}", biome_service::VERSION)
}

pub(crate) fn enumerate_pipes() -> io::Result<impl Iterator<Item = String>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,10 @@ fn into_member_vec(node: &JsSyntaxNode) -> Vec<String> {
let member_name = member_expr
.member_name()
.and_then(|it| it.as_string_constant().map(|it| it.to_owned()));
match member_name {
Some(name) => {
vec.insert(0, name);
next = member_expr.object().ok().map(AstNode::into_syntax);
}
None => break,
if let Some(member_name) = member_name {
vec.insert(0, member_name);
}
next = member_expr.object().ok().map(AstNode::into_syntax);
}
None => {
vec.insert(0, node.text_trimmed().to_string());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic, Ru
use biome_console::markup;
use biome_js_semantic::{ReferencesExtensions, SemanticModel};
use biome_js_syntax::{
AnyJsExpression, AnyJsForInitializer, AnyJsStatement, JsAssignmentExpression,
JsAssignmentOperator, JsBinaryExpression, JsBinaryOperator, JsForStatement,
JsIdentifierBinding, JsIdentifierExpression, JsPostUpdateExpression, JsPostUpdateOperator,
JsPreUpdateExpression, JsPreUpdateOperator, JsSyntaxKind, JsSyntaxToken, JsUnaryOperator,
AnyJsExpression, AnyJsForInitializer, AnyJsObjectMember, AnyJsStatement,
JsAssignmentExpression, JsAssignmentOperator, JsBinaryExpression, JsBinaryOperator,
JsForStatement, JsIdentifierBinding, JsIdentifierExpression, JsPostUpdateExpression,
JsPostUpdateOperator, JsPreUpdateExpression, JsPreUpdateOperator,
JsShorthandPropertyObjectMember, JsSyntaxKind, JsSyntaxToken, JsUnaryOperator,
JsVariableDeclarator,
};
use biome_rowan::{declare_node_union, AstNode, AstSeparatedList, TextRange};
Expand Down Expand Up @@ -52,7 +53,7 @@ declare_node_union! {
}

declare_node_union! {
pub(crate) AnyBindingExpression = JsPostUpdateExpression | JsPreUpdateExpression | JsIdentifierExpression
pub(crate) AnyBindingExpression = JsPostUpdateExpression | JsPreUpdateExpression | JsIdentifierExpression | JsShorthandPropertyObjectMember
}

impl Rule for UseForOf {
Expand Down Expand Up @@ -99,15 +100,13 @@ impl Rule for UseForOf {
.as_js_static_member_expression()?
.object()
.ok()?;

let index_only_used_with_array = |reference| {
let array_in_use = reference_being_used_by_array(reference, &array_used_in_for)
.is_some_and(|array_in_use| array_in_use);
let is_delete = is_delete(reference).is_some_and(|is_delete| is_delete);

array_in_use && !is_delete
};

if references.iter().all(index_only_used_with_array) {
Some(())
} else {
Expand Down Expand Up @@ -147,6 +146,12 @@ fn list_initializer_references(
return None;
}

if let Some(AnyJsObjectMember::JsShorthandPropertyObjectMember(expr)) =
AnyJsObjectMember::cast(reference.syntax().parent()?)
{
return Some(AnyBindingExpression::from(expr));
}

AnyBindingExpression::try_from(AnyJsExpression::cast(reference.syntax().parent()?)?)
.ok()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod sort;
mod sort_config;

use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, FixKind, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -150,25 +150,24 @@ lazy_static! {
}

impl Rule for UseSortedClasses {
type Query = AnyClassStringLike;
type Query = Ast<AnyClassStringLike>;
type State = String;
type Signals = Option<Self::State>;
type Options = UtilityClassSortingOptions;

fn run(ctx: &RuleContext<Self>) -> Option<Self::State> {
// TODO: unsure if options are needed here. The sort config should ideally be created once
// from the options and then reused for all queries.
// let options = &ctx.options();
let options = ctx.options();
let node = ctx.query();

let value = ctx.query().value()?;
// TODO: the sort config should already exist at this point, and be generated from the options,
// including the preset and extended options as well.
let sorted_value = sort_class_name(&value, &SORT_CONFIG);
if value.text() != sorted_value {
Some(sorted_value)
} else {
None
if node.should_visit(options).is_some() {
if let Some(value) = node.value() {
let sorted_value = sort_class_name(&value, &SORT_CONFIG);
if value.text() != sorted_value {
return Some(sorted_value);
}
}
}
None
}

fn diagnostic(ctx: &RuleContext<Self>, _: &Self::State) -> Option<RuleDiagnostic> {
Expand Down
Loading

0 comments on commit 26d6e52

Please sign in to comment.