summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
authorBrenley Dueck <brenleydueck@gmail.com>2022-09-28 11:47:48 -0500
committerGitHub <noreply@github.com>2022-09-28 18:47:48 +0200
commit23125b275f282f96a6316d11f97e5603dab0d009 (patch)
tree374ef90c365657aca64c58ecb007ce510472ab24 /cli/tools
parent9c861ec4301397456e249923c881d9d3b56651f4 (diff)
feat(lint): add --compact flag for terse output (#15926)
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/lint.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/cli/tools/lint.rs b/cli/tools/lint.rs
index da5df3a81..9afc9cd46 100644
--- a/cli/tools/lint.rs
+++ b/cli/tools/lint.rs
@@ -49,12 +49,14 @@ static STDIN_FILE_NAME: &str = "_stdin.ts";
pub enum LintReporterKind {
Pretty,
Json,
+ Compact,
}
fn create_reporter(kind: LintReporterKind) -> Box<dyn LintReporter + Send> {
match kind {
LintReporterKind::Pretty => Box::new(PrettyLintReporter::new()),
LintReporterKind::Json => Box::new(JsonLintReporter::new()),
+ LintReporterKind::Compact => Box::new(CompactLintReporter::new()),
}
}
@@ -66,6 +68,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
files: args,
ignore,
json,
+ compact,
..
} = lint_flags;
// First, prepare final configuration.
@@ -104,6 +107,8 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
let reporter_kind = if json {
LintReporterKind::Json
+ } else if compact {
+ LintReporterKind::Compact
} else {
LintReporterKind::Pretty
};
@@ -413,6 +418,50 @@ impl LintReporter for PrettyLintReporter {
}
}
+struct CompactLintReporter {
+ lint_count: u32,
+}
+
+impl CompactLintReporter {
+ fn new() -> CompactLintReporter {
+ CompactLintReporter { lint_count: 0 }
+ }
+}
+
+impl LintReporter for CompactLintReporter {
+ fn visit_diagnostic(&mut self, d: &LintDiagnostic, _source_lines: Vec<&str>) {
+ self.lint_count += 1;
+
+ eprintln!(
+ "{}: line {}, col {} - {} ({})",
+ d.filename,
+ d.range.start.line_index + 1,
+ d.range.start.column_index + 1,
+ d.message,
+ d.code
+ )
+ }
+
+ fn visit_error(&mut self, file_path: &str, err: &AnyError) {
+ eprintln!("Error linting: {}", file_path);
+ eprintln!(" {}", err);
+ }
+
+ fn close(&mut self, check_count: usize) {
+ match self.lint_count {
+ 1 => info!("Found 1 problem"),
+ n if n > 1 => info!("Found {} problems", self.lint_count),
+ _ => (),
+ }
+
+ match check_count {
+ n if n <= 1 => info!("Checked {} file", n),
+ n if n > 1 => info!("Checked {} files", n),
+ _ => unreachable!(),
+ }
+ }
+}
+
pub fn format_diagnostic(
diagnostic_code: &str,
message_line: &str,