Skip to content

Commit 0eba622

Browse files
committed
added linter rule for dnn-buttont type deprecation
1 parent c677d60 commit 0eba622

File tree

6 files changed

+98
-2
lines changed

6 files changed

+98
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# dnn-button type obsolete
2+
3+
**dnn-button** `type` property will be reused in the future to indicate the form type of button such as `submit` or `reset` or `button`. It has been marked as deprecated but will still work **in only this minor version**. Replace your current usage with the `appearance` prop. For this version only `formButtonType` will be used to indicate the type of form button this is. In the next minor release, `formButtonType` will be dreprecated in favor of the new meaning of `type`.
4+
5+
Example before:
6+
```html
7+
<dnn-button type="primary">Submit</dnn-button>
8+
```
9+
Example after:
10+
```html
11+
<dnn-button appearance="primary" formButtonType="submit">Submit</dnn-button>
12+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { RuleTester } from "@typescript-eslint/rule-tester";
2+
import * as vitest from "vitest";
3+
import { rule } from "./button-type-to-appearance.js";
4+
5+
RuleTester.afterAll = vitest.afterAll;
6+
RuleTester.it = vitest.it;
7+
RuleTester.itOnly = vitest.it.only;
8+
RuleTester.describe = vitest.describe;
9+
10+
const ruleTester = new RuleTester();
11+
12+
// Define a reusable configuration for JSX parser options
13+
const jsxParserOptions = {
14+
parserOptions: {
15+
ecmaFeatures: {
16+
jsx: true,
17+
},
18+
},
19+
};
20+
21+
ruleTester.run("button-type-to-appearance", rule, {
22+
valid: [
23+
{
24+
code: "<dnn-button></dnn-button>",
25+
languageOptions: jsxParserOptions,
26+
},
27+
{
28+
code: "<dnn-button appearance=\"secondary\"></dnn-button>",
29+
languageOptions: jsxParserOptions,
30+
},
31+
],
32+
invalid: [
33+
{
34+
code: "<dnn-button type=\"primary\"></dnn-button>",
35+
languageOptions: jsxParserOptions,
36+
errors: [{ messageId: "buttonTypeToAppearance" }],
37+
output: "<dnn-button appearance=\"primary\"></dnn-button>",
38+
},
39+
],
40+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createRule } from "../utils.js";
2+
3+
export const rule = createRule({
4+
name: "button-type-to-appearance",
5+
defaultOptions: [],
6+
meta: {
7+
docs: {
8+
description: "type property deprecated in favor of appearance",
9+
recommended: true,
10+
url: "https://github.com/DNNCommunity/dnn-elements/releases/tag/v0.24.0",
11+
},
12+
type: "problem",
13+
fixable: "code",
14+
messages: {
15+
buttonTypeToAppearance: "type property should be replaced with appearance."
16+
},
17+
schema: [],
18+
},
19+
create(context) {
20+
return {
21+
JSXElement(node) {
22+
if (
23+
node.openingElement.name.type === "JSXIdentifier" &&
24+
node.openingElement.name.name === "dnn-button"
25+
) {
26+
for (const attr of node.openingElement.attributes) {
27+
if (
28+
attr.type === "JSXAttribute" &&
29+
attr.name.name === "type"
30+
) {
31+
context.report({
32+
node: attr,
33+
messageId: "buttonTypeToAppearance",
34+
fix: (fixer) => fixer.replaceText(attr.name, "appearance"),
35+
});
36+
}
37+
}
38+
}
39+
}
40+
};
41+
},
42+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { rule as noLabelSlotInCheckbox } from "./no-label-slot-in-checkbox.js";
2+
import { rule as buttonTypeToAppearance } from "./button-type-to-appearance.js";
23

34
export const rules = {
45
"no-label-slot-in-checkbox": noLabelSlotInCheckbox,
6+
"button-type-to-appearance": buttonTypeToAppearance,
57
}

packages/stencil-library/src/components/dnn-permissions-grid/dnn-permissions-grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ export class DnnPermissionsGrid {
495495
</select>
496496
</div>,
497497
<dnn-button
498-
type="primary"
498+
appearance="primary"
499499
onClick={() => this.addRole()}
500500
>
501501
{this.localResx.Add}

packages/stencil-library/src/components/examples/dnn-example-form/dnn-example-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class DnnExampleForm {
155155
console.log(key, value);
156156
});
157157
console.groupEnd();
158-
/* eslint-enable no-console */
158+
159159
}}
160160
>
161161
<dnn-fieldset label="User Information">

0 commit comments

Comments
 (0)