Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(www): playground #1182

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 90 additions & 10 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude = [

[lib]
name = "deno_lint"
crate-type = ["cdylib", "rlib"]

[[example]]
name = "dlint"
Expand All @@ -23,6 +24,7 @@ test = true
[features]
default = []
docs = []
wasm = ["wasm-bindgen", "wee_alloc", "miette"]

[dependencies]
deno_ast = { version = "0.27.0", features = ["scopes", "transforms", "utils", "visit", "view", "module_specifier"] }
Expand All @@ -34,14 +36,16 @@ once_cell = "1.10.0"
derive_more = { version = "0.99.17", features = ["display"] }
anyhow = "1.0.56"
if_chain = "1.0.2"
wasm-bindgen = { version = "0.2", optional = true }
wee_alloc = { version = "0.4", optional = true }
miette = { version = "4.3.0", features = ["fancy-no-backtrace"], optional = true }

[dev-dependencies]
ansi_term = "0.12.1"
atty = "0.2.14"
clap = { version = "3", features = ["cargo"] }
env_logger = "0.9.0"
globwalk = "0.8.1"
miette = { version = "4.3.0", features = ["fancy-no-backtrace"] }
os_pipe = "1.0.1"
pulldown-cmark = "0.9.1"
rayon = "1.5.1"
Expand Down
13 changes: 5 additions & 8 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::diagnostic::{LintDiagnostic, Position, Range};
use crate::ignore_directives::{
CodeStatus, FileIgnoreDirective, LineIgnoreDirective,
};
use crate::perf::Perf;
use crate::rules::{self, get_all_rules, LintRule};
use deno_ast::swc::common::comments::Comment;
use deno_ast::swc::common::SyntaxContext;
Expand All @@ -15,8 +16,6 @@ use deno_ast::{
};
use std::collections::{HashMap, HashSet};

use std::time::Instant;

/// `Context` stores data needed while performing all lint rules to a file.
pub struct Context<'view> {
parsed_source: ParsedSource,
Expand Down Expand Up @@ -324,7 +323,8 @@ impl<'view> Context<'view> {
message: impl ToString,
maybe_hint: Option<String>,
) -> LintDiagnostic {
let time_start = Instant::now();
let mut perf = Perf::start();

let text_info = self.text_info();
let start = Position::new(
range.start.as_byte_index(text_info.range().start),
Expand All @@ -343,11 +343,8 @@ impl<'view> Context<'view> {
hint: maybe_hint,
};

let time_end = Instant::now();
debug!(
"Context::create_diagnostic took {:?}",
time_end - time_start
);
perf.mark("Context::create_diagnostic");

diagnostic
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#![deny(clippy::disallowed_methods)]
#![deny(clippy::disallowed_types)]

#[macro_use]
extern crate log;

#[cfg(test)]
#[macro_use]
mod test_util;
Expand All @@ -19,11 +16,16 @@ mod handler;
mod ignore_directives;
mod js_regex;
pub mod linter;
mod perf;
pub mod rules;
pub mod swc_util;
#[cfg(feature = "wasm")]
pub mod wasm;

pub use deno_ast::view::Program;
pub use deno_ast::view::ProgramRef;
#[cfg(feature = "wasm")]
pub use wasm::run;

#[cfg(test)]
mod lint_tests {
Expand Down
33 changes: 14 additions & 19 deletions src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use crate::diagnostic::LintDiagnostic;
use crate::ignore_directives::{
parse_file_ignore_directives, parse_line_ignore_directives,
};
use crate::perf::Perf;
use crate::rules::{ban_unknown_rule_code::BanUnknownRuleCode, LintRule};
use deno_ast::Diagnostic;
use deno_ast::MediaType;
use deno_ast::ParsedSource;
use deno_ast::Scope;

use std::time::Instant;

pub struct LinterBuilder {
ignore_file_directive: String,
ignore_diagnostic_directive: String,
Expand Down Expand Up @@ -102,39 +101,36 @@ impl Linter {
file_name: String,
source_code: String,
) -> Result<(ParsedSource, Vec<LintDiagnostic>), Diagnostic> {
let start = Instant::now();
let mut perf = Perf::start();

let syntax = deno_ast::get_syntax(self.media_type);
let parse_result = parse_program(&file_name, syntax, source_code);

let end_parse_program = Instant::now();
debug!(
"ast_parser.parse_program took {:#?}",
end_parse_program - start
);
perf.mark("ast_parser.parse_program");

let parsed_source = parse_result?;
let diagnostics = self.lint_program(&parsed_source);

let end = Instant::now();
debug!("Linter::lint took {:#?}", end - start);
perf.mark("Linter::lint");

Ok((parsed_source, diagnostics))
}

pub fn lint_with_ast(
mut self,
parsed_source: &ParsedSource,
) -> Vec<LintDiagnostic> {
let start = Instant::now();
let mut perf = Perf::start();

let diagnostics = self.lint_program(parsed_source);
let end = Instant::now();
debug!("Linter::lint_with_ast took {:#?}", end - start);

perf.mark("Linter::lint_with_ast");

diagnostics
}

fn filter_diagnostics(&self, mut context: Context) -> Vec<LintDiagnostic> {
let start = Instant::now();
let mut perf = Perf::start();

let mut filtered_diagnostics = context.check_ignore_directive_usage();
// Run `ban-unknown-rule-code`
Expand All @@ -143,8 +139,7 @@ impl Linter {
filtered_diagnostics.extend(context.ban_unused_ignore(&self.rules));
filtered_diagnostics.sort_by_key(|d| d.range.start.line_index);

let end = Instant::now();
debug!("Linter::filter_diagnostics took {:#?}", end - start);
perf.mark("Linter::filter_diagnostics");

filtered_diagnostics
}
Expand All @@ -153,7 +148,8 @@ impl Linter {
&mut self,
parsed_source: &ParsedSource,
) -> Vec<LintDiagnostic> {
let start = Instant::now();
let mut perf = Perf::start();

let check_unknown_rules = self
.rules
.iter()
Expand Down Expand Up @@ -196,8 +192,7 @@ impl Linter {
self.filter_diagnostics(context)
});

let end = Instant::now();
debug!("Linter::lint_module took {:#?}", end - start);
perf.mark("Linter::lint_program");

diagnostics
}
Expand Down
Loading