-
-
Notifications
You must be signed in to change notification settings - Fork 442
/
indent_size.rs
66 lines (58 loc) · 1.93 KB
/
indent_size.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::{declare_migration, MigrationAction};
use biome_analyze::context::RuleContext;
use biome_analyze::{ActionCategory, Ast, Rule, RuleAction, RuleDiagnostic};
use biome_console::markup;
use biome_diagnostics::{category, Applicability};
use biome_json_analyze::utils::matches_path;
use biome_json_factory::make::{ident, json_member_name};
use biome_json_syntax::JsonMemberName;
use biome_rowan::{AstNode, BatchMutationExt};
declare_migration! {
pub(crate) IndentSize {
version: "1.3.0",
name: "indentSize",
}
}
impl Rule for IndentSize {
type Query = Ast<JsonMemberName>;
type State = ();
type Signals = Option<Self::State>;
type Options = ();
fn run(ctx: &RuleContext<Self>) -> Self::Signals {
let node = ctx.query();
if matches_path(Some(node), &["formatter", "indentSize"]) {
Some(())
} else {
None
}
}
fn diagnostic(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<RuleDiagnostic> {
let node = ctx.query();
Some(
RuleDiagnostic::new(
category!("migrate"),
node.range(),
markup! {
"The option "<Emphasis>"formatter.indentSize"</Emphasis>" is deprecated."
}
.to_owned(),
)
.deprecated(),
)
}
fn action(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<MigrationAction> {
let node = ctx.query();
let mut mutation = ctx.root().begin();
let new_node = json_member_name(ident("\"indentWidth\""));
mutation.replace_node(node.clone(), new_node);
Some(RuleAction::new(
ActionCategory::QuickFix,
Applicability::Always,
markup! {
"Use the property "<Emphasis>"formatter.indentWidth"</Emphasis>" instead."
}
.to_owned(),
mutation,
))
}
}