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

[New] give resolvers access to parserServices #2238

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Sep 24, 2021

Is there a way for resolvers to access parserServices? If not, what do you think about enabling it, maybe like so?

modulePath,
sourceFile,
config,
context.parserServices,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pass context.parserServices -> resolver.resolve().

@ljharb
Copy link
Member

ljharb commented Sep 24, 2021

I guess it seems fine, but we’d need tests, and also what’s the use case? Does any parser actually provide info here, and does any resolver look for it?

@@ -80,19 +80,20 @@ exports.fileExistsWithCaseSync = function fileExistsWithCaseSync(filepath, cache
return result;
};

function relative(modulePath, sourceFile, settings) {
return fullResolve(modulePath, sourceFile, settings).path;
function relative(modulePath, sourceFile, context) {
Copy link
Member

@ljharb ljharb Sep 24, 2021

Choose a reason for hiding this comment

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

this is actually a breaking change for the utils package, so that seems quite suboptimal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I resolve that by accepting either the new value (context) or the old (settings), as in the latest commit?

modulePath,
sourceFile,
// Accept context or settings, for backward compatibility
!('settings' in context) ? { settings: context } : context,
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 pretty skeptical there’s always a “settings” in context, consistently from eslint 2 - 7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we pass context.settings -> it today, so we already rely on that, don't we?

return relative(p, context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), context.settings);

return resolve.relative(value, path, context.settings);

Copy link
Member

Choose a reason for hiding this comment

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

i guess that's true; if it wasn't an object it'd throw since it's not checked for truthiness. Still, is there a more robust way to check? perhaps eslint provides a Context constructor or something we could use to compare it to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question ... Here's where it's constructed today, I think: https://github.com/eslint/eslint/blob/cf34e5cf5ed5d09eb53c16cca06821c4e34b7b70/lib/linter/linter.js#L910-L954

Looking at that, I'm not sure what would be more robust, and consistent between ESLint versions?

Copy link
Member

@ljharb ljharb Sep 24, 2021

Choose a reason for hiding this comment

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

Another alternative is to always pass settings, and just also pass context? We could also throw if settings !== context.settings when context is provided

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally -- I propose overloading the argument because I think it's functionally equivalent, and slightly tidier than calling relative(modulePath, sourceFile, context.settings, context), but no strong feelings either way ...

Copy link
Member

Choose a reason for hiding this comment

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

it's definitely tidier - we could also allow relative(modulePath, sourceFile, null, context), and adapt it later whenever we do a semver-major

@codecov
Copy link

codecov bot commented Sep 24, 2021

Codecov Report

Merging #2238 (dc0553d) into main (dd81424) will decrease coverage by 0.59%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2238      +/-   ##
==========================================
- Coverage   95.23%   94.63%   -0.60%     
==========================================
  Files          65       65              
  Lines        2686     2685       -1     
  Branches      888      889       +1     
==========================================
- Hits         2558     2541      -17     
- Misses        128      144      +16     
Impacted Files Coverage Δ
src/ExportMap.js 92.85% <ø> (ø)
utils/resolve.js 88.03% <100.00%> (-11.97%) ⬇️
src/rules/no-unresolved.js 83.33% <0.00%> (-16.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd81424...dc0553d. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants