@dnncommunity/dnn-elements 0.24.4-beta.15 → 0.24.4-beta.16

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.
@@ -30,14 +30,15 @@ export const rule = createRule({
30
30
  messageId: "noLabelSlotInCheckbox",
31
31
  fix: fixer => {
32
32
  var _a;
33
- const sourceCode = context.getSourceCode();
33
+ const sourceCode = context.sourceCode;
34
34
  const checkboxText = sourceCode.getText(node.openingElement);
35
35
  const selfClosing = checkboxText.replace(/>$/, " />");
36
36
  const innerContent = node.children.map(child => sourceCode.getText(child)).join("").trim();
37
37
  // Detect leading indentation of the node
38
- const lines = sourceCode.getText(node).split("\n");
39
- const firstLine = lines[0];
40
- const indentMatch = firstLine.match(/^(\s*)/);
38
+ const parent = node.parent;
39
+ const parentLine = parent ? context.sourceCode.getLocFromIndex(parent.range[0]).line : node.loc.start.line;
40
+ const baseLineText = context.sourceCode.lines[parentLine - 1];
41
+ const indentMatch = baseLineText.match(/^(\s*)/);
41
42
  const indent = (_a = indentMatch === null || indentMatch === void 0 ? void 0 : indentMatch[1]) !== null && _a !== void 0 ? _a : "";
42
43
  // Build replacement with proper indentation
43
44
  const replacement = [
@@ -1 +1 @@
1
- {"version":3,"file":"no-label-slot-in-checkbox.js","sourceRoot":"","sources":["../../src/rules/no-label-slot-in-checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAC;IAC3B,IAAI,EAAE,2BAA2B;IACjC,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACF,IAAI,EAAE;YACF,WAAW,EAAE,iCAAiC;YAC9C,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,mEAAmE;SAC3E;QACD,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACN,qBAAqB,EAAE,oFAAoF;SAC9G;QACD,OAAO,EAAE,MAAM;QACf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GAAG,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,CAAC,CAAC,mCAAI,EAAE,CAAC;gCAEtC,4CAA4C;gCAC5C,MAAM,WAAW,GAAG;oCAChB,GAAG,MAAM,SAAS;oCAClB,GAAG,MAAM,KAAK,WAAW,EAAE;oCAC3B,GAAG,MAAM,KAAK,YAAY,EAAE;oCAC5B,GAAG,MAAM,UAAU;iCACtB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gCAEb,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;4BAChD,CAAC;yBACJ,CAAC,CAAC;oBACP,CAAC;gBACL,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import { createRule } from \"../utils.js\";\r\n\r\nexport const rule = createRule({\r\n name: \"no-label-slot-in-checkbox\",\r\n defaultOptions: [],\r\n meta: {\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 type: \"problem\",\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 schema: [], // Ensure schema is defined as an empty array or with the appropriate schema definition\r\n },\r\n create(context) {\r\n return {\r\n JSXElement(node) {\r\n if (\r\n node.openingElement.name.type === \"JSXIdentifier\" &&\r\n node.openingElement.name.name === \"dnn-checkbox\"\r\n ) {\r\n const innerContent = node.children\r\n .map(child => context.sourceCode.getText(child))\r\n .join(\"\")\r\n .trim();\r\n \r\n if (innerContent) {\r\n context.report({\r\n node,\r\n messageId: \"noLabelSlotInCheckbox\",\r\n fix: fixer => {\r\n const sourceCode = context.getSourceCode();\r\n const checkboxText = sourceCode.getText(node.openingElement);\r\n const selfClosing = checkboxText.replace(/>$/, \" />\");\r\n const innerContent = node.children.map(child => sourceCode.getText(child)).join(\"\").trim();\r\n\r\n // Detect leading indentation of the node\r\n const lines = sourceCode.getText(node).split(\"\\n\");\r\n const firstLine = lines[0];\r\n const indentMatch = firstLine.match(/^(\\s*)/);\r\n const indent = indentMatch?.[1] ?? \"\";\r\n\r\n // Build replacement with proper indentation\r\n const replacement = [\r\n `${indent}<label>`,\r\n `${indent} ${selfClosing}`,\r\n `${indent} ${innerContent}`,\r\n `${indent}</label>`,\r\n ].join(\"\\n\");\r\n\r\n return fixer.replaceText(node, replacement);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n };\r\n },\r\n});\r\n"]}
1
+ {"version":3,"file":"no-label-slot-in-checkbox.js","sourceRoot":"","sources":["../../src/rules/no-label-slot-in-checkbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAC;IAC3B,IAAI,EAAE,2BAA2B;IACjC,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACF,IAAI,EAAE;YACF,WAAW,EAAE,iCAAiC;YAC9C,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,mEAAmE;SAC3E;QACD,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACN,qBAAqB,EAAE,oFAAoF;SAC9G;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE,EAAE,EAAE,uFAAuF;KACtG;IACD,MAAM,CAAC,OAAO;QACV,OAAO;YACH,UAAU,CAAC,IAAI;gBACX,IACI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe;oBACjD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,EAClD,CAAC;oBACC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ;yBAC7B,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;yBAC/C,IAAI,CAA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KAAK,YAAY,EAAE;oCAC5B,GAAG,MAAM,UAAU;iCACtB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gCAEb,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;4BAChD,CAAC;yBACJ,CAAC,CAAC;oBACP,CAAC;gBACL,CAAC;YACL,CAAC;SACJ,CAAC;IACN,CAAC;CACJ,CAAC,CAAC","sourcesContent":["import { createRule } from \"../utils.js\";\r\n\r\nexport const rule = createRule({\r\n name: \"no-label-slot-in-checkbox\",\r\n defaultOptions: [],\r\n meta: {\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 type: \"problem\",\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 schema: [], // Ensure schema is defined as an empty array or with the appropriate schema definition\r\n },\r\n create(context) {\r\n return {\r\n JSXElement(node) {\r\n if (\r\n node.openingElement.name.type === \"JSXIdentifier\" &&\r\n node.openingElement.name.name === \"dnn-checkbox\"\r\n ) {\r\n const innerContent = node.children\r\n .map(child => context.sourceCode.getText(child))\r\n .join(\"\")\r\n .trim();\r\n \r\n if (innerContent) {\r\n context.report({\r\n node,\r\n messageId: \"noLabelSlotInCheckbox\",\r\n fix: fixer => {\r\n const sourceCode = context.sourceCode;\r\n const checkboxText = sourceCode.getText(node.openingElement);\r\n const selfClosing = checkboxText.replace(/>$/, \" />\");\r\n const innerContent = node.children.map(child => sourceCode.getText(child)).join(\"\").trim();\r\n\r\n // Detect leading indentation of the node\r\n const parent = node.parent;\r\n const parentLine = parent ? context.sourceCode.getLocFromIndex(parent.range[0]).line : node.loc.start.line;\r\n const baseLineText = context.sourceCode.lines[parentLine - 1];\r\n const indentMatch = baseLineText.match(/^(\\s*)/);\r\n const indent = indentMatch?.[1] ?? \"\";\r\n\r\n // Build replacement with proper indentation\r\n const replacement = [\r\n `${indent}<label>`,\r\n `${indent} ${selfClosing}`,\r\n `${indent} ${innerContent}`,\r\n `${indent}</label>`,\r\n ].join(\"\\n\");\r\n\r\n return fixer.replaceText(node, replacement);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n };\r\n },\r\n});\r\n"]}
@@ -23,14 +23,18 @@ ruleTester.run("no-label-slot-in-checkbox", rule, {
23
23
  ],
24
24
  invalid: [
25
25
  {
26
- code: "<dnn-checkbox onClick={e => console.log(e)}>Something</dnn-checkbox>",
26
+ code: [
27
+ "<dnn-checkbox onClick={e => console.log(e)}>",
28
+ " Something",
29
+ "</dnn-checkbox>",
30
+ ].join("\n"),
27
31
  languageOptions: jsxParserOptions,
28
32
  errors: [{ messageId: "noLabelSlotInCheckbox" }],
29
33
  output: [
30
34
  "<label>",
31
35
  " <dnn-checkbox onClick={e => console.log(e)} />",
32
36
  " Something",
33
- "</label>"
37
+ "</label>",
34
38
  ].join("\n"),
35
39
  },
36
40
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"no-label-slot-in-checkbox.test.js","sourceRoot":"","sources":["../../src/rules/no-label-slot-in-checkbox.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAEtD,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AACtC,UAAU,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;AAC1B,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;AACnC,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAEtC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;AAEpC,yDAAyD;AACzD,MAAM,gBAAgB,GAAG;IACrB,aAAa,EAAE;QACX,YAAY,EAAE;YACV,GAAG,EAAE,IAAI;SACZ;KACJ;CACJ,CAAC;AAEF,UAAU,CAAC,GAAG,CAAC,2BAA2B,EAAE,IAAI,EAAE;IAC9C,KAAK,EAAE;QACH;YACI,IAAI,EAAE,+BAA+B;YACrC,eAAe,EAAE,gBAAgB;SACpC;KACJ;IACD,OAAO,EAAE;QACL;YACI,IAAI,EAAE,sEAAsE;YAC5E,eAAe,EAAE,gBAAgB;YACjC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;YAChD,MAAM,EAAE;gBACJ,SAAS;gBACT,kDAAkD;gBAClD,aAAa;gBACb,UAAU;aACb,CAAC,IAAI,CAAC,IAAI,CAAC;SACf;KACJ;CACJ,CAAC,CAAC","sourcesContent":["import { RuleTester } from \"@typescript-eslint/rule-tester\";\r\nimport * as vitest from \"vitest\";\r\nimport { rule } from \"./no-label-slot-in-checkbox.js\";\r\n\r\nRuleTester.afterAll = vitest.afterAll;\r\nRuleTester.it = vitest.it;\r\nRuleTester.itOnly = vitest.it.only;\r\nRuleTester.describe = vitest.describe;\r\n\r\nconst ruleTester = new RuleTester();\r\n\r\n// Define a reusable configuration for JSX parser options\r\nconst jsxParserOptions = {\r\n parserOptions: {\r\n ecmaFeatures: {\r\n jsx: true,\r\n },\r\n },\r\n};\r\n\r\nruleTester.run(\"no-label-slot-in-checkbox\", rule, {\r\n valid: [\r\n {\r\n code: \"<dnn-checkbox></dnn-checkbox>\",\r\n languageOptions: jsxParserOptions,\r\n },\r\n ],\r\n invalid: [\r\n {\r\n code: \"<dnn-checkbox onClick={e => console.log(e)}>Something</dnn-checkbox>\",\r\n languageOptions: jsxParserOptions,\r\n errors: [{ messageId: \"noLabelSlotInCheckbox\" }],\r\n output: [\r\n \"<label>\",\r\n \" <dnn-checkbox onClick={e => console.log(e)} />\",\r\n \" Something\",\r\n \"</label>\"\r\n ].join(\"\\n\"),\r\n },\r\n ],\r\n});"]}
1
+ {"version":3,"file":"no-label-slot-in-checkbox.test.js","sourceRoot":"","sources":["../../src/rules/no-label-slot-in-checkbox.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAEtD,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AACtC,UAAU,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;AAC1B,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;AACnC,UAAU,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;AAEtC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;AAEpC,yDAAyD;AACzD,MAAM,gBAAgB,GAAG;IACrB,aAAa,EAAE;QACX,YAAY,EAAE;YACV,GAAG,EAAE,IAAI;SACZ;KACJ;CACJ,CAAC;AAEF,UAAU,CAAC,GAAG,CAAC,2BAA2B,EAAE,IAAI,EAAE;IAC9C,KAAK,EAAE;QACH;YACI,IAAI,EAAE,+BAA+B;YACrC,eAAe,EAAE,gBAAgB;SACpC;KACJ;IACD,OAAO,EAAE;QACL;YACI,IAAI,EAAE;gBACF,8CAA8C;gBAC9C,aAAa;gBACb,iBAAiB;aACpB,CAAC,IAAI,CAAC,IAAI,CAAC;YACZ,eAAe,EAAE,gBAAgB;YACjC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,uBAAuB,EAAE,CAAC;YAChD,MAAM,EAAE;gBACJ,SAAS;gBACT,kDAAkD;gBAClD,aAAa;gBACb,UAAU;aACb,CAAC,IAAI,CAAC,IAAI,CAAC;SACf;KACJ;CACJ,CAAC,CAAC","sourcesContent":["import { RuleTester } from \"@typescript-eslint/rule-tester\";\r\nimport * as vitest from \"vitest\";\r\nimport { rule } from \"./no-label-slot-in-checkbox.js\";\r\n\r\nRuleTester.afterAll = vitest.afterAll;\r\nRuleTester.it = vitest.it;\r\nRuleTester.itOnly = vitest.it.only;\r\nRuleTester.describe = vitest.describe;\r\n\r\nconst ruleTester = new RuleTester();\r\n\r\n// Define a reusable configuration for JSX parser options\r\nconst jsxParserOptions = {\r\n parserOptions: {\r\n ecmaFeatures: {\r\n jsx: true,\r\n },\r\n },\r\n};\r\n\r\nruleTester.run(\"no-label-slot-in-checkbox\", rule, {\r\n valid: [\r\n {\r\n code: \"<dnn-checkbox></dnn-checkbox>\",\r\n languageOptions: jsxParserOptions,\r\n },\r\n ],\r\n invalid: [\r\n {\r\n code: [\r\n \"<dnn-checkbox onClick={e => console.log(e)}>\",\r\n \" Something\",\r\n \"</dnn-checkbox>\",\r\n ].join(\"\\n\"),\r\n languageOptions: jsxParserOptions,\r\n errors: [{ messageId: \"noLabelSlotInCheckbox\" }],\r\n output: [\r\n \"<label>\",\r\n \" <dnn-checkbox onClick={e => console.log(e)} />\",\r\n \" Something\",\r\n \"</label>\",\r\n ].join(\"\\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.15",
3
+ "version": "0.24.4-beta.16",
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",