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(cli/lint): Add support for reading input from stdin #7263

Merged
merged 5 commits into from
Aug 31, 2020

Conversation

magurotuna
Copy link
Member

Resolves #7218

Given the following file named file.ts

let a: any;

then we can lint it in two ways:

  1. deno lint --unstable file.ts
  2. cat file.ts | deno lint --unstable - (new!)

I also added integration tests and updated the doc.

My concerns:

  • As I commented to lint_stdin, all inputs from stdin are treated as TypeScript. Should some flag like --ext be added to handle other types? (something like cat file.jsx | deno lint --unstable - --ext=jsx)
  • The linter requires file_name so I put it as _stdin.ts for now, referring to

    deno/cli/fmt.rs

    Line 179 in 9bfb0df

    match formatter.format_text(&PathBuf::from("_stdin.ts"), &source) {
    I wonder if there is a preferrable file name.

@bartlomieju
Copy link
Member

  • As I commented to lint_stdin, all inputs from stdin are treated as TypeScript. Should some flag like --ext be added to handle other types? (something like cat file.jsx | deno lint --unstable - --ext=jsx)

That's okay

The linter requires file_name so I put it as _stdin.ts for now, referring to

That's also okay

cli/lint.rs Outdated Show resolved Hide resolved
Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @magurotuna, this PR brings us closer to VSCode integration.

Comment on lines +2256 to +2269
itest!(deno_lint_from_stdin {
args: "lint --unstable -",
input: Some("let a: any;"),
output: "lint/expected_from_stdin.out",
exit_code: 1,
});

itest!(deno_lint_from_stdin_json {
args: "lint --unstable --json -",
input: Some("let a: any;"),
output: "lint/expected_from_stdin_json.out",
exit_code: 1,
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tests

@bartlomieju bartlomieju added this to the 1.4.0 milestone Aug 31, 2020
@ry
Copy link
Member

ry commented Aug 31, 2020

Since lint is marked unstable, I think we can land this now.

@bartlomieju bartlomieju removed this from the 1.4.0 milestone Aug 31, 2020
@bartlomieju bartlomieju merged commit fa65e49 into denoland:master Aug 31, 2020
@magurotuna magurotuna deleted the lint-stdin branch August 31, 2020 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deno lint command support read file from stdin like deno fmt
3 participants