standard / ts-standard

Typescript style guide, linter, and formatter using StandardJS
https://www.npmjs.com/package/ts-standard
MIT License
473 stars 36 forks source link

Stdin doesn't lint #83

Closed jmmendivil closed 3 years ago

jmmendivil commented 4 years ago

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 commented 4 years ago

Thanks for the bug report. This is related to https://github.com/typescript-eslint/typescript-eslint/issues/885

It seems I overlooked implementing the --stdin-filename flag. I have implemented the flag in https://github.com/toddbluhm/ts-standard/pull/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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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 :+1: