Skip to content

Commit c677d60

Browse files
committed
Use our own rules too
1 parent 6e842b5 commit c677d60

File tree

11 files changed

+59
-49
lines changed

11 files changed

+59
-49
lines changed

packages/stencil-library/eslint-plugin/src/configs/recommended.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ const prefixedRules: Linter.RulesRecord = Object.fromEntries(
1212
])
1313
);
1414

15-
// ✅ Classic config (extends-based)
16-
export const recommended: Linter.Config = {
17-
plugins: [pluginName],
18-
rules: prefixedRules,
19-
};
20-
2115
// ✅ Flat config (for modern eslint.config.js)
2216
export const flatRecommended: FlatConfig.Config[] = [
2317
{

packages/stencil-library/eslint-plugin/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { rules } from "./rules/index.js";
2-
import { recommended, flatRecommended } from "./configs/recommended.js";
2+
import { flatRecommended } from "./configs/recommended.js";
33
import type { Plugin } from "./types/plugin.js";
44
const { name, version } = require("../../package.json") as {
55
name: string;
@@ -10,7 +10,6 @@ const plugin: Plugin = {
1010
meta: { name, version },
1111
rules,
1212
configs: {
13-
recommended,
1413
flat: {
1514
recommended: flatRecommended,
1615
},

packages/stencil-library/eslint-plugin/src/rules/no-label-slot-in-checkbox.test.ts

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ ruleTester.run("no-label-slot-in-checkbox", rule, {
2424
code: "<dnn-checkbox></dnn-checkbox>",
2525
languageOptions: jsxParserOptions,
2626
},
27+
{
28+
code: '<dnn-checkbox><div slot="uncheckedicon">Test</div></dnn-checkbox>',
29+
languageOptions: jsxParserOptions,
30+
},
31+
{
32+
code: [
33+
"<dnn-checkbox>",
34+
" <div slot=\"uncheckedicon\">unchecked</div>",
35+
" <div slot=\"checkedicon\">checked</div>",
36+
"</dnn-checkbox>",
37+
].join("\n"),
38+
languageOptions: jsxParserOptions,
39+
}
2740
],
2841
invalid: [
2942
{
@@ -33,13 +46,27 @@ ruleTester.run("no-label-slot-in-checkbox", rule, {
3346
"</dnn-checkbox>",
3447
].join("\n"),
3548
languageOptions: jsxParserOptions,
36-
errors: [{ messageId: "noLabelSlotInCheckbox" }],
37-
output: [
38-
"<label>",
39-
" <dnn-checkbox onClick={e => console.log(e)} />",
49+
errors: [{ messageId: "noDefaultSlotInCheckbox" }],
50+
},
51+
{
52+
code: [
53+
"<dnn-checkbox onClick={e => console.log(e)}>",
54+
" <div slot=\"uncheckedicon\">unchecked</div>",
4055
" Something",
41-
"</label>",
56+
"</dnn-checkbox>",
57+
].join("\n"),
58+
languageOptions: jsxParserOptions,
59+
errors: [{ messageId: "noDefaultSlotInCheckbox" }],
60+
},
61+
{
62+
code: [
63+
"<dnn-checkbox onClick={e => console.log(e)}>",
64+
" <div slot=\"uncheckedicon\">unchecked</div>",
65+
" <p>Something</p>",
66+
"</dnn-checkbox>",
4267
].join("\n"),
68+
languageOptions: jsxParserOptions,
69+
errors: [{ messageId: "noDefaultSlotInCheckbox" }],
4370
},
4471
],
4572
});

packages/stencil-library/eslint-plugin/src/rules/no-label-slot-in-checkbox.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ export const rule = createRule({
55
defaultOptions: [],
66
meta: {
77
docs: {
8-
description: "Disallow label slot in checkbox",
8+
description: "Disallow default slot in dnn-checkbox; all children must have a named slot",
99
recommended: true,
1010
url: "https://github.com/DNNCommunity/dnn-elements/releases/tag/v0.24.0",
1111
},
1212
type: "problem",
1313
messages: {
14-
noLabelSlotInCheckbox: "Label slot is not allowed in dnn-checkbox, wrap dnn-checkbox with a label instead."
14+
noDefaultSlotInCheckbox: "All children of dnn-checkbox must have a named slot. Default slot is not allowed."
1515
},
16-
fixable: "code",
17-
schema: [], // Ensure schema is defined as an empty array or with the appropriate schema definition
16+
schema: [],
1817
},
1918
create(context) {
2019
return {
@@ -23,29 +22,25 @@ export const rule = createRule({
2322
node.openingElement.name.type === "JSXIdentifier" &&
2423
node.openingElement.name.name === "dnn-checkbox"
2524
) {
26-
const innerContent = node.children
27-
.map(child => context.sourceCode.getText(child))
28-
.join("")
29-
.trim();
30-
31-
if (innerContent) {
32-
context.report({
33-
node,
34-
messageId: "noLabelSlotInCheckbox",
35-
fix: fixer => {
36-
const sourceCode = context.sourceCode;
37-
const checkboxText = sourceCode.getText(node.openingElement);
38-
const selfClosing = checkboxText.replace(/>$/, " />");
39-
const innerContent = node.children.map(child => sourceCode.getText(child)).join("").trim();
40-
41-
return [
42-
fixer.insertTextBefore(node, `<label>\n`),
43-
fixer.replaceText(node, ` ${selfClosing}\n`),
44-
fixer.insertTextAfter(node, ` ${innerContent}\n`),
45-
fixer.insertTextAfter(node, `</label>`),
46-
];
47-
}
48-
});
25+
for (const child of node.children) {
26+
if (
27+
child.type === "JSXText" && child.value.trim() !== ""
28+
) {
29+
context.report({
30+
node: child,
31+
messageId: "noDefaultSlotInCheckbox",
32+
});
33+
} else if (
34+
child.type === "JSXElement" &&
35+
child.openingElement.attributes.every(attr =>
36+
!(attr.type === "JSXAttribute" && attr.name.name === "slot")
37+
)
38+
) {
39+
context.report({
40+
node: child,
41+
messageId: "noDefaultSlotInCheckbox",
42+
});
43+
}
4944
}
5045
}
5146
}

packages/stencil-library/eslint-plugin/src/types/plugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type Plugin = {
1111
};
1212
rules: RulesRecord;
1313
configs: {
14-
recommended: Linter.Config;
1514
flat: {
1615
recommended: FlatConfig.Config[];
1716
}

packages/stencil-library/src/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable */
1+
22
/* tslint:disable */
33
/**
44
* This is an autogenerated file created by the Stencil compiler.

packages/stencil-library/src/components/dnn-autocomplete/dnn-autocomplete.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export class DnnAutocomplete {
335335
}
336336
}
337337

338-
handleBlur(): void {
338+
private handleBlur(): void {
339339
var validity = this.inputField.checkValidity();
340340
this.valid = validity;
341341
this.fieldset.setValidity(validity, this.inputField.validationMessage);

packages/stencil-library/src/components/dnn-input/dnn-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class DnnInput {
228228
return "text";
229229
}
230230

231-
handleBlur(): void {
231+
private handleBlur(): void {
232232
this.focused = false
233233
var validity = this.inputField.checkValidity();
234234
this.valid = validity;

packages/stencil-library/src/components/dnn-modal/dnn-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class DnnModal {
7777
private mouseY: number;
7878
private w: number;
7979
private h: number;
80-
northDrag: HTMLDivElement;
80+
private northDrag: HTMLDivElement;
8181
private handleDismiss(){
8282
this.visible = false;
8383
this.dismissed.emit();

packages/stencil-library/src/components/dnn-vertical-splitview/dnn-vertical-splitview.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ export class DnnVerticalSplitview {
144144
}}>
145145
<slot name="left"></slot>
146146
</div>
147-
<dnn-checkbox>Testing</dnn-checkbox>
148147
<button
149148
onMouseDown={e => this.handleMouseDown(e)}
150149
onTouchStart={e => this.handleMouseDown(e)}

0 commit comments

Comments
 (0)