Skip to content

Commit 566318c

Browse files
authored
Improve messages for valid-compile rule (#74)
1 parent edd848f commit 566318c

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

src/rules/valid-compile.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ export default createRule("valid-compile", {
339339
*/
340340
function getWarnings(code: string): Warning[] {
341341
try {
342-
const result = compiler.compile(code, { generate: false })
342+
const result = compiler.compile(code, {
343+
generate: false,
344+
})
343345

344346
if (ignoreWarnings) {
345347
return []
@@ -348,8 +350,20 @@ export default createRule("valid-compile", {
348350
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore
349351
} catch (e: any) {
350352
// console.log(code)
353+
if (!ignoreWarnings) {
354+
try {
355+
const result = compiler.compile(code, {
356+
generate: false,
357+
errorMode: "warn",
358+
})
359+
return result.warnings
360+
} catch {
361+
// ignore
362+
}
363+
}
351364
return [
352365
{
366+
code: e.code,
353367
message: e.message,
354368
start: e.start,
355369
end: e.end,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"message": "<slot> name cannot be dynamic(dynamic-slot-name)",
4+
"line": 5,
5+
"column": 7
6+
}
7+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export const TESTING_SLOT_NAME = "testing"
3+
</script>
4+
5+
<slot name={TESTING_SLOT_NAME} />

tests/fixtures/rules/valid-compile/invalid/ts/enum01-errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"message": "The $ prefix is reserved, and cannot be used for variable and import names",
3+
"message": "The $ prefix is reserved, and cannot be used for variable and import names(illegal-declaration)",
44
"line": 2,
55
"column": 3
66
}

0 commit comments

Comments
 (0)