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

Pass filename as an argument to parse #5344

Closed
nmote opened this issue Feb 19, 2016 · 24 comments
Closed

Pass filename as an argument to parse #5344

nmote opened this issue Feb 19, 2016 · 24 comments
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 core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue

Comments

@nmote
Copy link
Contributor

nmote commented Feb 19, 2016

I have been experimenting with type-aware lint rules. The prototype I have combines Flow with babel-eslint to annotate the AST with type information.

However, for Flow to be able to provide complete type information it needs the path to the current file so that it can properly resolve imports/requires. To that end I would like to pass the file name as an argument to parse.

I understand that this is a radical departure from the current idea of what a frontend for ESLint is, but the change required to support this idea is very small and will not interfere with existing code. I'm happy to put up a pull request if it is likely to be accepted.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Feb 19, 2016
@ilyavolodin
Copy link
Member

I seem to remember that we already have something like that. We had a request a while back to pass filenames to rules, so we added a function to the rule context. So it should be available inside parse in one form or the other.

@nmote
Copy link
Contributor Author

nmote commented Feb 19, 2016

I don't think the context object is available to the parse function. It's called here with only the program text and the parserOptions object.

@ilyavolodin ilyavolodin added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Feb 19, 2016
@ilyavolodin
Copy link
Member

Oh, sorry, for some reason I though you were talking about validate method, not parse. I'm not 100% sure we want to pass filename to parser, but I'll let others decide.

@nmote
Copy link
Contributor Author

nmote commented Feb 19, 2016

In #5040 @nzakas asks for "ideas for how can ESLint better support TypeScript and Flow." This would be a great start. CC @jeffmo.

@nzakas
Copy link
Member

nzakas commented Feb 22, 2016

@nmote can you explain how you see this working? Keep in mind, we'd need something that won't interfere with how other parsers work.

@nmote
Copy link
Contributor Author

nmote commented Feb 22, 2016

I think the clearest thing would be for me to just put up a PR and we can discuss there. What I have is just a third argument passed to parse with the filename. Since current parsers only use the first two arguments it would not interfere with existing parsers. I'm certainly open to other ideas on how to accomplish this but this idea seems simplest.

@hzoo
Copy link
Member

hzoo commented Feb 22, 2016

So either parse(code: string, options: Object, filename: string) or parse(code: string, options: Object) where you can use options.filename?

@nmote
Copy link
Contributor Author

nmote commented Feb 22, 2016

Both of those would be fine with me, although perhaps options would need to be renamed if we go with the latter.

@nzakas
Copy link
Member

nzakas commented Feb 22, 2016

I thinking something in the options object makes the most sense. My fear of adding another parameter is that we could run into collisions should a parser randomly decide they want to add a third parameter.

My only fear about filename in the options object is whether or not that could potentially clash with another parser's options. We might need something a bit more specific.

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Feb 22, 2016
@nmote
Copy link
Contributor Author

nmote commented Feb 22, 2016

Sounds good to me. Suggestions for a specific option name? currentFilename?

I'll put together a PR.

@nmote
Copy link
Contributor Author

nmote commented Feb 23, 2016

pathToFile? pathToCurrentFile?

@ilyavolodin
Copy link
Member

@nmote Do you just need filename, or do you need a full path to a file?

@nmote
Copy link
Contributor Author

nmote commented Feb 23, 2016

Well, we at least need a relative path. Sorry for not being clearer throughout. With that in mind I think pathToFile probably makes more sense.

@ilyavolodin
Copy link
Member

That's why I asked. Yes, or filePath would be another options. Although all of them sort of imply that the variable only contains directory that the file is in, not the file name itself.

@nzakas
Copy link
Member

nzakas commented Feb 23, 2016

filePath seems like a good compromise.

@nzakas
Copy link
Member

nzakas commented Mar 22, 2016

@nmote do you still plan to put together a PR for this?

@nmote
Copy link
Contributor Author

nmote commented Mar 28, 2016

I do, sorry for the delay: I've been busy with other things. It's near the top of my list and I'll do it this week.

nmote added a commit to nmote/eslint that referenced this issue Apr 1, 2016
@nzakas nzakas added good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue labels Jun 25, 2016
@gyandeeps
Copy link
Member

@nmote I think you have done the work but didn't open a pull request. Do you want to open a pull request?

@hzoo
Copy link
Member

hzoo commented Jun 28, 2016

I can finish this up using that commit if @nmote doesn't (actually seems to be helpful for babel-eslint errors in general when figuring out how to run eslint tests)

@nzakas
Copy link
Member

nzakas commented Jun 29, 2016

There was a pull request that we closed because it was abandoned. @hzoo I'd say go for it.

@gyandeeps
Copy link
Member

@hzoo (just checking) r u working on this?

@annie
Copy link
Contributor

annie commented Aug 28, 2016

i can take this on if @hzoo isn't working on it!

how do i go about writing tests? i haven't made a core contribution yet so i'm not sure how to get started

@ilyavolodin
Copy link
Member

@azhang496 Unit tests are located here: https://github.com/eslint/eslint/blob/master/tests/lib/eslint.js You will probably need to create fake parser through Sinon and verify that filename is passed into parse method.

@hzoo
Copy link
Member

hzoo commented Aug 28, 2016

@azhang496 If you'd like to, go ahead!

annie added a commit to annie/eslint that referenced this issue Aug 31, 2016
annie added a commit to annie/eslint that referenced this issue Aug 31, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint good first issue Good for people who haven't worked on ESLint before help wanted The team would welcome a contribution from the community for this issue
Projects
None yet
Development

No branches or pull requests

7 participants