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
Misleading instructions at role prefer-property-order
#58
Comments
Hi @moshest this is a bit tricky. We don’t require all properties in the list to be in the package.json file. Do you have any recommendations on how to approach this problem? I plan on looking at it more this week. |
Yes, I think that should do it: const propertiesOrder = ['name', 'version', ...];
const orderMap = new Map();
propertiesOrder.forEach((property, index) => {
orderMap.set(property, index);
});
let i = 0;
Object.keys(packageJson).forEach((property, index) => {
if (!orderMap.has(property)) return;
const pos = orderMap.get(property);
if (pos === i) {
i += 1;
return;
}
if (i > 0) {
throw new Error(`Please move "${property}" after "${propertiesOrder[i - 1]}".`);
} else {
throw new Error(`Please move "${property}" to the top`);
}
}); To solve #57, We should filter let propertiesOrder = ['name', 'version', ...];
propertiesOrder = propertiesOrder.filter(property => packageJson.hasOwnProperty(property)); |
Thanks for the feedback, @moshest! |
This change gives better recommendations for what change is required by the user to resolve the lint issue. It also no longer throws an error when a property exists in the package.json file that doesn't exist in the preferred property order array. Thanks @moshest for the input.
* Closes #57 and #58 This change gives better recommendations for what change is required by the user to resolve the lint issue. It also no longer throws an error when a property exists in the package.json file that doesn't exist in the preferred property order array. Thanks @moshest for the input. * Remove unused variable
Hi @moshest v2.10.0 has been released! Thank you again. |
It's works great! |
Awesome! 🥇 |
My package.json look like this:
With the default ordering
bugs
should be afterversion
but the message I get is:If I will put
bugs
beforerepository
I will get:I think that better instructions will be (notice the quotes I added also):
My version is: 2.8.2
The text was updated successfully, but these errors were encountered: