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

doesn't work correctly with --stdin and pretty-error #739

Open
zakkie opened this issue Jan 27, 2021 · 1 comment
Open

doesn't work correctly with --stdin and pretty-error #739

zakkie opened this issue Jan 27, 2021 · 1 comment
Labels
Type: Bug Bug or Bug fixes

Comments

@zakkie
Copy link

zakkie commented Jan 27, 2021

unhandled exception occurred when --stdin and pretty-error:

$ textlint --rule no-todo --stdin --stdin-filename foo.md -f pretty-error < /tmp/foo.md
✖ Error
ENOENT: no such file or directory, open '<markdown>'

✖ Stack trace
Error: ENOENT: no such file or directory, open '<markdown>'
    at Object.openSync (node:fs:490:3)
    at Object.readFileSync (node:fs:391:35)
    at /usr/local/lib/node_modules/textlint/node_modules/@textlint/linter-formatter/lib/formatters/pretty-error.js:116:34
    at Array.forEach (<anonymous>)
    at formatter (/usr/local/lib/node_modules/textlint/node_modules/@textlint/linter-formatter/lib/formatters/pretty-error.js:115:13)
    at /usr/local/lib/node_modules/textlint/node_modules/@textlint/linter-formatter/lib/index.js:43:16
    at TextLintEngine.AbstractTextLintEngine.formatResults (/usr/local/lib/node_modules/textlint/lib/engine/textlint-engine-core.js:252:16)
    at /usr/local/lib/node_modules/textlint/lib/cli.js:211:37
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

$ cat /tmp/foo.md
- [ ] foo
- bar

$ textlint -v
v11.8.1
$ node -v
v15.6.0

It works fine if specified the file path directly:

$ textlint --rule no-todo /tmp/foo.md -f pretty-error < /tmp/foo.md
no-todo: Found TODO: '- [ ] foo'
/tmp/foo.md:1:3
         v
    0.
    1. - [ ] foo
    2. - bar
         ^

✖ 1 problem (1 error, 0 warnings)

Also it works fine if without -f pretty-error option:

$ textlint --rule no-todo --stdin --stdin-filename foo.md  < /tmp/foo.md

<markdown>
  1:3  error  Found TODO: '- [ ] foo'  no-todo

✖ 1 problem (1 error, 0 warnings)
@azu
Copy link
Member

azu commented Jan 28, 2021

Thanks for the report.

It is an expected error because pretty-error read file content using filePath of TextlintResult.

const code = require("fs").readFileSync(result.filePath, "utf-8");

Current TextlintResult does not include actual file content.

export interface TextlintMessage {
// See src/shared/type/MessageType.js
// Message Type
type: string;
// Rule Id
ruleId: string;
message: string;
// optional data
data?: any;
// FixCommand
fix?: TextlintMessageFixCommand;
// location info
// Text -> AST TxtNode(0-based columns) -> textlint -> TextlintMessage(**1-based columns**)
line: number; // start with 1
column: number; // start with 1
// indexed-location
index: number; // start with 0
// Severity Level
// See src/shared/type/SeverityLevel.js
severity: number;
}
// Linting result
export interface TextlintResult {
filePath: string;
messages: TextlintMessage[];
}

So, It is a current limitation.

We have two options for improving this error.

  1. Improve error message(show a message that it is the limitation)
  2. Fix to work pretty-error with --stdin

2 is ideal, but It means that add file content to TextlintResult like ESLint's source.
I concerned that TextlintResult output is going to be bigger.

I have not an actual use case that adds file content to TextlintResult, so I did not implement -f pretty-error with --stdion.(There is a workaround that just use textlint -f pretty-error /path/to/file)

If there is another use-case, I'm ok that implement 2 of the options.

@azu azu added the Type: Bug Bug or Bug fixes label Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants