eslint-plugin-sitecore-pagebuilder 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +115 -2
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/no-conditional-field-render.d.ts +14 -0
- package/dist/rules/no-conditional-field-render.d.ts.map +1 -0
- package/dist/rules/no-conditional-field-render.js +68 -0
- package/dist/rules/no-conditional-field-render.js.map +1 -0
- package/dist/rules/no-empty-early-return.d.ts +16 -0
- package/dist/rules/no-empty-early-return.d.ts.map +1 -0
- package/dist/rules/no-empty-early-return.js +80 -0
- package/dist/rules/no-empty-early-return.js.map +1 -0
- package/dist/utils.d.ts +28 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +125 -0
- package/dist/utils.js.map +1 -0
- package/package.json +59 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- `no-conditional-field-render`: flags field components hidden behind a check on their own value.
|
|
8
|
+
- `no-empty-early-return`: flags components that return nothing for empty fields without handling Page Builder.
|
|
9
|
+
- `recommended` flat config.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krushna Patel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
|
1
|
-
#
|
|
1
|
+
# eslint-plugin-sitecore-pagebuilder
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ESLint rules for [Sitecore Content SDK](https://doc.sitecore.com/sai/en/developers/content-sdk/) apps that catch code which hides empty fields and components from authors in Page Builder.
|
|
4
|
+
|
|
5
|
+
These bugs pass code review and work fine on the live site. They're usually found late, by an author who can't fill in a field. This plugin finds them while you write the component.
|
|
6
|
+
|
|
7
|
+
The fixes it suggests come from [`sitecore-pagebuilder-kit`](../kit).
|
|
8
|
+
|
|
9
|
+
> Community package. Not affiliated with or endorsed by Sitecore.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install --save-dev eslint-plugin-sitecore-pagebuilder
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires ESLint 9 with flat config, which Content SDK apps use by default from version 1.1.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// eslint.config.mjs
|
|
23
|
+
import pagebuilder from 'eslint-plugin-sitecore-pagebuilder';
|
|
24
|
+
|
|
25
|
+
export default [
|
|
26
|
+
// ...your existing config
|
|
27
|
+
pagebuilder.configs.recommended,
|
|
28
|
+
];
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or pick rules yourself:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
export default [
|
|
35
|
+
{
|
|
36
|
+
plugins: { 'sitecore-pagebuilder': pagebuilder },
|
|
37
|
+
rules: {
|
|
38
|
+
'sitecore-pagebuilder/no-conditional-field-render': 'error',
|
|
39
|
+
'sitecore-pagebuilder/no-empty-early-return': 'warn',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Rules
|
|
46
|
+
|
|
47
|
+
| Rule | What it catches | Recommended |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| [`no-conditional-field-render`](#no-conditional-field-render) | A field component hidden behind a check on its own value | warn |
|
|
50
|
+
| [`no-empty-early-return`](#no-empty-early-return) | A component that returns nothing for an empty field | warn |
|
|
51
|
+
|
|
52
|
+
### no-conditional-field-render
|
|
53
|
+
|
|
54
|
+
In Page Builder, the SDK's field components render a placeholder for empty fields so authors can click and type. A condition on the field's value removes the component before it gets the chance.
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
// ❌
|
|
58
|
+
{fields.title.value && <Text field={fields.title} tag="h2" />}
|
|
59
|
+
{fields.image?.value?.src ? <Image field={fields.image} /> : null}
|
|
60
|
+
{!fields.cta.value.href ? null : <Link field={fields.cta} />}
|
|
61
|
+
|
|
62
|
+
// ✅ Let the SDK handle empty fields
|
|
63
|
+
<Text field={fields.title} tag="h2" />
|
|
64
|
+
|
|
65
|
+
// ✅ Wrapper markup that should disappear on the live site
|
|
66
|
+
<FieldGuard field={fields.title}>
|
|
67
|
+
<div className="card__title"><Text field={fields.title} tag="h2" /></div>
|
|
68
|
+
</FieldGuard>
|
|
69
|
+
|
|
70
|
+
// ✅ Editing-aware conditions are allowed
|
|
71
|
+
{(page.mode.isEditing || fields.title.value) && <Text field={fields.title} />}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
It only reports when the condition and the rendered component refer to the same field, so `{fields.showTitle.value && <Text field={fields.title} />}` is fine. Destructured fields and TypeScript non-null assertions are understood.
|
|
75
|
+
|
|
76
|
+
**Options**
|
|
77
|
+
|
|
78
|
+
- `components` (`string[]`): extra component names that render a field through a `field` prop, such as your own wrappers. Defaults cover `Text`, `RichText`, `Image`, `NextImage`, `Link`, `DateField` and `File`.
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
'sitecore-pagebuilder/no-conditional-field-render': ['warn', { components: ['Heading', 'CtaLink'] }]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### no-empty-early-return
|
|
85
|
+
|
|
86
|
+
A component that returns `null` when a field is empty disappears entirely in Page Builder, leaving authors nothing to click.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
// ❌
|
|
90
|
+
function Promo({ fields }) {
|
|
91
|
+
if (!fields.image.value.src) return null;
|
|
92
|
+
return <Image field={fields.image} />;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function RelatedArticles(props) {
|
|
96
|
+
if (!props.fields.items?.length) return null;
|
|
97
|
+
return <ul>...</ul>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ✅ Keep it on the live site, show it while editing
|
|
101
|
+
function Promo({ fields }) {
|
|
102
|
+
const { page } = useSitecore();
|
|
103
|
+
if (!page.mode.isEditing && !fields.image.value.src) return null;
|
|
104
|
+
return <Image field={fields.image} />;
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
A bare `if (!fields) return null` is not reported. Missing datasources are better handled by the SDK's `withDatasourceCheck()`. Functions that don't return JSX are ignored.
|
|
109
|
+
|
|
110
|
+
## Limitations
|
|
111
|
+
|
|
112
|
+
These rules use syntax, not types, so they follow the patterns teams actually write rather than every possible one. A field passed through a variable with a different name, or checked in a helper function, won't be matched. Reports have no auto-fix yet, because the right fix depends on the design.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
MIT © Krushna Patel
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
declare const rules: {
|
|
3
|
+
'no-conditional-field-render': import("eslint").Rule.RuleModule;
|
|
4
|
+
'no-empty-early-return': import("eslint").Rule.RuleModule;
|
|
5
|
+
};
|
|
6
|
+
declare const plugin: {
|
|
7
|
+
meta: {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
};
|
|
11
|
+
rules: {
|
|
12
|
+
'no-conditional-field-render': import("eslint").Rule.RuleModule;
|
|
13
|
+
'no-empty-early-return': import("eslint").Rule.RuleModule;
|
|
14
|
+
};
|
|
15
|
+
configs: Record<string, Linter.Config>;
|
|
16
|
+
};
|
|
17
|
+
export { rules };
|
|
18
|
+
export default plugin;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI7C,QAAA,MAAM,KAAK;;;CAGV,CAAC;AAEF,QAAA,MAAM,MAAM;;;;;;;;;aAGK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC;CACrB,CAAC;AAW1B,OAAO,EAAE,KAAK,EAAE,CAAC;AACjB,eAAe,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import noConditionalFieldRender from './rules/no-conditional-field-render.js';
|
|
2
|
+
import noEmptyEarlyReturn from './rules/no-empty-early-return.js';
|
|
3
|
+
const rules = {
|
|
4
|
+
'no-conditional-field-render': noConditionalFieldRender,
|
|
5
|
+
'no-empty-early-return': noEmptyEarlyReturn,
|
|
6
|
+
};
|
|
7
|
+
const plugin = {
|
|
8
|
+
meta: { name: 'eslint-plugin-sitecore-pagebuilder', version: '0.1.0' },
|
|
9
|
+
rules,
|
|
10
|
+
configs: {},
|
|
11
|
+
};
|
|
12
|
+
plugin.configs.recommended = {
|
|
13
|
+
name: 'sitecore-pagebuilder/recommended',
|
|
14
|
+
plugins: { 'sitecore-pagebuilder': plugin },
|
|
15
|
+
rules: {
|
|
16
|
+
'sitecore-pagebuilder/no-conditional-field-render': 'warn',
|
|
17
|
+
'sitecore-pagebuilder/no-empty-early-return': 'warn',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
export { rules };
|
|
21
|
+
export default plugin;
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,wBAAwB,MAAM,wCAAwC,CAAC;AAC9E,OAAO,kBAAkB,MAAM,kCAAkC,CAAC;AAElE,MAAM,KAAK,GAAG;IACZ,6BAA6B,EAAE,wBAAwB;IACvD,uBAAuB,EAAE,kBAAkB;CAC5C,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,EAAE,IAAI,EAAE,oCAAoC,EAAE,OAAO,EAAE,OAAO,EAAE;IACtE,KAAK;IACL,OAAO,EAAE,EAAmC;CACrB,CAAC;AAE1B,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG;IAC3B,IAAI,EAAE,kCAAkC;IACxC,OAAO,EAAE,EAAE,sBAAsB,EAAE,MAAM,EAAE;IAC3C,KAAK,EAAE;QACL,kDAAkD,EAAE,MAAM;QAC1D,4CAA4C,EAAE,MAAM;KACrD;CACF,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC;AACjB,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RuleModule } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flags conditions on a field's value that wrap the Content SDK component
|
|
4
|
+
* rendering the same field:
|
|
5
|
+
*
|
|
6
|
+
* {fields.title.value && <Text field={fields.title} />}
|
|
7
|
+
* {fields.image?.value?.src ? <Image field={fields.image} /> : null}
|
|
8
|
+
*
|
|
9
|
+
* In Page Builder the SDK renders an empty-field placeholder so authors can
|
|
10
|
+
* fill the field in, but the condition removes the component first.
|
|
11
|
+
*/
|
|
12
|
+
declare const rule: RuleModule;
|
|
13
|
+
export default rule;
|
|
14
|
+
//# sourceMappingURL=no-conditional-field-render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-conditional-field-render.d.ts","sourceRoot":"","sources":["../../src/rules/no-conditional-field-render.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,aAAa,CAAC;AAMrB;;;;;;;;;GASG;AACH,QAAA,MAAM,IAAI,EAAE,UAqDX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DEFAULT_FIELD_COMPONENTS, collectRenderedFields, collectValueReads, mentionsEditing, rendersNothing, } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flags conditions on a field's value that wrap the Content SDK component
|
|
4
|
+
* rendering the same field:
|
|
5
|
+
*
|
|
6
|
+
* {fields.title.value && <Text field={fields.title} />}
|
|
7
|
+
* {fields.image?.value?.src ? <Image field={fields.image} /> : null}
|
|
8
|
+
*
|
|
9
|
+
* In Page Builder the SDK renders an empty-field placeholder so authors can
|
|
10
|
+
* fill the field in, but the condition removes the component first.
|
|
11
|
+
*/
|
|
12
|
+
const rule = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Disallow hiding a Sitecore field component behind a check on its own value',
|
|
17
|
+
recommended: true,
|
|
18
|
+
url: 'https://github.com/Krushna285/sitecore-pagebuilder-kit/blob/main/packages/eslint-plugin/README.md#no-conditional-field-render',
|
|
19
|
+
},
|
|
20
|
+
schema: [
|
|
21
|
+
{
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
components: { type: 'array', items: { type: 'string' }, uniqueItems: true },
|
|
25
|
+
},
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
messages: {
|
|
30
|
+
hidden: "'{{field}}' is hidden when empty, so authors can't fill it in Page Builder. Wrap it in <FieldGuard field={{{field}}}> or render the field component without the condition.",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
create(context) {
|
|
34
|
+
const options = (context.options[0] ?? {});
|
|
35
|
+
const components = [...DEFAULT_FIELD_COMPONENTS, ...(options.components ?? [])];
|
|
36
|
+
const sourceCode = context.sourceCode;
|
|
37
|
+
const check = (node, test, rendered) => {
|
|
38
|
+
if (mentionsEditing(test, sourceCode))
|
|
39
|
+
return;
|
|
40
|
+
const reads = collectValueReads(test, sourceCode);
|
|
41
|
+
if (reads.size === 0)
|
|
42
|
+
return;
|
|
43
|
+
for (const branch of rendered) {
|
|
44
|
+
for (const field of collectRenderedFields(branch, sourceCode, components)) {
|
|
45
|
+
if (reads.has(field)) {
|
|
46
|
+
context.report({ node, messageId: 'hidden', data: { field } });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
LogicalExpression(node) {
|
|
54
|
+
if (node.operator !== '&&')
|
|
55
|
+
return;
|
|
56
|
+
check(node, node.left, [node.right]);
|
|
57
|
+
},
|
|
58
|
+
ConditionalExpression(node) {
|
|
59
|
+
if (rendersNothing(node.alternate))
|
|
60
|
+
check(node, node.test, [node.consequent]);
|
|
61
|
+
else if (rendersNothing(node.consequent))
|
|
62
|
+
check(node, node.test, [node.alternate]);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
export default rule;
|
|
68
|
+
//# sourceMappingURL=no-conditional-field-render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-conditional-field-render.js","sourceRoot":"","sources":["../../src/rules/no-conditional-field-render.ts"],"names":[],"mappings":"AACA,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,cAAc,GAGf,MAAM,aAAa,CAAC;AAMrB;;;;;;;;;GASG;AACH,MAAM,IAAI,GAAe;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,4EAA4E;YACzF,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,+HAA+H;SACrI;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;iBAC5E;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,MAAM,EACJ,4KAA4K;SAC/K;KACF;IAED,MAAM,CAAC,OAAO;QACZ,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAY,CAAC;QACtD,MAAM,UAAU,GAAG,CAAC,GAAG,wBAAwB,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC;QAChF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,IAAa,EAAE,QAAmB,EAAE,EAAE;YAClE,IAAI,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC;gBA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field is empty, without
|
|
4
|
+
* checking for Page Builder first:
|
|
5
|
+
*
|
|
6
|
+
* if (!fields.title.value) return null;
|
|
7
|
+
* if (!props.fields.items?.length) return null;
|
|
8
|
+
*
|
|
9
|
+
* On the live site that's fine, but in Page Builder the whole component
|
|
10
|
+
* disappears and authors have nothing to click to fill it in.
|
|
11
|
+
* A bare `if (!fields) return null` is left alone; use the SDK's
|
|
12
|
+
* withDatasourceCheck() for missing datasources.
|
|
13
|
+
*/
|
|
14
|
+
declare const rule: RuleModule;
|
|
15
|
+
export default rule;
|
|
16
|
+
//# sourceMappingURL=no-empty-early-return.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-empty-early-return.d.ts","sourceRoot":"","sources":["../../src/rules/no-empty-early-return.ts"],"names":[],"mappings":"AACA,OAAO,EAA2E,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvH;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,IAAI,EAAE,UAgEX,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { collectFieldChecks, mentionsEditing, rendersNothing, walk } from '../utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flags components that return nothing when a field is empty, without
|
|
4
|
+
* checking for Page Builder first:
|
|
5
|
+
*
|
|
6
|
+
* if (!fields.title.value) return null;
|
|
7
|
+
* if (!props.fields.items?.length) return null;
|
|
8
|
+
*
|
|
9
|
+
* On the live site that's fine, but in Page Builder the whole component
|
|
10
|
+
* disappears and authors have nothing to click to fill it in.
|
|
11
|
+
* A bare `if (!fields) return null` is left alone; use the SDK's
|
|
12
|
+
* withDatasourceCheck() for missing datasources.
|
|
13
|
+
*/
|
|
14
|
+
const rule = {
|
|
15
|
+
meta: {
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Disallow returning nothing for empty fields without handling Page Builder editing',
|
|
19
|
+
recommended: true,
|
|
20
|
+
url: 'https://github.com/Krushna285/sitecore-pagebuilder-kit/blob/main/packages/eslint-plugin/README.md#no-empty-early-return',
|
|
21
|
+
},
|
|
22
|
+
schema: [],
|
|
23
|
+
messages: {
|
|
24
|
+
vanishes: "This component returns nothing when '{{field}}' is empty, so it disappears in Page Builder. Check page.mode.isEditing first, or keep rendering so authors can fill the field in.",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
create(context) {
|
|
28
|
+
const sourceCode = context.sourceCode;
|
|
29
|
+
const returnsNothing = (statement) => {
|
|
30
|
+
if (!statement)
|
|
31
|
+
return false;
|
|
32
|
+
if (statement.type === 'ReturnStatement')
|
|
33
|
+
return rendersNothing(statement.argument);
|
|
34
|
+
if (statement.type === 'BlockStatement') {
|
|
35
|
+
const last = statement.body[statement.body.length - 1];
|
|
36
|
+
return Boolean(last) && last.type === 'ReturnStatement' && rendersNothing(last.argument);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
const containsJsx = (fn) => {
|
|
41
|
+
let found = false;
|
|
42
|
+
walk(fn.body, sourceCode, (n) => {
|
|
43
|
+
if (found)
|
|
44
|
+
return false;
|
|
45
|
+
if (n.type === 'JSXElement' || n.type === 'JSXFragment')
|
|
46
|
+
found = true;
|
|
47
|
+
});
|
|
48
|
+
return found;
|
|
49
|
+
};
|
|
50
|
+
const enclosingFunction = (node) => {
|
|
51
|
+
let current = node.parent;
|
|
52
|
+
while (current) {
|
|
53
|
+
if (current.type === 'FunctionDeclaration' ||
|
|
54
|
+
current.type === 'FunctionExpression' ||
|
|
55
|
+
current.type === 'ArrowFunctionExpression') {
|
|
56
|
+
return current;
|
|
57
|
+
}
|
|
58
|
+
current = current.parent;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
IfStatement(node) {
|
|
64
|
+
if (!returnsNothing(node.consequent))
|
|
65
|
+
return;
|
|
66
|
+
const fn = enclosingFunction(node);
|
|
67
|
+
if (!fn || !containsJsx(fn))
|
|
68
|
+
return;
|
|
69
|
+
if (mentionsEditing(node.test, sourceCode))
|
|
70
|
+
return;
|
|
71
|
+
const checks = collectFieldChecks(node.test, sourceCode);
|
|
72
|
+
if (checks.length === 0)
|
|
73
|
+
return;
|
|
74
|
+
context.report({ node, messageId: 'vanishes', data: { field: checks[0] } });
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
export default rule;
|
|
80
|
+
//# sourceMappingURL=no-empty-early-return.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-empty-early-return.js","sourceRoot":"","sources":["../../src/rules/no-empty-early-return.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,cAAc,EAAE,IAAI,EAAiC,MAAM,aAAa,CAAC;AAEvH;;;;;;;;;;;GAWG;AACH,MAAM,IAAI,GAAe;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,mFAAmF;YAChG,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,yHAAyH;SAC/H;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,QAAQ,EACN,kLAAkL;SACrL;KACF;IAED,MAAM,CAAC,OAAO;QACZ,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QAEtC,MAAM,cAAc,GAAG,CAAC,SAAkB,EAAW,EAAE;YACrD,IAAI,CAAC,SAAS;gBAAE,OAAO,KAAK,CAAC;YAC7B,IAAI,SAAS,CAAC,IAAI,KAAK,iBAAiB;gBAAE,OAAO,cAAc,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;YACpF,IAAI,SAAS,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;gBACxC,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,GAAG,CAA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AAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC;oBAAE,OAAO;gBACnD,MAAM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;gBACzD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;oBAAE,OAAO;gBAChC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9E,CAAC;SACmB,CAAC;IACzB,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Rule, SourceCode } from 'eslint';
|
|
2
|
+
/** ESTree nodes, including JSX and TypeScript nodes the core types don't model. */
|
|
3
|
+
export type AnyNode = any;
|
|
4
|
+
/** Content SDK components that render a Sitecore field through a `field` prop. */
|
|
5
|
+
export declare const DEFAULT_FIELD_COMPONENTS: string[];
|
|
6
|
+
/** Calls `visit` on `node` and every descendant. Return false from `visit` to skip children. */
|
|
7
|
+
export declare function walk(node: AnyNode, sourceCode: SourceCode, visit: (n: AnyNode) => boolean | void): void;
|
|
8
|
+
/** Source text with optional chaining, non-null assertions and whitespace removed. */
|
|
9
|
+
export declare function normalize(node: AnyNode, sourceCode: SourceCode): string;
|
|
10
|
+
/**
|
|
11
|
+
* Finds every `X.value` read inside `node` and returns the normalized text of `X`.
|
|
12
|
+
* `fields.title.value`, `fields.title?.value?.src` and `!!title.value` all yield the field expression.
|
|
13
|
+
*/
|
|
14
|
+
export declare function collectValueReads(node: AnyNode, sourceCode: SourceCode): Set<string>;
|
|
15
|
+
/** Normalized `field={...}` expressions of Content SDK field components inside `node`. */
|
|
16
|
+
export declare function collectRenderedFields(node: AnyNode, sourceCode: SourceCode, components: string[]): Set<string>;
|
|
17
|
+
/** True for `null`, `undefined`, `false` and `''`: branches that render nothing. */
|
|
18
|
+
export declare function rendersNothing(node: AnyNode): boolean;
|
|
19
|
+
/** True when the expression mentions `isEditing` (e.g. `page.mode.isEditing`). */
|
|
20
|
+
export declare function mentionsEditing(node: AnyNode, sourceCode: SourceCode): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Finds reads of component fields deeper than `fields` itself, such as
|
|
23
|
+
* `fields.items`, `props.fields.items.length` or `fields.title.value`.
|
|
24
|
+
* A bare `fields` / `props.fields` check (a missing datasource) is not included.
|
|
25
|
+
*/
|
|
26
|
+
export declare function collectFieldChecks(node: AnyNode, sourceCode: SourceCode): string[];
|
|
27
|
+
export type RuleModule = Rule.RuleModule;
|
|
28
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAE/C,mFAAmF;AAEnF,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAE1B,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,UAA0E,CAAC;AAEhH,gGAAgG;AAChG,wBAAgB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,CASvG;AAED,sFAAsF;AACtF,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAMvE;AAiBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAQpF;AASD,0FAA0F;AAC1F,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAiB9G;AAED,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAKrD;AAED,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAQ9E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,EAAE,CAiBlF;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** Content SDK components that render a Sitecore field through a `field` prop. */
|
|
2
|
+
export const DEFAULT_FIELD_COMPONENTS = ['Text', 'RichText', 'Image', 'NextImage', 'Link', 'DateField', 'File'];
|
|
3
|
+
/** Calls `visit` on `node` and every descendant. Return false from `visit` to skip children. */
|
|
4
|
+
export function walk(node, sourceCode, visit) {
|
|
5
|
+
if (!node || typeof node.type !== 'string')
|
|
6
|
+
return;
|
|
7
|
+
if (visit(node) === false)
|
|
8
|
+
return;
|
|
9
|
+
const keys = sourceCode.visitorKeys[node.type] ?? [];
|
|
10
|
+
for (const key of keys) {
|
|
11
|
+
const child = node[key];
|
|
12
|
+
if (Array.isArray(child))
|
|
13
|
+
child.forEach((c) => walk(c, sourceCode, visit));
|
|
14
|
+
else
|
|
15
|
+
walk(child, sourceCode, visit);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Source text with optional chaining, non-null assertions and whitespace removed. */
|
|
19
|
+
export function normalize(node, sourceCode) {
|
|
20
|
+
return sourceCode
|
|
21
|
+
.getText(node)
|
|
22
|
+
.replace(/\s+/g, '')
|
|
23
|
+
.replace(/\?\./g, '.')
|
|
24
|
+
.replace(/!(?=[.\[]|$)/g, '');
|
|
25
|
+
}
|
|
26
|
+
const propertyName = (member) => member.property?.type === 'Identifier' && !member.computed
|
|
27
|
+
? member.property.name
|
|
28
|
+
: member.property?.type === 'Literal'
|
|
29
|
+
? String(member.property.value)
|
|
30
|
+
: undefined;
|
|
31
|
+
const unwrap = (node) => {
|
|
32
|
+
let current = node;
|
|
33
|
+
while (current && (current.type === 'TSNonNullExpression' || current.type === 'ChainExpression')) {
|
|
34
|
+
current = current.expression;
|
|
35
|
+
}
|
|
36
|
+
return current;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Finds every `X.value` read inside `node` and returns the normalized text of `X`.
|
|
40
|
+
* `fields.title.value`, `fields.title?.value?.src` and `!!title.value` all yield the field expression.
|
|
41
|
+
*/
|
|
42
|
+
export function collectValueReads(node, sourceCode) {
|
|
43
|
+
const reads = new Set();
|
|
44
|
+
walk(node, sourceCode, (n) => {
|
|
45
|
+
if (n.type === 'MemberExpression' && propertyName(n) === 'value') {
|
|
46
|
+
reads.add(normalize(unwrap(n.object), sourceCode));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return reads;
|
|
50
|
+
}
|
|
51
|
+
const jsxName = (name) => {
|
|
52
|
+
if (!name)
|
|
53
|
+
return undefined;
|
|
54
|
+
if (name.type === 'JSXIdentifier')
|
|
55
|
+
return name.name;
|
|
56
|
+
if (name.type === 'JSXMemberExpression')
|
|
57
|
+
return name.property?.name;
|
|
58
|
+
return undefined;
|
|
59
|
+
};
|
|
60
|
+
/** Normalized `field={...}` expressions of Content SDK field components inside `node`. */
|
|
61
|
+
export function collectRenderedFields(node, sourceCode, components) {
|
|
62
|
+
const rendered = new Set();
|
|
63
|
+
walk(node, sourceCode, (n) => {
|
|
64
|
+
if (n.type !== 'JSXOpeningElement')
|
|
65
|
+
return;
|
|
66
|
+
const name = jsxName(n.name);
|
|
67
|
+
if (!name || !components.includes(name))
|
|
68
|
+
return;
|
|
69
|
+
for (const attr of n.attributes ?? []) {
|
|
70
|
+
if (attr.type === 'JSXAttribute' &&
|
|
71
|
+
attr.name?.name === 'field' &&
|
|
72
|
+
attr.value?.type === 'JSXExpressionContainer') {
|
|
73
|
+
rendered.add(normalize(unwrap(attr.value.expression), sourceCode));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return rendered;
|
|
78
|
+
}
|
|
79
|
+
/** True for `null`, `undefined`, `false` and `''`: branches that render nothing. */
|
|
80
|
+
export function rendersNothing(node) {
|
|
81
|
+
const n = unwrap(node);
|
|
82
|
+
if (!n)
|
|
83
|
+
return true;
|
|
84
|
+
if (n.type === 'Literal')
|
|
85
|
+
return n.value === null || n.value === false || n.value === '';
|
|
86
|
+
return n.type === 'Identifier' && n.name === 'undefined';
|
|
87
|
+
}
|
|
88
|
+
/** True when the expression mentions `isEditing` (e.g. `page.mode.isEditing`). */
|
|
89
|
+
export function mentionsEditing(node, sourceCode) {
|
|
90
|
+
let found = false;
|
|
91
|
+
walk(node, sourceCode, (n) => {
|
|
92
|
+
if (found)
|
|
93
|
+
return false;
|
|
94
|
+
if (n.type === 'Identifier' && /^is(Editing|PageEditing|EditMode)$/.test(n.name))
|
|
95
|
+
found = true;
|
|
96
|
+
if (n.type === 'MemberExpression' && /^(isEditing|pageEditing)$/.test(propertyName(n) ?? ''))
|
|
97
|
+
found = true;
|
|
98
|
+
});
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Finds reads of component fields deeper than `fields` itself, such as
|
|
103
|
+
* `fields.items`, `props.fields.items.length` or `fields.title.value`.
|
|
104
|
+
* A bare `fields` / `props.fields` check (a missing datasource) is not included.
|
|
105
|
+
*/
|
|
106
|
+
export function collectFieldChecks(node, sourceCode) {
|
|
107
|
+
const checks = [];
|
|
108
|
+
walk(node, sourceCode, (n) => {
|
|
109
|
+
if (n.type !== 'MemberExpression')
|
|
110
|
+
return;
|
|
111
|
+
const text = normalize(n, sourceCode);
|
|
112
|
+
const parts = text.split('.');
|
|
113
|
+
const index = parts.indexOf('fields');
|
|
114
|
+
if (index >= 0 && parts.length > index + 1) {
|
|
115
|
+
checks.push(text);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (propertyName(n) === 'value') {
|
|
119
|
+
checks.push(text);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return checks;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAMA,kFAAkF;AAClF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AAEhH,gGAAgG;AAChG,MAAM,UAAU,IAAI,CAAC,IAAa,EAAE,UAAsB,EAAE,KAAqC;IAC/F,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO;IACnD,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK;QAAE,OAAO;IAClC,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACrD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;;YACtE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,SAAS,CAAC,IAAa,EAAE,UAAsB;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C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sitecore-pagebuilder",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ESLint rules that catch Sitecore Content SDK code which hides empty fields and components from authors in Page Builder.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"eslint": ">=9.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/estree": "^1.0.6",
|
|
31
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
32
|
+
"eslint": "^9.15.0"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"eslint",
|
|
36
|
+
"eslintplugin",
|
|
37
|
+
"eslint-plugin",
|
|
38
|
+
"sitecore",
|
|
39
|
+
"content-sdk",
|
|
40
|
+
"page-builder",
|
|
41
|
+
"sitecoreai",
|
|
42
|
+
"xm-cloud"
|
|
43
|
+
],
|
|
44
|
+
"author": "Krushna Patel",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/Krushna285/sitecore-pagebuilder-kit.git",
|
|
49
|
+
"directory": "packages/eslint-plugin"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/Krushna285/sitecore-pagebuilder-kit/tree/main/packages/eslint-plugin#readme",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/Krushna285/sitecore-pagebuilder-kit/issues"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=18.18"
|
|
60
|
+
}
|
|
61
|
+
}
|