We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
What version of textlint are you using?
12.2.3
What file type (Markdown, plain text, etc.) are you using?
Markdown
What did you do? Please include the actual source code causing the issue.
It is convenient that textlint can load custom formatter via file.
textlint -f custom-formatter.js **/*.md
Source Code: https://github.com/takenspc/junit-reports/tree/textlint
What did you expect to happen?
texlint loads the formatter.
What actually happened? Please include the actual, raw output from textlint.
textlint failed to load the formatter.
Log of GitHub Actions: https://github.com/takenspc/junit-reports/actions/runs/3493635216/jobs/5848666329
Error Could not find formatter custom-formatter.js Error: Cannot find module 'custom-formatter.js' Require stack: - /home/runner/work/junit-reports/junit-reports/node_modules/@textlint/linter-formatter/lib/src/index.js - /home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/options.js - /home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/cli.js - /home/runner/work/junit-reports/junit-reports/node_modules/textlint/bin/textlint.js Stack trace Error: Could not find formatter custom-formatter.js Error: Cannot find module 'custom-formatter.js' Require stack: - /home/runner/work/junit-reports/junit-reports/node_modules/@textlint/linter-formatter/lib/src/index.js - /home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/options.js - /home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/cli.js - /home/runner/work/junit-reports/junit-reports/node_modules/textlint/bin/textlint.js at createFormatter (/home/runner/work/junit-reports/junit-reports/node_modules/@textlint/linter-formatter/lib/src/index.js:40:15) at TextLintEngine.onFormat (/home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/textlint-engine.js:48:59) at TextLintEngine.formatResults (/home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/engine/textlint-engine-core.js:239:32) at /home/runner/work/junit-reports/junit-reports/node_modules/textlint/lib/src/cli.js:221:39
textlint/packages/@textlint/linter-formatter/src/index.ts
Line 24 in 752d866
if (fs.existsSync(formatterName)) { formatterPath = formatterName; } // snip try { formatter = moduleInterop(require(formatterPath)); } catch (ex) { throw new Error(`Could not find formatter ${formatterName} ${ex}`); }
In most cases, fs.existsSync resolves relative paths using process.cwd() while require() resolves relative paths using __dirname.
fs.existsSync
process.cwd()
require()
__dirname
That is, existence of a relative path resolved using process.cwd() does not guarantee the relative path can be required.
require
One of possible solutions is changing
if (fs.existsSync(formatterName)) { formatterPath = formatterName;
to
if (fs.existsSync(path.resolve(__dirname, formatterName))) { formatterPath = path.resolve(__dirname, formatterName);
The text was updated successfully, but these errors were encountered:
Can you try next?
textlint -f ./custom-formatter.js **/*.md
📝 custom-formatter.js is valid npm module name.
custom-formatter.js
Sorry, something went wrong.
No branches or pull requests
What version of textlint are you using?
12.2.3
What file type (Markdown, plain text, etc.) are you using?
Markdown
What did you do? Please include the actual source code causing the issue.
It is convenient that textlint can load custom formatter via file.
Source Code: https://github.com/takenspc/junit-reports/tree/textlint
What did you expect to happen?
texlint loads the formatter.
What actually happened? Please include the actual, raw output from textlint.
textlint failed to load the formatter.
Log of GitHub Actions: https://github.com/takenspc/junit-reports/actions/runs/3493635216/jobs/5848666329
Related codes
textlint/packages/@textlint/linter-formatter/src/index.ts
Line 24 in 752d866
In most cases,
fs.existsSync
resolves relative paths usingprocess.cwd()
whilerequire()
resolves relative paths using__dirname
.That is, existence of a relative path resolved using
process.cwd()
does not guarantee the relative path can berequire
d.One of possible solutions is changing
to
The text was updated successfully, but these errors were encountered: