docs: update metadata of rules
MODIFY
CONTRIBUTING.md
CONTRIBUTING.md
@@ -177,7 +177,7 @@ When creating a new pull request, it's preferable to use a conventional commit-f
Here are some other scripts that you might find useful.
-#### Run benchmarks via comments
+#### If you are a core contributor
If you are a core contributor, and you have access to create new branches
from the main repository (not a fork), use these comments to run specific workflows:
@@ -188,6 +188,11 @@ from the main repository (not a fork), use these comments to run specific workfl
#### Creating rules
+When implementing **new rules**, they have to be implemented under the group `nursery`. New rules should
+always be considered unstable/not exhaustive.
+
+This gives to the project time to test the rule, find edge cases, etc.
+
When creating or updating lint rules, you need to be aware that there's a lot of generated code inside our toolchain, and
our CI makes sure that this code is not out of sync. If some autogenerated files are out of sync,
the CI will fail.
@@ -198,6 +203,7 @@ Run the following commands to update the generated files:
- `cargo codegen-bindings`, it will update the TypeScript types released inside the JS APIs;
- `cargo codegen-schema`, it will update the JSON Schema file of the configuration, used by VSCode;
+
#### Naming patterns for rules
1. Forbid a concept

MODIFY
crates/rome_cli/tests/configs.rs
crates/rome_cli/tests/configs.rs
@@ -133,7 +133,8 @@ pub const CONFIG_LINTER_UPGRADE_DIAGNOSTIC: &str = r#"{
"rules": {
"recommended": true,
"nursery": {
- "noUnreachable": "error"
+ "noUnreachable": "error",
+ "noUnusedVariables": "error"
}
}
}

MODIFY
crates/rome_cli/tests/snapshots/main_check/upgrade_severity.snap
crates/rome_cli/tests/snapshots/main_check/upgrade_severity.snap
@@ -10,7 +10,8 @@ expression: content
"rules": {
"recommended": true,
"nursery": {
- "noUnreachable": "error"
+ "noUnreachable": "error",
+ "noUnusedVariables": "error"
}
}
}

MODIFY
crates/rome_js_analyze/src/analyzers/nursery/no_new_symbol.rs
crates/rome_js_analyze/src/analyzers/nursery/no_new_symbol.rs
@@ -31,7 +31,7 @@ declare_rule! {
pub(crate) NoNewSymbol {
version: "0.10.0",
name: "noNewSymbol",
- recommended: true,
+ recommended: false,
}
}

MODIFY
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_unused_variables.rs
crates/rome_js_analyze/src/semantic_analyzers/nursery/no_unused_variables.rs
@@ -99,7 +99,7 @@ declare_rule! {
pub(crate) NoUnusedVariables {
version: "0.9.0",
name: "noUnusedVariables",
- recommended: true,
+ recommended: false,
}
}

