forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lint): use default globs, upgrade to v0.1.9 (denoland#6222)
This commit: * added default file globs so "deno lint" can be run without arguments (just like "deno fmt") * added test for globs in "deno lint" * upgrade "deno_lint" crate to v0.1.9
- Loading branch information
1 parent
e53a1b1
commit e4e332a
Showing
12 changed files
with
165 additions
and
101 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. | ||
|
||
//! This module provides file formating utilities using | ||
//! [`deno_lint`](https://github.com/denoland/deno_lint). | ||
//! | ||
//! At the moment it is only consumed using CLI but in | ||
//! the future it can be easily extended to provide | ||
//! the same functions as ops available in JS runtime. | ||
|
||
use crate::colors; | ||
use crate::file_fetcher::map_file_extension; | ||
use crate::fmt::collect_files; | ||
use crate::fmt_errors; | ||
use crate::swc_util; | ||
use deno_core::ErrBox; | ||
use deno_lint::diagnostic::LintDiagnostic; | ||
use deno_lint::linter::Linter; | ||
use deno_lint::rules; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
pub fn lint_files(args: Vec<String>) -> Result<(), ErrBox> { | ||
let target_files = collect_files(args)?; | ||
|
||
let mut error_counts = 0; | ||
|
||
for file_path in target_files { | ||
let file_diagnostics = lint_file(file_path)?; | ||
error_counts += file_diagnostics.len(); | ||
for d in file_diagnostics.iter() { | ||
let fmt_diagnostic = format_diagnostic(d); | ||
eprintln!("{}\n", fmt_diagnostic); | ||
} | ||
} | ||
|
||
if error_counts > 0 { | ||
eprintln!("Found {} problems", error_counts); | ||
std::process::exit(1); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn lint_file(file_path: PathBuf) -> Result<Vec<LintDiagnostic>, ErrBox> { | ||
let file_name = file_path.to_string_lossy().to_string(); | ||
let source_code = fs::read_to_string(&file_path)?; | ||
let media_type = map_file_extension(&file_path); | ||
let syntax = swc_util::get_syntax_for_media_type(media_type); | ||
|
||
let mut linter = Linter::default(); | ||
let lint_rules = rules::get_recommended_rules(); | ||
|
||
let file_diagnostics = | ||
linter.lint(file_name, source_code, syntax, lint_rules)?; | ||
|
||
Ok(file_diagnostics) | ||
} | ||
|
||
fn format_diagnostic(d: &LintDiagnostic) -> String { | ||
let pretty_message = format!( | ||
"({}) {}", | ||
colors::gray(d.code.to_string()), | ||
d.message.clone() | ||
); | ||
|
||
fmt_errors::format_stack( | ||
true, | ||
pretty_message, | ||
Some(d.line_src.clone()), | ||
Some(d.location.col as i64), | ||
Some((d.location.col + d.snippet_length) as i64), | ||
&[fmt_errors::format_location( | ||
d.location.filename.clone(), | ||
d.location.line as i64, | ||
d.location.col as i64, | ||
)], | ||
0, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[WILDCARD] | ||
Found 5 problems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
var a = 1, | ||
b = 2, | ||
c = 3; | ||
// deno-lint-ignore | ||
while (false) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[WILDCARD] | ||
|
||
Found [WILDCARD] problems |