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

Stdin doesn't lint #83

Closed
jmmendivil opened this issue Aug 7, 2020 · 5 comments
Closed

Stdin doesn't lint #83

jmmendivil opened this issue Aug 7, 2020 · 5 comments

Comments

@jmmendivil
Copy link

jmmendivil commented Aug 7, 2020

Hey, thank you, great project.

I would like to use it with ale (vim) for asynchronous lint, but it seems stdin isn't working as expected.

simple.ts

type Foo = {
  x: string
}

const f: Foo = {
  x: 'bar'
};

Output from ts-standard ./src/simple.ts

ts-standard: Typescript Standard Style! (https://github.com/toddbluhm/ts-standard)
ts-standard: Run `ts-standard --fix` to automatically fix some problems.
  /Users/jm/lint-test/src/simple.ts:1:6: Use an `interface` instead of a `type`. (@typescript-eslint/consistent-type-definitions)
  /Users/jm/lint-test/src/simple.ts:5:7: 'f' is assigned a value but never used. (@typescript-eslint/no-unused-vars)
  /Users/jm/lint-test/src/simple.ts:7:2: Extra semicolon. (@typescript-eslint/semi)

All fine.

But if I do cat ./src/simple.ts | ts-standard --stdin

(node:17421) ExperimentalWarning: Readable[Symbol.asyncIterator] is an experimental feature. This feature could change at any time
ts-standard: Typescript Standard Style! (https://github.com/toddbluhm/ts-standard)
  <text>:1:6: Parsing error: Unexpected token Foo ()

Am I missing something?

macos 10.15.4
node v10.15.1
npm 6.14.7

@toddbluhm
Copy link
Collaborator

Thanks for the bug report. This is related to typescript-eslint/typescript-eslint#885

It seems I overlooked implementing the --stdin-filename flag. I have implemented the flag in #92 and confirmed that --stdin with --stdin-filename works. The CLI now also exits with an error if you try to use --stdin without the --stdin-filename flag.

My setup was as follows:

Folder structure

src/simple.ts
package.json
tsconfig.eslint.json
tsconfig.json

My tsconfig.json and tsconfig.eslint.json files uses src/**/* for includes.

In package.json I had the following script:
cat ./src/simple.ts | ts-standard --stdin --stdin-filename ./src/simple.ts

I also testing out the --fix flag and confirmed that worked also by using this script:
cat ./src/simple.ts | ts-standard --stdin --stdin-filename ./src/simple.ts --fix | tee ./src/simple.ts

If you are still running into issues, I can post the full example project and/or provide more detailed specifics.

@toddbluhm
Copy link
Collaborator

I am so sorry for the delay on this! 10.0.0 has been released with a fix for this as well as a migration to the official standard org.

@lorenzogrv
Copy link

@toddbluhm I've found this while trying to configure ALE to use ts-standard rather than standard for typescript files. Is the ts-standard --stdin interface fully compatible with standard counterpart?

Thx and keep up the good work ;)

@toddbluhm
Copy link
Collaborator

@lorenzogrv The interface should be fully compatible with the exception that the --stdin-filename flag with the file path needs to also be provided.

The typescript compiler/linter requires the path in order to properly lint the file (it still uses the stdin data for linting and outputs to stdout but the parser underneath requires the file path). I was unable to find a way around this requirement. If you are unable to provide the file path, then it will not work for your use case.

If --stdin is not working as expected, feel free to open a bug report for us to look into 😄 I do not actively use the --stdin flag so it could very well be broken.

@lorenzogrv
Copy link

@toddbluhm Thanks! Need to dig more, but knowing about --stdin-filename is useful information.

While I have been using JavaScript and standard for years, I'm a beginer within typescript, so will research more before opening a bug report. I'm sure the experimental setup I did for ALE is not correct. Anyway your clues about --stdin fragility may put me in the path to integrate successfully within my beloved vim.

Keep up the good work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants