Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Oct 29, 2021
1 parent 009bd8c commit f71cfc8
Show file tree
Hide file tree
Showing 24 changed files with 104 additions and 543 deletions.
1 change: 0 additions & 1 deletion crates/formatter/src/format_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ fn tokenize_node(node: SyntaxNode) -> FormatElement {
SyntaxKind::OBJECT_EXPR => {
let object = ObjectExpr::cast(node).unwrap();

dbg!(&object);
let separator = format_elements![token(","), soft_line_break_or_space()];

let properties_list: Vec<FormatElement> = object
Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/class/class_declarator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rslint_parser::ast::{ClassBody, ClassDecl, ClassElement, SuperCall};

impl ToFormatElement for ClassDecl {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
dbg!(self);
let class_token = formatter.format_token(&self.class_token()?)?;
let name = formatter.format_node(self.name()?)?;
let extends = if let Some(parent) = self.parent() {
Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/class/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ impl ToFormatElement for ConstructorParameters {

impl ToFormatElement for ConstructorParamOrPat {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
dbg!(self);
match self {
ConstructorParamOrPat::TsConstructorParam(_) => todo!(),
ConstructorParamOrPat::Pattern(pattern) => pattern.to_format_element(formatter),
Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/expressions/object_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rslint_parser::ast::ObjectExpr;

impl ToFormatElement for ObjectExpr {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
dbg!(self);
let separator = format_elements!(token(","), soft_line_break_or_space());
let props = formatter.format_children(self.props())?;

Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mod test {
let src = r#"let a1 = [{}, {}];
"#;
let tree = parse_text(src, 0);
dbg!(&tree.syntax());
let result = Formatter::default().format_root(&tree.syntax());
assert_eq!(
result.code(),
Expand Down
2 changes: 1 addition & 1 deletion crates/formatter/src/ts/props/literal_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use rslint_parser::ast::LiteralProp;
impl ToFormatElement for LiteralProp {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
let key = formatter.format_node(self.key()?)?;
let value = formatter.format_node(self.value()?)?;
let colon = formatter.format_token(&self.colon_token()?)?;
let value = formatter.format_node(self.value()?)?;
Some(format_elements![key, colon, space_token(), value])
}
}
1 change: 0 additions & 1 deletion crates/formatter/src/ts/statements/continue_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rslint_parser::ast::ContinueStmt;
impl ToFormatElement for ContinueStmt {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
// NOTE: rslint parser (upstream) is currently broken https://github.com/rslint/rslint/issues/126
dbg!(self);
let ident = if let Some(name_ref) = self.name_ref() {
format_elements![space_token(), formatter.format_node(name_ref)?]
} else {
Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/statements/expression_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{format_elements, token, FormatElement, Formatter, ToFormatElement};

impl ToFormatElement for ExprStmt {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
dbg!(self);
Some(format_elements![
formatter.format_node(self.expr()?)?,
token(";")
Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/statements/for_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rslint_parser::ast::{ForHead, ForStmt, ForStmtInit, ForStmtTest, ForStmtUpda
impl ToFormatElement for ForStmt {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
let inner = if self.init().is_some() || self.test().is_some() || self.update().is_some() {
dbg!(self);
let mut inner = vec![];
if let Some(init) = self.init() {
inner.push(formatter.format_node(init)?);
Expand Down
1 change: 0 additions & 1 deletion crates/formatter/src/ts/statements/switch_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rslint_parser::ast::{CaseClause, DefaultClause, SwitchCase, SwitchStmt};

impl ToFormatElement for SwitchStmt {
fn to_format_element(&self, formatter: &Formatter) -> Option<FormatElement> {
dbg!(self);
let switch = formatter.format_token(&self.switch_token()?)?;
let condition = formatter.format_node(self.test()?)?;
let l_curly = formatter.format_token(&self.l_curly_token()?)?;
Expand Down
1 change: 0 additions & 1 deletion crates/rslint_errors/src/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl Formatter for ShortFormatter {
ids.insert(d.file_id);
});
for id in ids {
dbg!(id);
let cur_diags = diagnostics
.iter()
.filter(|x| x.file_id == id && x.primary.is_some())
Expand Down
2 changes: 0 additions & 2 deletions crates/rslint_parser/src/ast/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ impl Literal {
}

pub fn kind(&self) -> LiteralKind {
dbg!(self.token().kind());
match self.token().kind() {
T![null] => LiteralKind::Null,
NUMBER => match parse_js_num(self.to_string()).unwrap() {
Expand Down Expand Up @@ -490,7 +489,6 @@ impl Literal {

impl ArrowExpr {
pub fn body(&self) -> Option<ExprOrBlock> {
dbg!("here", self.syntax().children().last());
ExprOrBlock::cast(self.syntax().children().last()?)
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/rslint_parser/src/ast/generated/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ pub struct DotExpr {
pub(crate) syntax: SyntaxNode,
}
impl DotExpr {
pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
pub fn object(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T ! [.]) }
pub fn prop(&self) -> Option<Name> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct NewExpr {
Expand Down Expand Up @@ -635,9 +638,9 @@ impl FnExpr {
pub fn name(&self) -> Option<Name> { support::child(&self.syntax) }
pub fn type_params(&self) -> Option<TsTypeParams> { support::child(&self.syntax) }
pub fn parameters(&self) -> Option<ArgList> { support::child(&self.syntax) }
pub fn body(&self) -> Option<BlockStmt> { support::child(&self.syntax) }
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T ! [:]) }
pub fn return_type(&self) -> Option<TsType> { support::child(&self.syntax) }
pub fn body(&self) -> Option<BlockStmt> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ClassExpr {
Expand Down
42 changes: 42 additions & 0 deletions crates/rslint_parser/src/ast/generated/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,45 @@ impl AstToken for Number {
}
fn syntax(&self) -> &SyntaxToken { &self.syntax }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Whitespace {
pub(crate) syntax: SyntaxToken,
}
impl std::fmt::Display for Whitespace {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.syntax, f)
}
}
impl AstToken for Whitespace {
fn can_cast(kind: SyntaxKind) -> bool { kind == WHITESPACE }
fn cast(syntax: SyntaxToken) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxToken { &self.syntax }
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Comment {
pub(crate) syntax: SyntaxToken,
}
impl std::fmt::Display for Comment {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.syntax, f)
}
}
impl AstToken for Comment {
fn can_cast(kind: SyntaxKind) -> bool { kind == COMMENT }
fn cast(syntax: SyntaxToken) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxToken { &self.syntax }
}
6 changes: 0 additions & 6 deletions crates/rslint_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ pub use rslint_syntax::*;
/// It also includes labels and possibly notes
pub type ParserError = rslint_errors::Diagnostic;

pub enum SyntaxError {
MissingElement,
}

pub type SyntaxResult<Node> = Result<Node, SyntaxError>;

use std::ops::Range;

/// Abstracted token for `TokenSource`
Expand Down
3 changes: 0 additions & 3 deletions crates/syntax/examples/log_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ fn main() {
log_attr(n);
}
}

dbg!(tree.to_string());
}

fn log_attr(n: SyntaxNode) -> Option<()> {
let attr = ast::JsxAttribute::cast(n)?;
dbg!(attr);
None
}
3 changes: 1 addition & 2 deletions crates/syntax/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ fn main() -> Result<()> {
};

let src = std::fs::read_to_string(path)?;
let tree = syntax::parse(&src, language)?;
let _tree = syntax::parse(&src, language)?;

dbg!(tree);
Ok(())
}
Loading

0 comments on commit f71cfc8

Please sign in to comment.