Open NickHeiner opened 5 years ago
npm is the default; any user of yarn always has to implicitly know how to convert npm commands into yarn commands - that's just the cost of using yarn.
I think that's an inflexible and user-unfriendly approach; my project has some contributors who are less familiar with the Node ecosystem. And more broadly, I don't like giving anyone an error message that's explicitly the wrong thing to do. So, as-is, I can't use this project.
What if I submitted a PR allowing the user to override the error message entirely via rule config?
I might except an option to override the install command specifically - but in general, people unfamliar with the node ecosystem can't really avoid needing to learn it in order to contribute. Also, if your goal is "user friendly", then you'd use npm, since it's the default.
Also, if your goal is "user friendly", then you'd use npm, since it's the default.
I see your point, but I'm not going to derail this into an npm v. yarn debate. :smile:
I might except an option to override the install command specifically
That would be perfect. For instance, I'd also override it in my case to be the workspace-aware command.
Seems reasonable. If there’s more than one rule that has similar messaging, let’s put it in settings instead of rule options.
This is what I've done as a workaround. :smile:
const originalRule = require('eslint-plugin-import/lib/rules/no-extraneous-dependencies');
const _ = require('lodash');
const regex = /'([@/a-z0-9-]*)' should be listed/i;
module.exports = {
...originalRule,
create: (context) => {
const interceptingContext = _.cloneDeep(context);
interceptingContext.report = (...args) => {
const [node, message] = args;
const match = message.match(regex);
if (match) {
const packageName = match[1];
const newMessage = `Add '${packageName}' to this package's package.json.`;
context.report(node, newMessage);
return;
}
return context.report(...args);
};
return originalRule.create(interceptingContext);
}
};
You could also use eslint-rule-composer.
Ha! Neat. I didn't know about that.
My team uses
yarn
. The error message forno-extraneous-dependencies
says:I'd rather either omit the second sentence entirely, or add an option to tell devs to use
yarn
. Otherwise, it could create confusion on my team.