forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7826ffa
commit 0db03ed
Showing
12 changed files
with
266 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable no-console */ | ||
import type { Rule } from 'eslint'; | ||
import type { CallExpression } from 'estree'; | ||
|
||
export const loaderLocation: Rule.RuleModule = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'Detect declaration location of loader$', | ||
recommended: true, | ||
url: 'https://github.com/BuilderIO/qwik', | ||
}, | ||
messages: { | ||
invalidLoaderLocation: | ||
'loader$() can only be declared in `layout.tsx`, `index.tsx` and `plugin.tsx` inside the `src/routes` directory, instead it was declared in "{{path}}". Please check the docs: https://qwik.builder.io/qwikcity/loader', | ||
}, | ||
}, | ||
create(context) { | ||
const path = context.getFilename(); | ||
const isLayout = /^layout(|!|-.+)\.tsx?$/.test(path); | ||
const isIndex = /^index(|!|-.+)\.tsx?$/.test(path); | ||
const canContainLoader = isIndex || isLayout; | ||
return { | ||
'CallExpression[callee.name=/^loader\\$$/]'(node: CallExpression) { | ||
if (!canContainLoader) { | ||
context.report({ | ||
node: node.callee, | ||
messageId: 'invalidLoaderLocation', | ||
data: { | ||
path, | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.