Skip to content

Commit

Permalink
Merge branch 'main' into select-bin-packages
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Oct 16, 2024
2 parents ffb2576 + f32efe1 commit f4a632a
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 80 deletions.
43 changes: 23 additions & 20 deletions assets/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<style>
/* Styles for the loading screen */
:root {
--web-bg-color: #282828;
--web-bg-color: #2b2c2f;
}

* {
Expand All @@ -30,7 +30,7 @@
flex-direction: column;
}

#game {
body {
background-color: var(--web-bg-color);
}

Expand All @@ -55,21 +55,12 @@
transform: rotate(360deg);
}
}

#bevy {
/* Hide Bevy app before it loads */
height: 0;
}
</style>
</head>

<body>
<div id="game" class="center">
<div id="loading-screen" class="center">
<span class="spinner"></span>
</div>

<canvas id="bevy">Javascript and canvas support is required</canvas>
<body class="center">
<div id="loading-screen" class="center">
<span class="spinner"></span>
</div>

<script type="module">
Expand All @@ -89,14 +80,26 @@
<script type="module">
// Hide loading screen when the game starts.
const loading_screen = document.getElementById("loading-screen");
const bevy = document.getElementById("bevy");
const observer = new MutationObserver(() => {
if (bevy.height > 1) {
loading_screen.style.display = "none";
observer.disconnect();
const observer = new MutationObserver((records) => {
for (const record of records) {
for (const addedNode of record.addedNodes) {
if (addedNode instanceof HTMLCanvasElement) {
// A new canvas has been created, which means that the game has been loaded
// Hide the loading screen!
loading_screen.style.display = "none";
observer.disconnect();
return;
}
}
}
});
observer.observe(bevy, { attributeFilter: ["height"] });

observer.observe(document.body, {
subtree: false,
childList: true,
attributes: false,
characterData: false,
});
</script>

<script type="module">
Expand Down
1 change: 1 addition & 0 deletions bevy_lint/src/callback.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc_driver::Callbacks;
use rustc_interface::interface::Config;

/// The `rustc` [`Callbacks`] that register Bevy's lints.
pub struct BevyLintCallback;

impl Callbacks for BevyLintCallback {
Expand Down
161 changes: 107 additions & 54 deletions bevy_lint/src/groups.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,123 @@
//! Lint groups that can be toggled together.
//!
//! Each lint is organized within a specific category, such as [`PERFORMANCE`] or [`STYLE`].
use crate::{
lint::{BevyLint, LintGroup},
lints::LINTS,
};
use rustc_lint::{Level, LintStore};

/// A group of deny-by-default lints that check for outright wrong or useless code.
///
/// These lints are carefully picked to be free of false positives. You should avoid
/// `#[allow(...)]`-ing these lints without a _very_ good reason.
pub static CORRECTNESS: &LintGroup = &LintGroup {
name: "bevy::correctness",
level: Level::Deny,
};
/// A macro for declaring [`LintGroup`]s that auto-generates a table with the name and default
/// level in the documentation.
macro_rules! declare_group {
{
$(#[$attr:meta])*
$vis:vis static $static_name:ident = {
name: $group_name:literal,
level: $level:expr$(,)?
};
} => {
$(#[$attr])*
///
/// <table>
/// <tr>
/// <td>Name</td>
#[doc = concat!(" <td><code>", stringify!($group_name), "</code></td>")]
/// </tr>
/// <tr>
/// <td>Default Level</td>
#[doc = concat!(" <td><code>", stringify!($level), "</code></td>")]
/// </tr>
/// </table>
$vis static $static_name: &LintGroup = &LintGroup {
name: $group_name,
level: $level,
};
};
}

/// A group similar to [`CORRECTNESS`] that checks for suspicious or usually wrong code.
///
/// The linted code may have been written intentionally, but should probably still be fixed.
pub static SUSPICIOUS: &LintGroup = &LintGroup {
name: "bevy::suspicious",
level: Level::Warn,
};
declare_group! {
/// A group of deny-by-default lints that check for outright wrong or useless code.
///
/// These lints are carefully picked to be free of false positives. You should avoid
/// `#[allow(...)]`-ing these lints without a _very_ good reason.
pub static CORRECTNESS = {
name: "bevy::correctness",
level: Level::Deny,
};
}

/// A group that offers suggestions on how to simplify your code.
pub static COMPLEXITY: &LintGroup = &LintGroup {
name: "bevy::complexity",
level: Level::Warn,
};
declare_group! {
/// A group similar to [`CORRECTNESS`] that checks for suspicious or usually wrong code.
///
/// The linted code may have been written intentionally, but should probably still be fixed.
pub static SUSPICIOUS = {
name: "bevy::suspicious",
level: Level::Warn,
};
}

/// A group that suggests how to increase the performance of your code.
pub static PERFORMANCE: &LintGroup = &LintGroup {
name: "bevy::performance",
level: Level::Warn,
};
declare_group! {
/// A group that offers suggestions on how to simplify your code.
pub static COMPLEXITY = {
name: "bevy::complexity",
level: Level::Warn,
};
}

/// A group of lints that encourage idiomatic code.
///
/// These lints are opinionated and may be freely disabled if you disagree with their suggestions.
pub static STYLE: &LintGroup = &LintGroup {
name: "bevy::style",
level: Level::Warn,
};
declare_group! {
/// A group that suggests how to increase the performance of your code.
pub static PERFORMANCE = {
name: "bevy::performance",
level: Level::Warn,
};
}

/// A group of lints that make the linter incredibly nit-picky.
///
/// If you enable this group, expect to liberally apply `#[allow(...)]` attributes throughout your
/// code.
pub static PEDANTIC: &LintGroup = &LintGroup {
name: "bevy::pedantic",
level: Level::Allow,
};
declare_group! {
/// A group of lints that encourage idiomatic code.
///
/// These lints are opinionated and may be freely disabled if you disagree with their suggestions.
pub static STYLE = {
name: "bevy::style",
level: Level::Warn,
};
}

/// A group of opt-in lints that restrict you from writing certain code.
///
/// These are designed for scenarios where you want to increase the consistency of your code-base
/// and reject certain patterns. They should not all be enabled at once, but instead specific lints
/// should be individually enabled.
pub static RESTRICTION: &LintGroup = &LintGroup {
name: "bevy::restriction",
level: Level::Allow,
};
declare_group! {
/// A group of lints that make the linter incredibly nit-picky.
///
/// If you enable this group, expect to liberally apply `#[allow(...)]` attributes throughout your
/// code.
pub static PEDANTIC = {
name: "bevy::pedantic",
level: Level::Allow,
};
}

/// A group of unstable lints that may be removed at any time for any reason.
pub static NURSERY: &LintGroup = &LintGroup {
name: "bevy::nursery",
level: Level::Allow,
};
declare_group! {
/// A group of opt-in lints that restrict you from writing certain code.
///
/// These are designed for scenarios where you want to increase the consistency of your code-base
/// and reject certain patterns. They should not all be enabled at once, but instead specific lints
/// should be individually enabled.
pub static RESTRICTION = {
name: "bevy::restriction",
level: Level::Allow,
};
}

declare_group! {
/// A group of unstable lints that may be removed at any time for any reason.
pub static NURSERY = {
name: "bevy::nursery",
level: Level::Allow,
};
}

/// A list of all [`LintGroup`]s.
///
/// If a group is not in this list, it will not be registered in [`register_groups()`].
static GROUPS: &[&LintGroup] = &[
CORRECTNESS,
SUSPICIOUS,
Expand All @@ -77,6 +129,7 @@ static GROUPS: &[&LintGroup] = &[
NURSERY,
];

/// Registers all [`LintGroup`]s in [`GROUPS`] with the [`LintStore`].
pub(crate) fn register_groups(store: &mut LintStore) {
for &group in GROUPS {
let lints = LINTS
Expand Down
5 changes: 5 additions & 0 deletions bevy_lint/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! `bevy_lint` is a Rust linter for the [Bevy game engine](https://bevyengine.org).
//!
//! This is the primary documentation for its supported lints and lint groups. It is not intended
//! to be consumed as a library.
// Enables linking to `rustc` crates.
#![feature(rustc_private)]
// Allows chaining `if let` multiple times using `&&`.
Expand Down
9 changes: 9 additions & 0 deletions bevy_lint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ macro_rules! declare_bevy_lint {
$group:ident,
$desc:expr$(,)?
} => {
/// Click me for more information.
///
/// ```ignore
/// Lint {
#[doc = concat!(" name: \"bevy::", stringify!($name), "\",")]
#[doc = concat!(" group: ", stringify!($group), ",")]
#[doc = concat!(" description: ", stringify!($desc), ",")]
/// }
/// ```
$(#[$attr])*
$vis static $name: &$crate::lint::BevyLint = &$crate::lint::BevyLint {
lint: &::rustc_lint::Lint {
Expand Down
16 changes: 10 additions & 6 deletions bevy_lint/src/lints/missing_reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,18 @@ impl TraitType {
_ => return None,
};

// Find the `HirId` from the `DefId`. This is like a `DefId`, but with further
// Tries to convert the `DefId` to a `LocalDefId`, exiting early if it cannot be done.
// This will only work if `T` in `impl T` is defined within the same crate.
//
// In most cases this will succeed due to Rust's orphan rule, but it notably fails
// within `bevy_reflect` itself, since that crate implements `Reflect` for `std` types
// such as `String`.
let local_def_id = def_id.as_local()?;

// Find the `HirId` from the `LocalDefId`. This is like a `DefId`, but with further
// constraints on what it can represent.
let hir_id = OwnerId {
// This is guaranteed to be a `LocalDefId` due to Rust's orphan rule. The traits
// (`Reflect`, `Component`, etc.) are from an external crate, so the type
// definition _must_ be local. The only case this may not be upheld is within
// Bevy's own crates.
def_id: def_id.expect_local(),
def_id: local_def_id,
}
.into();

Expand Down
4 changes: 4 additions & 0 deletions bevy_lint/src/lints/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! All lints offered by `bevy_lint`.
//!
//! Click on each module to learn more about individual lints.
use crate::lint::BevyLint;
use rustc_lint::{Lint, LintStore};

Expand Down

0 comments on commit f4a632a

Please sign in to comment.