@dnncommunity/dnn-elements 0.24.4-beta.4 → 0.24.4-beta.5
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/dist/collection/eslint-plugin/__tests__/no-label-slot-in-checkbox.tests.js +3 -3
- package/dist/collection/eslint-plugin/__tests__/no-label-slot-in-checkbox.tests.js.map +1 -1
- package/dist/collection/eslint-plugin/src/rules/no-label-slot-in-checkbox.js +10 -23
- package/dist/collection/eslint-plugin/src/rules/no-label-slot-in-checkbox.js.map +1 -1
- package/package.json +1 -1
- package/src/eslint-plugin/__tests__/no-label-slot-in-checkbox.tests.ts +3 -3
- package/src/eslint-plugin/dist/no-label-slot-in-checkbox.js +10 -23
- package/src/eslint-plugin/dist/no-label-slot-in-checkbox.js.map +1 -1
- package/src/eslint-plugin/src/rules/no-label-slot-in-checkbox.ts +11 -28
|
@@ -17,10 +17,10 @@ ruleTester.run("no-label-slot-in-checkbox", noLabelSlotInCheckbox, {
|
|
|
17
17
|
],
|
|
18
18
|
invalid: [
|
|
19
19
|
{
|
|
20
|
-
code: "<dnn-checkbox onClick={e => console.log(e)}
|
|
20
|
+
code: "<dnn-checkbox onClick={e => console.log(e)}>Something</dnn-checkbox>",
|
|
21
21
|
errors: [{ messageId: "noLabelSlotInCheckbox" }],
|
|
22
|
-
output: "<label>\n<dnn-checkbox onClick={e => console.log(e)}></dnn-checkbox>\
|
|
23
|
-
}
|
|
22
|
+
output: "<label>\n<dnn-checkbox onClick={e => console.log(e)}></dnn-checkbox>\nSomething\n</label>",
|
|
23
|
+
}
|
|
24
24
|
],
|
|
25
25
|
});
|
|
26
26
|
//# sourceMappingURL=no-label-slot-in-checkbox.tests.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-label-slot-in-checkbox.tests.js","sourceRoot":"","sources":["../../../src/eslint-plugin/__tests__/no-label-slot-in-checkbox.tests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAE9D,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;IAC9B,MAAM,EAAE,QAAQ;IAChB,aAAa,EAAE;QACX,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE;YACV,GAAG,EAAE,IAAI;SACZ;QACD,UAAU,EAAE,QAAQ;KACvB;CACJ,CAAC,CAAC;AAEH,UAAU,CAAC,GAAG,CAAC,2BAA2B,EAAE,qBAAqB,EAAE;IAC/D,KAAK,EAAE;QACH,EAAE,IAAI,EAAE,+BAA+B,EAAE;KAC5C;IACD,OAAO,EAAE;QACL;YACI,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"no-label-slot-in-checkbox.tests.js","sourceRoot":"","sources":["../../../src/eslint-plugin/__tests__/no-label-slot-in-checkbox.tests.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAE9D,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC;IAC9B,MAAM,EAAE,QAAQ;IAChB,aAAa,EAAE;QACX,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE;YACV,GAAG,EAAE,IAAI;SACZ;QACD,UAAU,EAAE,QAAQ;KACvB;CACJ,CAAC,CAAC;AAEH,UAAU,CAAC,GAAG,CAAC,2BAA2B,EAAE,qBAAqB,EAAE;IAC/D,KAAK,EAAE;QACH,EAAE,IAAI,EAAE,+BAA+B,EAAE;KAC5C;IACD,OAAO,EAAE;QACL;YACI,IAAI,EAAE,sEAAsE;YAC5E,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;YAChD,MAAM,EAAE,2FAA2F;SACtG;KACJ;CACJ,CAAC,CAAC","sourcesContent":["import { RuleTester } from \"eslint\";\r\nimport { noLabelSlotInCheckbox } from \"../src/rules/no-label-slot-in-checkbox\";\r\nconst tsParser = require.resolve(\"@typescript-eslint/parser\");\r\n\r\nconst ruleTester = new RuleTester({\r\n parser: tsParser,\r\n parserOptions: {\r\n ecmaVersion: 2022,\r\n ecmaFeatures: {\r\n jsx: true,\r\n },\r\n sourceType: \"module\",\r\n },\r\n});\r\n\r\nruleTester.run(\"no-label-slot-in-checkbox\", noLabelSlotInCheckbox, {\r\n valid: [\r\n { code: \"<dnn-checkbox></dnn-checkbox>\" },\r\n ],\r\n invalid: [\r\n {\r\n code: \"<dnn-checkbox onClick={e => console.log(e)}>Something</dnn-checkbox>\",\r\n errors: [{ messageId: \"noLabelSlotInCheckbox\" }],\r\n output: \"<label>\\n<dnn-checkbox onClick={e => console.log(e)}></dnn-checkbox>\\nSomething\\n</label>\",\r\n }\r\n ],\r\n});"]}
|
|
@@ -18,33 +18,20 @@ export const noLabelSlotInCheckbox = {
|
|
|
18
18
|
const jsxNode = node;
|
|
19
19
|
if (jsxNode.name.type === "JSXIdentifier" && jsxNode.name.name === "dnn-checkbox") {
|
|
20
20
|
const parent = context.getAncestors().find(ancestor => ancestor.type === "JSXElement");
|
|
21
|
-
if (parent) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
21
|
+
if (parent && parent.type === "JSXElement") {
|
|
22
|
+
const parentElement = parent; // Cast to access children
|
|
23
|
+
const innerContent = parentElement.children
|
|
24
|
+
.map((child) => context.sourceCode.getText(child))
|
|
25
|
+
.join("")
|
|
26
|
+
.trim();
|
|
27
|
+
if (innerContent) {
|
|
28
28
|
context.report({
|
|
29
29
|
node: node,
|
|
30
30
|
messageId: "noLabelSlotInCheckbox",
|
|
31
31
|
fix: (fixer) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
child.openingElement &&
|
|
36
|
-
child.openingElement.name &&
|
|
37
|
-
child.openingElement.name.type === "JSXIdentifier" &&
|
|
38
|
-
child.openingElement.name.name === "label");
|
|
39
|
-
if (label && label.type === "JSXElement") {
|
|
40
|
-
const labelText = context.sourceCode.getText(label).replace(/<label>|<\/label>/g, '').trim();
|
|
41
|
-
const checkboxText = context.sourceCode.getText(node);
|
|
42
|
-
// Combine the label text and checkbox into a label wrapper with multiline formatting
|
|
43
|
-
const fixedText = `<label>\n${checkboxText}</dnn-checkbox>\n${labelText}\n</label>`;
|
|
44
|
-
return fixer.replaceText(parent, fixedText);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
32
|
+
const checkboxText = context.sourceCode.getText(node);
|
|
33
|
+
const fixedText = `<label>\n${checkboxText.replace(innerContent, "").trim()}</dnn-checkbox>\n${innerContent}\n</label>`;
|
|
34
|
+
return fixer.replaceText(parent, fixedText);
|
|
48
35
|
}
|
|
49
36
|
});
|
|
50
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-label-slot-in-checkbox.js","sourceRoot":"","sources":["../../../../src/eslint-plugin/src/rules/no-label-slot-in-checkbox.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,qBAAqB,GAAoB;IAClD,IAAI,EAAE;QACF,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACF,WAAW,EAAE,iCAAiC;YAC9C,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,mEAAmE;SAC3E;QACD,QAAQ,EAAE;YACN,qBAAqB,EAAE,oFAAoF;SAC9G;QACD,OAAO,EAAE,MAAM;KAClB;IACD,MAAM,CAAC,OAAyB;QAC5B,OAAO;YACH,iBAAiB,CAAC,IAAe;gBAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;oBACpC,MAAM,OAAO,GAAG,IAAyB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AAa,CAAC,QAAQ;iCACtC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;iCACtD,IAAI,CAAC,EAAE,CAAC;iCACR,IAAI,EAAE,CAAC;4BAEZ,IAAI,YAAY,EAAE,CAAC;gCACf,OAAO,CAAC,MAAM,CAAC;oCACX,IAAI,EAAE,IAAI;oCACV,SAAS,EAAE,uBAAuB;oCAClC,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE;wCACX,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;wCACtD,MAAM,SAAS,GAAG,YAAY,YAAY,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,oBAAoB,YAAY,YAAY,CAAC;wCACxH,OAAO,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;oCAChD,CAAC;iCACJ,CAAC,CAAC;4BACP,CAAC;wBACL,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ,CAAC","sourcesContent":["import type { Rule } from 'eslint';\r\nimport type { JSXOpeningElement } from \"estree-jsx\";\r\n\r\nexport const noLabelSlotInCheckbox: Rule.RuleModule = {\r\n meta: {\r\n type: \"problem\",\r\n docs: {\r\n description: \"Disallow label slot in checkbox\",\r\n recommended: true,\r\n url: \"https://github.com/DNNCommunity/dnn-elements/releases/tag/v0.24.0\",\r\n },\r\n messages: {\r\n noLabelSlotInCheckbox: \"Label slot is not allowed in dnn-checkbox, wrap dnn-checkbox with a label instead.\"\r\n },\r\n fixable: \"code\",\r\n },\r\n create(context: Rule.RuleContext): Rule.RuleListener {\r\n return {\r\n JSXOpeningElement(node: Rule.Node) {\r\n if (node.type === \"JSXOpeningElement\") {\r\n const jsxNode = node as JSXOpeningElement;\r\n if (jsxNode.name.type === \"JSXIdentifier\" && jsxNode.name.name === \"dnn-checkbox\") {\r\n const parent = context.getAncestors().find(ancestor => ancestor.type === \"JSXElement\");\r\n if (parent && parent.type === \"JSXElement\") {\r\n const parentElement = parent as any; // Cast to access children\r\n const innerContent = parentElement.children\r\n .map((child: any) => context.sourceCode.getText(child))\r\n .join(\"\")\r\n .trim();\r\n\r\n if (innerContent) {\r\n context.report({\r\n node: node,\r\n messageId: \"noLabelSlotInCheckbox\",\r\n fix: (fixer) => {\r\n const checkboxText = context.sourceCode.getText(node);\r\n const fixedText = `<label>\\n${checkboxText.replace(innerContent, \"\").trim()}</dnn-checkbox>\\n${innerContent}\\n</label>`;\r\n return fixer.replaceText(parent, fixedText);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n }\r\n }\r\n };\r\n }\r\n};\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnncommunity/dnn-elements",
|
|
3
|
-
"version": "0.24.4-beta.
|
|
3
|
+
"version": "0.24.4-beta.5",
|
|
4
4
|
"description": "Dnn themed custom elements.",
|
|
5
5
|
"repository": "https://github.com/dnncommunity/dnn-elements",
|
|
6
6
|
"homepage": "https://dnncommunity.github.io/dnn-elements",
|
|
@@ -19,9 +19,9 @@ ruleTester.run("no-label-slot-in-checkbox", noLabelSlotInCheckbox, {
|
|
|
19
19
|
],
|
|
20
20
|
invalid: [
|
|
21
21
|
{
|
|
22
|
-
code: "<dnn-checkbox onClick={e => console.log(e)}
|
|
22
|
+
code: "<dnn-checkbox onClick={e => console.log(e)}>Something</dnn-checkbox>",
|
|
23
23
|
errors: [{ messageId: "noLabelSlotInCheckbox" }],
|
|
24
|
-
output: "<label>\n<dnn-checkbox onClick={e => console.log(e)}></dnn-checkbox>\
|
|
25
|
-
}
|
|
24
|
+
output: "<label>\n<dnn-checkbox onClick={e => console.log(e)}></dnn-checkbox>\nSomething\n</label>",
|
|
25
|
+
}
|
|
26
26
|
],
|
|
27
27
|
});
|
|
@@ -21,33 +21,20 @@ exports.noLabelSlotInCheckbox = {
|
|
|
21
21
|
const jsxNode = node;
|
|
22
22
|
if (jsxNode.name.type === "JSXIdentifier" && jsxNode.name.name === "dnn-checkbox") {
|
|
23
23
|
const parent = context.getAncestors().find(ancestor => ancestor.type === "JSXElement");
|
|
24
|
-
if (parent) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (
|
|
24
|
+
if (parent && parent.type === "JSXElement") {
|
|
25
|
+
const parentElement = parent; // Cast to access children
|
|
26
|
+
const innerContent = parentElement.children
|
|
27
|
+
.map((child) => context.sourceCode.getText(child))
|
|
28
|
+
.join("")
|
|
29
|
+
.trim();
|
|
30
|
+
if (innerContent) {
|
|
31
31
|
context.report({
|
|
32
32
|
node: node,
|
|
33
33
|
messageId: "noLabelSlotInCheckbox",
|
|
34
34
|
fix: (fixer) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
child.openingElement &&
|
|
39
|
-
child.openingElement.name &&
|
|
40
|
-
child.openingElement.name.type === "JSXIdentifier" &&
|
|
41
|
-
child.openingElement.name.name === "label");
|
|
42
|
-
if (label && label.type === "JSXElement") {
|
|
43
|
-
const labelText = context.sourceCode.getText(label).replace(/<label>|<\/label>/g, '').trim();
|
|
44
|
-
const checkboxText = context.sourceCode.getText(node);
|
|
45
|
-
// Combine the label text and checkbox into a label wrapper with multiline formatting
|
|
46
|
-
const fixedText = `<label>\n${checkboxText}</dnn-checkbox>\n${labelText}\n</label>`;
|
|
47
|
-
return fixer.replaceText(parent, fixedText);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
35
|
+
const checkboxText = context.sourceCode.getText(node);
|
|
36
|
+
const fixedText = `<label>\n${checkboxText.replace(innerContent, "").trim()}</dnn-checkbox>\n${innerContent}\n</label>`;
|
|
37
|
+
return fixer.replaceText(parent, fixedText);
|
|
51
38
|
}
|
|
52
39
|
});
|
|
53
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-label-slot-in-checkbox.js","sourceRoot":"","sources":["../src/rules/no-label-slot-in-checkbox.ts"],"names":[],"mappings":";;;AAGa,QAAA,qBAAqB,GAAoB;IAClD,IAAI,EAAE;QACF,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACF,WAAW,EAAE,iCAAiC;YAC9C,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,mEAAmE;SAC3E;QACD,QAAQ,EAAE;YACN,qBAAqB,EAAE,oFAAoF;SAC9G;QACD,OAAO,EAAE,MAAM;KAClB;IACD,MAAM,CAAC,OAAyB;QAC5B,OAAO;YACH,iBAAiB,CAAC,IAAe;gBAC7B,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;oBACpC,MAAM,OAAO,GAAG,IAAyB,CAAC;oBAC1C,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;wBAChF,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;wBACvF,IAAI,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"no-label-slot-in-checkbox.js","sourceRoot":"","sources":["../src/rules/no-label-slot-in-checkbox.ts"],"names":[],"mappings":";;;AAGa,QAAA,qBAAqB,GAAoB;IAClD,IAAI,EAAE;QACF,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACF,WAAW,EAAE,iCAAiC;YAC9C,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,mEAAmE;SAC3E;QACD,QAAQ,EAAE;YACN,qBAAqB,EAAE,oFAAoF;SAC9G;QACD,OAAO,EAAE,MAAM;KAClB;IACD,MAAM,CAAC,OAAyB;QAC5B,OAAO;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,CAAC;CACJ,CAAC"}
|
|
@@ -21,38 +21,21 @@ export const noLabelSlotInCheckbox: Rule.RuleModule = {
|
|
|
21
21
|
const jsxNode = node as JSXOpeningElement;
|
|
22
22
|
if (jsxNode.name.type === "JSXIdentifier" && jsxNode.name.name === "dnn-checkbox") {
|
|
23
23
|
const parent = context.getAncestors().find(ancestor => ancestor.type === "JSXElement");
|
|
24
|
-
if (parent) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
if (parent && parent.type === "JSXElement") {
|
|
25
|
+
const parentElement = parent as any; // Cast to access children
|
|
26
|
+
const innerContent = parentElement.children
|
|
27
|
+
.map((child: any) => context.sourceCode.getText(child))
|
|
28
|
+
.join("")
|
|
29
|
+
.trim();
|
|
30
|
+
|
|
31
|
+
if (innerContent) {
|
|
31
32
|
context.report({
|
|
32
33
|
node: node,
|
|
33
34
|
messageId: "noLabelSlotInCheckbox",
|
|
34
35
|
fix: (fixer) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
child.type === "JSXElement" &&
|
|
39
|
-
child.openingElement &&
|
|
40
|
-
child.openingElement.name &&
|
|
41
|
-
child.openingElement.name.type === "JSXIdentifier" &&
|
|
42
|
-
child.openingElement.name.name === "label");
|
|
43
|
-
|
|
44
|
-
if (label && label.type === "JSXElement") {
|
|
45
|
-
const labelText = context.sourceCode.getText(label).replace(/<label>|<\/label>/g, '').trim();
|
|
46
|
-
const checkboxText = context.sourceCode.getText(node);
|
|
47
|
-
|
|
48
|
-
// Combine the label text and checkbox into a label wrapper with multiline formatting
|
|
49
|
-
const fixedText = `<label>\n${checkboxText}</dnn-checkbox>\n${labelText}\n</label>`;
|
|
50
|
-
|
|
51
|
-
return fixer.replaceText(parent, fixedText);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return null;
|
|
36
|
+
const checkboxText = context.sourceCode.getText(node);
|
|
37
|
+
const fixedText = `<label>\n${checkboxText.replace(innerContent, "").trim()}</dnn-checkbox>\n${innerContent}\n</label>`;
|
|
38
|
+
return fixer.replaceText(parent, fixedText);
|
|
56
39
|
}
|
|
57
40
|
});
|
|
58
41
|
}
|