MODIFY
crates/rome_service/src/configuration/linter/rules.rs
crates/rome_service/src/configuration/linter/rules.rs
@@ -400,11 +400,8 @@ impl Nursery {
"noUnusedVariables",
"useCamelCase",
];
- const RECOMMENDED_RULES: [&'static str; 2] = ["noNewSymbol", "noUnusedVariables"];
- const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 2] = [
- RuleFilter::Rule("nursery", Self::CATEGORY_RULES[0]),
- RuleFilter::Rule("nursery", Self::CATEGORY_RULES[2]),
- ];
+ const RECOMMENDED_RULES: [&'static str; 0] = [];
+ const RECOMMENDED_RULES_AS_FILTERS: [RuleFilter<'static>; 0] = [];
pub(crate) fn is_recommended(&self) -> bool { !matches!(self.recommended, Some(false)) }
pub(crate) fn get_enabled_rules(&self) -> IndexSet<RuleFilter> {
IndexSet::from_iter(self.rules.iter().filter_map(|(key, conf)| {
@@ -430,7 +427,7 @@ impl Nursery {
pub(crate) fn is_recommended_rule(rule_name: &str) -> bool {
Self::RECOMMENDED_RULES.contains(&rule_name)
}
- pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 2] {
+ pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 0] {
Self::RECOMMENDED_RULES_AS_FILTERS
}
}

MODIFY
rome.json
rome.json
"rules": {
"recommended": true,
"nursery": {
- "noUnreachable": "error"
+ "noUnreachable": "error",
+ "noUnusedVariables": "error",
+ "useCamelCase": "off"
}
}
}

MODIFY
website/api/server.js
website/api/server.js
@@ -17,10 +17,10 @@ const db = new pg.Client();
const stripe = require("stripe")(process.env.STRIPE_SECRET);
-let Sentry;
+let sentry;
if (process.env.SENTRY_DSN !== undefined) {
- Sentry = require("@sentry/node");
- Sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 1 });
+ sentry = require("@sentry/node");
+ sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 1 });
}
const tiers = [
@@ -491,8 +491,8 @@ app.post(
// rome-ignore lint(nursery/noUnusedVariables): false positive
app.use(function (err, req, res, next) {
// rome-ignore lint/js/preferOptionalChaining: netlify's node version does not support optional call expressions
- if (Sentry !== undefined) {
- Sentry.captureException(err);
+ if (sentry !== undefined) {
+ sentry.captureException(err);
}
console.error(err.stack);
res.status(500);
@@ -512,8 +512,8 @@ async function main() {
main().catch((err) => {
// rome-ignore lint/js/preferOptionalChaining: netlify's node version does not support optional call expressions
- if (Sentry !== undefined) {
- Sentry.captureException(err);
+ if (sentry !== undefined) {
+ sentry.captureException(err);
}
console.error(err.stack);
process.exit(1);

MODIFY
website/playground/package.json
website/playground/package.json
"build:wasm": "wasm-pack build --out-dir ../../npm/wasm-web --target web --release --scope rometools ../../crates/rome_wasm",
"build:wasm-dev": "wasm-pack build --out-dir ../../npm/wasm-web --target web --dev --scope rometools ../../crates/rome_wasm",
"format": "cargo rome-cli-dev format --write ./src",
- "format:rome": "rome format --write src .",
+ "check": "cargo rome-cli-dev check ./src",
"tsc": "tsc"
},
"dependencies": {

MODIFY
website/src/docs/lint/rules/index.md
website/src/docs/lint/rules/index.md
@@ -13,6 +13,8 @@ eleventyNavigation:
<section>
<h2>Correctness</h2>
+
+This group should includes those rules that are meant to prevent possible bugs and misuse of the language.
<div class="rule">
<h3 data-toc-exclude id="noArguments">
<a href="/docs/lint/rules/noArguments">noArguments (since v0.7.0)</a>
@@ -253,11 +255,15 @@ initializer and update expressions are not needed
</section>
<section>
<h2>Nursery</h2>
+
+Rules that are being written. Rules under this category are meant to be considered unstable or buggy.
+
+Rules can be downgraded to this category in case some path release is needed. After an arbitrary amount of time, the team can decide
+to promote these rules into a more appropriate category.
<div class="rule">
<h3 data-toc-exclude id="noNewSymbol">
<a href="/docs/lint/rules/noNewSymbol">noNewSymbol (since v0.10.0)</a>
<a class="header-anchor" href="#noNewSymbol"></a>
- <span class="recommended">recommended</span>
</h3>
Disallow <code>new</code> operators with the <code>Symbol</code> object
</div>
@@ -272,7 +278,6 @@ Disallow unreachable code
<h3 data-toc-exclude id="noUnusedVariables">
<a href="/docs/lint/rules/noUnusedVariables">noUnusedVariables (since v0.9.0)</a>
<a class="header-anchor" href="#noUnusedVariables"></a>
- <span class="recommended">recommended</span>
</h3>
Disallow unused variables.
</div>
@@ -286,6 +291,8 @@ Enforce camel case naming convention.
</section>
<section>
<h2>Style</h2>
+
+Rules that focus mostly on making the code more consistent.
<div class="rule">
<h3 data-toc-exclude id="noNegationElse">
<a href="/docs/lint/rules/noNegationElse">noNegationElse (since v0.7.0)</a>

MODIFY
xtask/lintdoc/src/main.rs
xtask/lintdoc/src/main.rs
@@ -2,7 +2,7 @@ use pulldown_cmark::{html::write_html, CodeBlockKind, Event, LinkType, Parser, T
use rome_analyze::{AnalysisFilter, ControlFlow, RuleCategories, RuleFilter};
use rome_console::{
fmt::{Formatter, HTML},
- markup,
+ markup, Markup,
};
use rome_diagnostics::{file::SimpleFile, Diagnostic};
use rome_js_analyze::{analyze, metadata};
@@ -71,15 +71,38 @@ fn main() -> Result<()> {
}
for (group, rules) in groups {
- let group_name = match group {
- "correctness" => "Correctness",
- "nursery" => "Nursery",
- "style" => "Style",
+ let (group_name, description) = match group {
+ "correctness" => (
+ "Correctness",
+ markup! {
+ "This group should includes those rules that are meant to prevent possible bugs and misuse of the language."
+ },
+ ),
+
+ "nursery" => (
+ "Nursery",
+ markup! {
+ "Rules that are being written. Rules under this category are meant to be considered unstable or buggy.
+
+Rules can be downgraded to this category in case some path release is needed. After an arbitrary amount of time, the team can decide
+to promote these rules into a more appropriate category."
+
+ },
+ ),
+ "style" => (
+ "Style",
+ markup! {
+ "Rules that focus mostly on making the code more consistent."
+ },
+ ),
_ => panic!("Unknown group ID {group:?}"),
};
writeln!(index, "<section>")?;
writeln!(index, "<h2>{group_name}</h2>")?;
+ writeln!(index)?;
+ markup_to_string(&mut index, description)?;
+ writeln!(index)?;
for (rule, meta) in rules {
let version = meta.version;
@@ -491,3 +514,9 @@ fn assert_lint(
Ok(())
}
+
+pub fn markup_to_string(buffer: &mut Vec<u8>, markup: Markup) -> io::Result<()> {
+ let mut write = HTML(buffer);
+ let mut fmt = Formatter::new(&mut write);
+ fmt.write_markup(markup)
+}

docs: update metadata of rules (#3215)