Skip to content

Commit

Permalink
Merge branch 'main' into feat/use-consistent-grid-areas
Browse files Browse the repository at this point in the history
  • Loading branch information
chansuke authored Jun 10, 2024
2 parents 2d15b78 + da6f180 commit de4314b
Show file tree
Hide file tree
Showing 39 changed files with 1,143 additions and 2,368 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:

jobs:
format:
name: Format and Lint Rust Files
name: Format project
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
Expand All @@ -44,7 +44,7 @@ jobs:
taplo format --check
lint:
name: Lint Rust Files
name: Lint project
runs-on: ubuntu-latest
steps:
- name: Checkout PR Branch
Expand All @@ -57,7 +57,9 @@ jobs:
components: clippy
cache-base: main
- name: Run clippy
run: cargo lint
run: |
cargo lint
cargo run -p rules_check
check-dependencies:
name: Check Dependencies
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
#### Bug fixes

- Fix [#3069](https://github.com/biomejs/biome/issues/3069), prevent overwriting paths when using `--staged` or `--changed` options. Contributed by @unvalley
- Fix a case where the file link inside a diagnostic wasn't correctly displayed inside a terminal run by VSCode. Contributed by @uncenter

### Configuration

Expand Down Expand Up @@ -59,6 +60,16 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- [noEmptyInterface](https://biomejs.dev/linter/rules/no-empty-interface/) now ignores empty interfaces in ambient modules ([#3110](https://github.com/biomejs/biome/issues/3110)). Contributed by @Conaclos

- [noUnusedVariables](https://biomejs.dev/linter/rules/no-unused-variables/) and [noUnusedFunctionParameters](https://biomejs.dev/linter/rules/no-unused-function-parameters/) no longer report the parameters of a constructor type ([#3135](https://github.com/biomejs/biome/issues/3135)).

Previously, `arg` was reported as unused in a constructor type like:

```ts
export type Classlike = new (arg: unknown) => string;
```

Contributed by @Conaclos

### Parser

#### New features
Expand Down Expand Up @@ -424,6 +435,7 @@ New rules are incubated in the nursery group. Once stable, we promote them to a
- Add [nursery/useGenericFontNames](https://biomejs.dev/linter/rules/use-generic-font-names). [#2573](https://github.com/biomejs/biome/pull/2573) Contributed by @togami2864
- Add [nursery/noYodaExpression](https://biomejs.dev/linter/rules/no-yoda-expression/). Contributed by @michellocana
- Add [nursery/noUnusedFunctionParameters](https://biomejs.dev/linter/rules/no-unused-function-parameters/) Contributed by @printfn
- Add [nursery/UseSemanticElements](https://biomejs.dev/linter/rules/use-semantic-elements/). Contributed by @fujiyamaorange

#### Enhancements

Expand Down
51 changes: 50 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
# Use the newer version of the cargo resolver
# https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
members = ["crates/*", "xtask/bench", "xtask/codegen", "xtask/coverage", "xtask/libs_bench"]
members = ["crates/*", "xtask/bench", "xtask/codegen", "xtask/coverage", "xtask/libs_bench", "xtask/rules_check"]
resolver = "2"

[workspace.lints.rust]
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"json": {
"formatter": {
"indentStyle": "space"
"indentStyle": "space",
"lineWidth": 1
}
},
"vcs": {
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_aria/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ macro_rules! define_role {
}
None
}

fn concepts_by_role<'a>(&self) -> ElementsAndAttributes<'a> {
Some(Self::CONCEPTS.iter())
}
}
};
}
Expand Down
59 changes: 59 additions & 0 deletions crates/biome_aria/src/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,61 @@ impl<'a> AriaRoles {

false
}

/// Given a role, it returns the corresponding elements and attributes associated to that role
pub fn get_elements_by_role(&self, role: &str) -> ElementsAndAttributes {
let role_candidate = match role {
"checkbox" => &CheckboxRole as &dyn AriaRoleDefinitionWithConcepts,
"radio" => &RadioRole as &dyn AriaRoleDefinitionWithConcepts,
"option" => &OptionRole as &dyn AriaRoleDefinitionWithConcepts,
"combobox" => &ComboBoxRole as &dyn AriaRoleDefinitionWithConcepts,
"heading" => &HeadingRole as &dyn AriaRoleDefinitionWithConcepts,
"separator" => &SeparatorRole as &dyn AriaRoleDefinitionWithConcepts,
"button" => &ButtonRole as &dyn AriaRoleDefinitionWithConcepts,
"article" => &ArticleRole as &dyn AriaRoleDefinitionWithConcepts,
"dialog" => &DialogRole as &dyn AriaRoleDefinitionWithConcepts,
"alert" => &AlertRole as &dyn AriaRoleDefinitionWithConcepts,
"alertdialog" => &AlertDialogRole as &dyn AriaRoleDefinitionWithConcepts,
"cell" => &CellRole as &dyn AriaRoleDefinitionWithConcepts,
"columnheader" => &ColumnHeaderRole as &dyn AriaRoleDefinitionWithConcepts,
"definition" => &DefinitionRole as &dyn AriaRoleDefinitionWithConcepts,
"figure" => &FigureRole as &dyn AriaRoleDefinitionWithConcepts,
"form" => &FormRole as &dyn AriaRoleDefinitionWithConcepts,
"graphics-document" => &GraphicsDocumentRole as &dyn AriaRoleDefinitionWithConcepts,
"graphics-object" => &GraphicsObjectRole as &dyn AriaRoleDefinitionWithConcepts,
"grid" => &GridRole as &dyn AriaRoleDefinitionWithConcepts,
"gridcell" => &GridCellRole as &dyn AriaRoleDefinitionWithConcepts,
"group" => &GroupRole as &dyn AriaRoleDefinitionWithConcepts,
"img" => &ImgRole as &dyn AriaRoleDefinitionWithConcepts,
"link" => &LinkRole as &dyn AriaRoleDefinitionWithConcepts,
"list" => &ListRole as &dyn AriaRoleDefinitionWithConcepts,
"listbox" => &ListBoxRole as &dyn AriaRoleDefinitionWithConcepts,
"listitem" => &ListItemRole as &dyn AriaRoleDefinitionWithConcepts,
"navigation" => &NavigationRole as &dyn AriaRoleDefinitionWithConcepts,
"row" => &RowRole as &dyn AriaRoleDefinitionWithConcepts,
"rowgroup" => &RowGroupRole as &dyn AriaRoleDefinitionWithConcepts,
"rowheader" => &RowHeaderRole as &dyn AriaRoleDefinitionWithConcepts,
"search" => &SearchboxRole as &dyn AriaRoleDefinitionWithConcepts,
"searchbox" => &SearchboxRole as &dyn AriaRoleDefinitionWithConcepts,
"table" => &TableRole as &dyn AriaRoleDefinitionWithConcepts,
"term" => &TermRole as &dyn AriaRoleDefinitionWithConcepts,
"textbox" => &TextboxRole as &dyn AriaRoleDefinitionWithConcepts,
"generic" => &GenericRole as &dyn AriaRoleDefinitionWithConcepts,
"caption" => &CaptionRole as &dyn AriaRoleDefinitionWithConcepts,
"main" => &MainRole as &dyn AriaRoleDefinitionWithConcepts,
"time" => &TimeRole as &dyn AriaRoleDefinitionWithConcepts,
"p" => &ParagraphRole as &dyn AriaRoleDefinitionWithConcepts,
"aside" => &ComplementaryRole as &dyn AriaRoleDefinitionWithConcepts,
"blockquote" => &BlockQuoteRole as &dyn AriaRoleDefinitionWithConcepts,
"associationlist" => &AssociationListRole as &dyn AriaRoleDefinitionWithConcepts,
"status" => &StatusRole as &dyn AriaRoleDefinitionWithConcepts,
"contentinfo" => &ContentInfoRole as &dyn AriaRoleDefinitionWithConcepts,
"region" => &RegionRole as &dyn AriaRoleDefinitionWithConcepts,
_ => return None,
};

role_candidate.concepts_by_role()
}
}

type ElementsAndAttributes<'a> = Option<Iter<'a, (&'a str, &'a [(&'a str, &'a str)])>>;
Expand All @@ -1249,6 +1304,10 @@ pub trait AriaRoleDefinitionWithConcepts: AriaRoleDefinition {
fn concepts_by_element_name<'a>(&self, _element_name: &str) -> ElementsAndAttributes<'a> {
None
}

fn concepts_by_role<'a>(&self) -> ElementsAndAttributes<'a> {
None
}
}

/// Convenient type to retrieve metadata regarding ARIA roles
Expand Down
22 changes: 14 additions & 8 deletions crates/biome_diagnostics/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::Path;
use std::{io, iter};
use std::{env, io, iter};

use biome_console::{fmt, markup, HorizontalLine, Markup, MarkupBuf, MarkupElement, MarkupNode};
use biome_text_edit::TextEdit;
Expand Down Expand Up @@ -91,15 +91,21 @@ impl<D: Diagnostic + ?Sized> fmt::Display for PrintHeader<'_, D> {
_ => None,
};

let is_vscode = env::var("TERM_PROGRAM").unwrap_or_default() == "vscode";

if let Some(name) = file_name {
let path_name = Path::new(name);
if path_name.is_absolute() {
let link = format!("file://{}", name);
fmt.write_markup(markup! {
<Hyperlink href={link}>{name}</Hyperlink>
})?;
} else {
if is_vscode {
fmt.write_str(name)?;
} else {
let path_name = Path::new(name);
if path_name.is_absolute() {
let link = format!("file://{}", name);
fmt.write_markup(markup! {
<Hyperlink href={link}>{name}</Hyperlink>
})?;
} else {
fmt.write_str(name)?;
}
}

// Print the line and column position if the location has a span and source code
Expand Down
29 changes: 15 additions & 14 deletions crates/biome_js_analyze/src/lint/correctness/no_unused_variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use biome_analyze::{
use biome_console::markup;
use biome_js_semantic::ReferencesExtensions;
use biome_js_syntax::binding_ext::{
AnyJsBindingDeclaration, AnyJsIdentifierBinding, JsAnyParameterParentFunction,
AnyJsBindingDeclaration, AnyJsIdentifierBinding, AnyJsParameterParentFunction,
};
use biome_js_syntax::declaration_ext::is_in_ambient_context;
use biome_js_syntax::{
Expand Down Expand Up @@ -114,23 +114,26 @@ pub enum SuggestedFix {
}

fn is_function_that_is_ok_parameter_not_be_used(
parent_function: &Option<JsAnyParameterParentFunction>,
parent_function: &Option<AnyJsParameterParentFunction>,
) -> bool {
matches!(
parent_function,
Some(
// bindings in signatures are ok to not be used
JsAnyParameterParentFunction::TsMethodSignatureClassMember(_)
| JsAnyParameterParentFunction::TsCallSignatureTypeMember(_)
| JsAnyParameterParentFunction::TsConstructSignatureTypeMember(_)
| JsAnyParameterParentFunction::TsConstructorSignatureClassMember(_)
| JsAnyParameterParentFunction::TsMethodSignatureTypeMember(_)
| JsAnyParameterParentFunction::TsSetterSignatureClassMember(_)
| JsAnyParameterParentFunction::TsSetterSignatureTypeMember(_)
AnyJsParameterParentFunction::TsMethodSignatureClassMember(_)
| AnyJsParameterParentFunction::TsCallSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsConstructSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsConstructorSignatureClassMember(_)
| AnyJsParameterParentFunction::TsMethodSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsSetterSignatureClassMember(_)
| AnyJsParameterParentFunction::TsSetterSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsIndexSignatureClassMember(_)
// bindings in function types are ok to not be used
| JsAnyParameterParentFunction::TsFunctionType(_)
| AnyJsParameterParentFunction::TsFunctionType(_)
| AnyJsParameterParentFunction::TsConstructorType(_)
// binding in declare are ok to not be used
| JsAnyParameterParentFunction::TsDeclareFunctionDeclaration(_)
| AnyJsParameterParentFunction::TsDeclareFunctionDeclaration(_)
| AnyJsParameterParentFunction::TsDeclareFunctionExportDefaultDeclaration(_)
)
)
}
Expand Down Expand Up @@ -285,10 +288,8 @@ impl Rule for NoUnusedVariables {
}

let binding = ctx.query();
let name = binding.name_token().ok()?;
let name = name.text_trimmed();

if name.starts_with('_') {
if binding.name_token().ok()?.text_trimmed().starts_with('_') {
return None;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use biome_analyze::{
use biome_console::markup;
use biome_js_semantic::ReferencesExtensions;
use biome_js_syntax::{
binding_ext::{AnyJsBindingDeclaration, JsAnyParameterParentFunction},
binding_ext::{AnyJsBindingDeclaration, AnyJsParameterParentFunction},
JsIdentifierBinding,
};
use biome_rowan::{AstNode, BatchMutationExt};
Expand Down Expand Up @@ -65,23 +65,26 @@ pub enum SuggestedFix {
}

fn is_function_that_is_ok_parameter_not_be_used(
parent_function: &Option<JsAnyParameterParentFunction>,
parent_function: &Option<AnyJsParameterParentFunction>,
) -> bool {
matches!(
parent_function,
Some(
// bindings in signatures are ok to not be used
JsAnyParameterParentFunction::TsMethodSignatureClassMember(_)
| JsAnyParameterParentFunction::TsCallSignatureTypeMember(_)
| JsAnyParameterParentFunction::TsConstructSignatureTypeMember(_)
| JsAnyParameterParentFunction::TsConstructorSignatureClassMember(_)
| JsAnyParameterParentFunction::TsMethodSignatureTypeMember(_)
| JsAnyParameterParentFunction::TsSetterSignatureClassMember(_)
| JsAnyParameterParentFunction::TsSetterSignatureTypeMember(_)
AnyJsParameterParentFunction::TsMethodSignatureClassMember(_)
| AnyJsParameterParentFunction::TsCallSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsConstructSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsConstructorSignatureClassMember(_)
| AnyJsParameterParentFunction::TsMethodSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsSetterSignatureClassMember(_)
| AnyJsParameterParentFunction::TsSetterSignatureTypeMember(_)
| AnyJsParameterParentFunction::TsIndexSignatureClassMember(_)
// bindings in function types are ok to not be used
| JsAnyParameterParentFunction::TsFunctionType(_)
| AnyJsParameterParentFunction::TsFunctionType(_)
| AnyJsParameterParentFunction::TsConstructorType(_)
// binding in declare are ok to not be used
| JsAnyParameterParentFunction::TsDeclareFunctionDeclaration(_)
| AnyJsParameterParentFunction::TsDeclareFunctionDeclaration(_)
| AnyJsParameterParentFunction::TsDeclareFunctionExportDefaultDeclaration(_)
)
)
}
Expand Down
Loading

0 comments on commit de4314b

Please sign in to comment.