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

Fix: wrong comment when module not found in config (fixes #8192) #8196

Merged
merged 1 commit into from Mar 8, 2017

Conversation

alberto
Copy link
Member

@alberto alberto commented Mar 4, 2017

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[X] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)
PR #8100 modified the message when there was an error loading a plugin or config, but didn't account for other possible errors. In this case, babel-eslint was not present, and the error was misleading.

Is there anything you'd like reviewers to focus on?
Is there a cleaner way to check for this rather than using the error message?

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@alberto, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @gyandeeps and @mysticatea to be potential reviewers.

@alberto alberto added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly cli Relates to ESLint's command-line interface labels Mar 4, 2017
@not-an-aardvark
Copy link
Member

Is there a cleaner way to check for this rather than using the error message?

You can detect module-loading errors by checking err.code === "MODULE_NOT_FOUND".

Could you clarify what errors this logic is checking for? Intuitively, it seems like we should be able to avoid throwing TypeErrors, so I'm confused what the effect of catching them is. Also, I'm not sure I understand why this logic is only catching missing-module errors related to eslint-config-eslint.

@eslintbot
Copy link

LGTM

@alberto
Copy link
Member Author

alberto commented Mar 4, 2017

I have updated the PR, I hope the intention is clearer now. I tried to provide a better error for people trying to load an inexistent config from a shared config, a plugin or one of the eslint core configs. Main use case is someone has a typo in his config (e.g. eslint:recommend instead of eslint:recommended).

@eslintbot
Copy link

LGTM

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this LGTM, but I have a few suggestions for how it could be more readable.

try {
if (parentPath.indexOf("eslint:") === 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: parentPath.startsWith("eslint:") might be a bit more readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, thanks!

*/
parentPath = (!path.isAbsolute(parentPath)
? path.join(relativeTo || path.dirname(filePath), parentPath)
: parentPath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more readable to avoid negating the condition here.

parentPath = path.isAbsolute(parentPath)
    ? parentPath
    : path.join(relativeTo || path.dirname(filePath), parentPath);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really touch this part, but, yeah, I will update it while I am on it

const packagePath = filePath.substr(7, filePath.lastIndexOf("/") - 7);
const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1);

normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin");
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath, configName };
return { filePath, configName, pluginPath };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to include pluginPath in the return value when it's always the same as filePath?

According to the JSDoc comment, the return value of this function is "A path that can be used directly to load the configuration", but it would be useful if it described the properties of the return value in more detail.

Copy link
Member Author

@alberto alberto Mar 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pluginPath is not a very accurate name. Maybe configFullName is more appropriate. Its value is something like plugin:node/recommended, which is what I wanted to include in the error message, since it is what the user will have in its config file.

filePath is modified in the previous line to contain the resolved path of the config file.

I'm not very fond of JSDoc. How should I document the optional properties of a return object?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there's an official JSDoc way to do it, but just explaining the optional properties in words would be a good improvement.

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@alberto
Copy link
Member Author

alberto commented Mar 7, 2017

@not-an-aardvark let me know if it LGTY now. Thanks for your feedback, I'm much happier with the code now :)

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly cli Relates to ESLint's command-line interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants