Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: add control for executing rules based on Svelte/SvelteKit context #980
feat: add control for executing rules based on Svelte/SvelteKit context #980
Changes from 8 commits
0b44be4
4ca476a
4fbe97d
cb70fea
910effd
ad3dfc3
f1a1cca
531911a
a36d935
bbfae0e
8a02534
0707e79
280ae67
afd422d
f686b4d
ae40057
4640ef5
d7b588f
0e28cc1
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Check warning on line 10 in packages/eslint-plugin-svelte/src/rules/no-export-load-in-svelte-module-in-kit-pages.ts
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.
runes
are a boolean,isNotSatisfies
doesn't work for that...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.
I already changed it to array. How can I make "runes" even more plural?😅
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.
Hmm, I don't like the design of having separate
fileType
andsvelteKitFileType
. I see 2 ways to do it better:I think the second solution is more work (and requires quite careful design), but ultimately serves us better, because rules are fundamentally going to be enabled based on the properties of the current context/file, not based on its type...
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.
At here, it’s better to keep things simple and store only basic information. This is because the definition of "context" can change depending on the rules. For example, we might want to create a rule that prevents placing files like
xxx.svelte.js
in the same directory as+page.svelte
.Another example is that
xxx.svelte.js
might be used for implementing composables, and we might want to enforce a rule that their names must start withuseX
.In short, since the definition of "context" depends on the rules, it’s better to just manage file types here.
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.
I'm still not convinced. I think we should instead add something like a
fileContext
field where we add some information about the file and we can possibly extend it in the future. I am not sure your first example is possible in eslint, as it operates on files separately. But anyway, we would probably need a separate flag for.svelte.js/ts
files. But I don't think it is useful to have a way to distinguish+page.js
,+page.server.js
,+layout.js
and+layout.server.js
- what you would actually want in most situations is 2 flags - "Is this a layout file?" and "Is this a server-only file?"Does that make sense to you or am I being too convoluted?
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 is one of specific example why "Is this a layout file?" and "Is this a server-only file" is not enough.
#438
This rule should check only
+layout.(js|ts)
. (+layout.svelte
should not check.)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.
Hmm, maybe I'm wrong (I haven't used SvelteKit server-side yet), but #438 should also check
+page.(js|ts)
, no? Then it's exactly what I've been getting at :D The differentiator isn't really a list of filename suffixes, but a role the file plays in SvelteKit...Anyway, if my change is not accepted, then I would like to think a little bit more about how
fileType
andsvelteKitFileType
interact...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.
And yes, the list of "file role flags" would probably be longer and would need to expand over time and some rules would check multiple flags at once...
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.
Yes. In that case, we can add helper functions for common validation patterns.
I think it’s best to start with basic functionality and then add more convenient features later if they prove to be valuable.
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.
Yes. We need to check
+page.(js|ts)
also, but what I wanted to say is that "Is this a layout file?" and "Is this a server-only file" is not enough.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.
Hmm, yeah, that's probably a good enough alternative.
I was thinking about the
fileType
a little bit more as well. I get that insvelteKitFileType
, the list of file suffixes makes sense, but I think it gets confusing withfileType
pretty quickly - if I understand it correctly, a+page.svelte
would havea file type.svelte
and+page.js
would have a file type of.svelte.js
- which is a little counterintuitive. MaybefileType
could have values"component"|"plain"
or something similar? Then it wouldn't give the illusion of being a filename extension, which it isn't in case of SvelteKit files...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.
rename to
svelteFileType
.bbfae0e
No.
.svelte.[js|ts]
will be used forxxx.svelte.js
orxxx.svelte.ts
. But not+page.js
,.svelte
and.svelte.[js|ts]
is taken from the docs. (I intendedsvelteFileType
to be determined by the file extension.)https://svelte.dev/docs/svelte/svelte-js-files
svelteFileType
should be null for+page.js
, so I fixed this bug.8a02534