Skip to content

Commit f99f087

Browse files
committed
commonize
1 parent 1b92b0b commit f99f087

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

packages/eslint-plugin-svelte/src/rules/valid-prop-names-in-kit-pages.ts

+20-28
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,27 @@ import type { AST } from 'svelte-eslint-parser';
22
import type { TSESTree } from '@typescript-eslint/types';
33
import { createRule } from '../utils/index.js';
44
import { isKitPageComponent } from '../utils/svelte-kit.js';
5+
import type { RuleContext } from '../types.js';
56

67
const EXPECTED_PROP_NAMES = ['data', 'errors', 'form', 'snapshot'];
78

9+
function checkProp(node: TSESTree.VariableDeclarator, context: RuleContext) {
10+
if (node.id.type !== 'ObjectPattern') return;
11+
for (const p of node.id.properties) {
12+
if (
13+
p.type === 'Property' &&
14+
p.value.type === 'Identifier' &&
15+
!EXPECTED_PROP_NAMES.includes(p.value.name)
16+
) {
17+
context.report({
18+
node: p.value,
19+
loc: p.value.loc,
20+
messageId: 'unexpected'
21+
});
22+
}
23+
}
24+
}
25+
826
export default createRule('valid-prop-names-in-kit-pages', {
927
meta: {
1028
docs: {
@@ -58,20 +76,7 @@ export default createRule('valid-prop-names-in-kit-pages', {
5876
}
5977

6078
// export let { xxx, yyy } = zzz
61-
if (node.id.type !== 'ObjectPattern') return;
62-
for (const p of node.id.properties) {
63-
if (
64-
p.type === 'Property' &&
65-
p.value.type === 'Identifier' &&
66-
!EXPECTED_PROP_NAMES.includes(p.value.name)
67-
) {
68-
context.report({
69-
node: p.value,
70-
loc: p.value.loc,
71-
messageId: 'unexpected'
72-
});
73-
}
74-
}
79+
checkProp(node, context);
7580
},
7681

7782
// Svelte5
@@ -86,20 +91,7 @@ export default createRule('valid-prop-names-in-kit-pages', {
8691
return;
8792
}
8893

89-
if (node.id.type !== 'ObjectPattern') return;
90-
for (const p of node.id.properties) {
91-
if (
92-
p.type === 'Property' &&
93-
p.value.type === 'Identifier' &&
94-
!EXPECTED_PROP_NAMES.includes(p.value.name)
95-
) {
96-
context.report({
97-
node: p.value,
98-
loc: p.value.loc,
99-
messageId: 'unexpected'
100-
});
101-
}
102-
}
94+
checkProp(node, context);
10395
}
10496
};
10597
}

0 commit comments

Comments
 (0)