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
Add parser
option to getSchema
#26
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach can work, but I'd like to tweak your implementation a little bit in order to prevent the library from constructing a new parser for each execution. That can negatively impact performance for bulk operations. Instead, we can change the getSchema config options to receive the parser
instance itself. Then prisma-lint or any other library can expose its own parser and pass it into getSchema
.
Example:
import { PrismaParser, getSchema } from '@mrleebo/prisma-ast'
const lintParser = new PrismaParser({ nodeLocationTracking: "full" })
getSchema(source, { parser: lintParser })
I made some code suggestions with the core ideas of the change. You'll also need to add PrismaParser to the index.ts exports
export { PrismaParser } from './parser';
The other changes you made like the visitor factory make sense and we can keep that.
data: T, | ||
...tokens: IToken[] | ||
): T { | ||
if (parser.config.nodeLocationTracking === 'none') return data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the visitor now uses the parser's config instead of receiving its own.
Thanks for the feedback. I've iterated in that direction -- let me know what you think. UPDATE: I confirmed this approach works from |
configOverride
parameter to getSchema
parser
option to getSchema
@maxh this feature should be available via prisma-ast v0.8.0 |
I finally got around to hacking on using location data in
prisma-lint
!loop-payments/prisma-lint#84
Everything works great when testing in the
prisma-lint
repository, but I didn't get location data when running the linter on a schema in a different repository (backend
) that usesprisma-lint
. I think this is becauseprisma-ast
was looking for a config file inbackend
.I wasn't sure how to get the location node configuration for
prisma-ast
to be set byprisma-lint
without requiringbackend
to also have to configureprisma-ast
, which felt like too much to ask for users ofprisma-lint
.This PR allows
prisma-lint
to request location information on demand fromprisma-ast
, regardless of the config.I recommend reviewing with the hide whitespace option enabled: