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
Add support for loading custom formatter from package #6228
Add support for loading custom formatter from package #6228
Conversation
@meriouma Don't do squash and force push locally, keep the commits' history, that's fine. We'll merge with squash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good to me. I've left a suggestion for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggest] Sorry, I missed one point. Could you make single exporting consistent with other modules?
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggest] I think it's good to improve the CLI help and the doc about the --custom-formatter
option. It will support a package name, not only a relative/absolute file path.
Could you update also the following files?
Lines 178 to 180 in 743030d
--custom-formatter | |
Path to a JS file exporting a custom formatting function. |
The `formatter` Node.js API option can also accept a function, whereas the `--custom-formatter` CLI flag accepts a path to a JS file exporting one. The function in both cases must fit the signature described in the [Developer Guide](../../developer-guide/formatters.md). |
@meriouma Are you still working on this? |
@JounQin Yes, I will apply the changes. I stopped pushing changes yesterday so we were not two persons pushing in the branch at the same time. |
You'll only need to pull the latest codes and then continue the work. 🍺 |
@meriouma Thank you for addressing the requested changes! The PR looks almost good to me. I got an idea to test a custom formatter dependency in the repository: to install a private internal dependency. For example:
{
"devDependencies": {
"stylelint-test-custom-formatter": "file:packages/stylelint-test-custom-formatter"
}
}
$ tree packages
packages/
└── stylelint-test-custom-formatter/
├── index.js
└── package.json
1 directory, 2 files Run a test: $ bin/stylelint.js --config=scripts/visual-config.json --custom-formatter=stylelint-test-custom-formatter scripts/*.css
Custom formatter reports 1 warning(s).% What do you think about this idea? |
@ybiquitous |
@JounQin I thought about how to test the dependency behavior without mocking. But mocking dependency resolution in |
Yeah, a mock module like https://github.com/stylelint/stylelint/blob/main/lib/__tests__/__mocks__/get-stdin.js is fine IMO. (Besides, https://github.com/stylelint/stylelint/blob/main/lib/__tests__/__mocks__/get-stdin.js seems can be deleted safely in favor of #6182, see #6233 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! LGTM 👍🏼
@meriouma Thanks for your contribution! |
Changelog entry added:
|
Closes #6100
No, it's self-explanatory.