Skip to content

Commit

Permalink
Merge branch 'website-v2' into revamp-home
Browse files Browse the repository at this point in the history
  • Loading branch information
vasucp1207 authored Dec 6, 2023
2 parents d2f2d1c + 94e9d15 commit d926fbf
Show file tree
Hide file tree
Showing 238 changed files with 14,244 additions and 3,626 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/website/src/content/docs/ja/ @biomejs/japanese-translation-reviewers
/website/.textlintrc.json @biomejs/japanese-translation-reviewers
/website/prh.yml @biomejs/japanese-translation-reviewers
/.github/workflows/ja-translation.yaml @biomejs/japanese-translation-reviewers
32 changes: 32 additions & 0 deletions .github/workflows/ja-translation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Checks for Japanese Documentation

on:
pull_request:
branches:
- main
paths:
- "website/src/content/docs/ja/**"

jobs:
ja-docs-check:
name: Checks on JA Docs
runs-on: ubuntu-latest
steps:
- name: Checkout PR Branch
uses: actions/checkout@v4
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/[email protected]
with:
version: 8
- name: Install libraries
working-directory: website
run: pnpm i
- name: Run textlint
working-directory: website
run: pnpm textlint
56 changes: 56 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,58 @@ Read our [guidelines to categorize a change](https://biomejs.dev/internals/versi
New entries must be placed in a section entitled `Unreleased`.
Read our [guidelines for writing a good changelog entry](https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#changelog).

## Unreleased

### Analyzer

### CLI

### Configuration

### Editors

### Formatter

### JavaScript APIs

### Linter

#### New features

#### Enhancements

#### Bug fixes

- Fix [#959](https://github.com/biomejs/biome/issues/959). [noEmptyInterface](https://biomejs.dev/linter/rules/no-empty-interface) no longer reports interface that extends a type and is in an external module. COntributed by @Conaclos

Empty interface that extends a type are sometimes used to extend an existing interface.
This is generally used to extend an interface of an external module.

```ts
interface Extension {
metadata: unknown;
}

declare module "@external/module" {
export interface ExistingInterface extends Extension {}
}
```

- Fix [#1061](https://github.com/biomejs/biome/issues/1061). [noRedeclare](https://biomejs.dev/linter/rules/no-redeclare) no longer reports overloads of `export default function`. Contributed by @Conaclos

The following code is no longer reported:

```ts
export default function(a: boolean): boolean;
export default function(a: number): number;
export default function(a: number | boolean): number | boolean {
return a;
}
```

### Parser


## 1.4.1 (2023-11-30)

### Editors
Expand All @@ -32,6 +84,10 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom

#### New features

- Add [useForOf](https://biomejs.dev/linter/rules/use-for-of) rule.
The rule recommends a for-of loop when the loop index is only used to read from an array that is being iterated.
Contributed by @victor-teles

#### Enhancement

- Implements [#924](https://github.com/biomejs/biome/issues/924) and [#920](https://github.com/biomejs/biome/issues/920). [noUselessElse](https://biomejs.dev/linter/rules/no-useless-else) now ignores `else` clauses that follow at least one `if` statement that doesn't break early. Contributed by @Conaclos
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

54 changes: 54 additions & 0 deletions crates/biome_analyze/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,57 @@ impl Rule for ExampleRule {
}
}
```

### Semantic Model

The semantic model provides information about the references of a binding (variable) within a program, indicating if it is written (e.g., `const a = 4`), read (e.g., `const b = a`, where `a` is read), or exported.


#### How to use the query `Semantic<>` in a lint rule

We have a for loop that creates an index i, and we need to identify where this index is used inside the body of the loop

```js
for (let i = 0; i < array.length; i++) {
array[i] = i
}
```

To get started we need to create a new rule using the semantic type `type Query = Semantic<JsForStatement>;`
We can now use the `ctx.model()` to get information about bindings in the for loop.

```rust,ignore
impl Rule for ForLoopCountReferences {
type Query = Semantic<JsForStatement>;
type State = ();
type Signals = Option<Self::State>;
type Options = ();
fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let node = ctx.query();
// The model holds all informations about the semantic, like scopes and declarations
let model = ctx.model();
// Here we are extracting the `let i = 0;` declaration in for loop
let initializer = node.initializer()?;
let declarators = initializer.as_js_variable_declaration()?.declarators();
let initializer = declarators.first()?.ok()?;
let initializer_id = initializer.id().ok()?;
// Now we have the binding of this declaration
let binding = initializer_id
.as_any_js_binding()?
.as_js_identifier_binding()?;
// How many times this variable appers in the code
let count = binding.all_references(model).count();
// Get all read references
let readonly_references = binding.all_reads(model);
// Get all write references
let write_references = binding.all_writes(model);
}
}
```
4 changes: 2 additions & 2 deletions crates/biome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::configuration::LoadedConfiguration;
use crate::vcs::store_path_to_ignore_from_vcs;
use crate::{
configuration::load_configuration, execute_mode, setup_cli_subscriber, CliDiagnostic,
CliSession, Execution, TraversalMode,
CliSession, Execution,
};
use biome_service::configuration::organize_imports::OrganizeImports;
use biome_service::configuration::{FormatterConfiguration, LinterConfiguration};
Expand Down Expand Up @@ -94,7 +94,7 @@ pub(crate) fn ci(mut session: CliSession, payload: CiCommandPayload) -> Result<(
.update_settings(UpdateSettingsParams { configuration })?;

execute_mode(
Execution::new(TraversalMode::CI),
Execution::new_ci(),
session,
&payload.cli_options,
payload.paths,
Expand Down
40 changes: 34 additions & 6 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ impl Execution {
}
}

#[derive(Debug)]
pub(crate) enum ExecutionEnvironment {
GitHub,
}

#[derive(Debug)]
pub(crate) enum TraversalMode {
/// This mode is enabled when running the command `biome check`
Expand Down Expand Up @@ -62,7 +67,10 @@ pub(crate) enum TraversalMode {
stdin: Option<(PathBuf, String)>,
},
/// This mode is enabled when running the command `biome ci`
CI,
CI {
/// Whether the CI is running in a specific environment, e.g. GitHub, GitLab, etc.
environment: Option<ExecutionEnvironment>,
},
/// This mode is enabled when running the command `biome format`
Format {
/// It ignores parse errors
Expand Down Expand Up @@ -113,6 +121,26 @@ impl Execution {
}
}

pub(crate) fn new_ci() -> Self {
// Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables
let is_github = std::env::var("GITHUB_ACTIONS")
.ok()
.map(|value| value == "true")
.unwrap_or(false);

Self {
report_mode: ReportMode::default(),
traversal_mode: TraversalMode::CI {
environment: if is_github {
Some(ExecutionEnvironment::GitHub)
} else {
None
},
},
max_diagnostics: MAXIMUM_DISPLAYABLE_DIAGNOSTICS,
}
}

/// Creates an instance of [Execution] by passing [traversal mode](TraversalMode) and [report mode](ReportMode)
pub(crate) fn with_report(traversal_mode: TraversalMode, report_mode: ReportMode) -> Self {
Self {
Expand Down Expand Up @@ -140,17 +168,17 @@ impl Execution {
match &self.traversal_mode {
TraversalMode::Check { fix_file_mode, .. }
| TraversalMode::Lint { fix_file_mode, .. } => fix_file_mode.as_ref(),
TraversalMode::Format { .. } | TraversalMode::CI | TraversalMode::Migrate { .. } => {
None
}
TraversalMode::Format { .. }
| TraversalMode::CI { .. }
| TraversalMode::Migrate { .. } => None,
}
}

pub(crate) fn as_diagnostic_category(&self) -> &'static Category {
match self.traversal_mode {
TraversalMode::Check { .. } => category!("check"),
TraversalMode::Lint { .. } => category!("lint"),
TraversalMode::CI => category!("ci"),
TraversalMode::CI { .. } => category!("ci"),
TraversalMode::Format { .. } => category!("format"),
TraversalMode::Migrate { .. } => category!("migrate"),
}
Expand Down Expand Up @@ -205,7 +233,7 @@ impl Execution {
match self.traversal_mode {
TraversalMode::Check { fix_file_mode, .. }
| TraversalMode::Lint { fix_file_mode, .. } => fix_file_mode.is_some(),
TraversalMode::CI => false,
TraversalMode::CI { .. } => false,
TraversalMode::Format { write, .. } => write,
TraversalMode::Migrate { write: dry_run, .. } => dry_run,
}
Expand Down
4 changes: 3 additions & 1 deletion crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult {
TraversalMode::Check { .. } => {
check_file(shared_context, path, &file_features, category!("check"))
}
TraversalMode::CI => check_file(shared_context, path, &file_features, category!("ci")),
TraversalMode::CI { .. } => {
check_file(shared_context, path, &file_features, category!("ci"))
}
TraversalMode::Migrate { .. } => {
unreachable!("The migration should not be called for this file")
}
Expand Down
12 changes: 12 additions & 0 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::process_file::{process_file, DiffKind, FileStatus, Message};
use super::ExecutionEnvironment;
use crate::cli_options::CliOptions;
use crate::execute::diagnostics::{
CIFormatDiffDiagnostic, CIOrganizeImportsDiffDiagnostic, ContentDiffAdvice,
Expand All @@ -9,6 +10,7 @@ use crate::{
Report, ReportDiagnostic, ReportDiff, ReportErrorKind, ReportKind, TraversalMode,
};
use biome_console::{fmt, markup, Console, ConsoleExt};
use biome_diagnostics::PrintGitHubDiagnostic;
use biome_diagnostics::{
adapters::StdError, category, DiagnosticExt, Error, PrintDescription, PrintDiagnostic,
Resource, Severity,
Expand Down Expand Up @@ -570,13 +572,23 @@ fn process_messages(options: ProcessMessagesOptions) {
}
}
}
let running_on_github = matches!(
mode.traversal_mode(),
TraversalMode::CI {
environment: Some(ExecutionEnvironment::GitHub),
}
);

for diagnostic in diagnostics_to_print {
if diagnostic.severity() >= *diagnostic_level {
console.error(markup! {
{if verbose { PrintDiagnostic::verbose(&diagnostic) } else { PrintDiagnostic::simple(&diagnostic) }}
});
}

if running_on_github {
console.log(markup! {{PrintGitHubDiagnostic::simple(&diagnostic)}});
}
}

if mode.is_check() && total_skipped_suggested_fixes > 0 {
Expand Down
Loading

0 comments on commit d926fbf

Please sign in to comment.