Skip to content

Commit

Permalink
feat: add button_has_type rule (#1350)
Browse files Browse the repository at this point in the history
* feat: add button_has_type rule

* fix: clippy

* fix: update schemas

* fix: update docs

* typo

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>

* typo

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>

* message

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>

* chore: clean up indentation

* update docs

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
  • Loading branch information
marvinhagemeister and bartlomieju authored Nov 29, 2024
1 parent b465b6a commit c9b8aec
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/rules/button_has_type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Checks that a `<button>` JSX element has a valid `type` attribute. The default
value is `"submit"` which is often not the desired behavior.

### Invalid:

```tsx
<button />
<button type="foo" />
<button type={condition ? "foo" : "bar"} />
<button type={foo} />
<button type={2} />
```

### Valid:

```tsx
<button type="submit" />
<button type="button" />
<button type="reset" />
<button type={condition ? "button" : "submit"} />
```
1 change: 1 addition & 0 deletions schemas/rules.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ban-untagged-ignore",
"ban-untagged-todo",
"ban-unused-ignore",
"button-has-type",
"camelcase",
"constructor-super",
"default-param-last",
Expand Down
2 changes: 2 additions & 0 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod ban_unknown_rule_code;
pub mod ban_untagged_ignore;
pub mod ban_untagged_todo;
pub mod ban_unused_ignore;
pub mod button_has_type;
pub mod camelcase;
pub mod constructor_super;
pub mod default_param_last;
Expand Down Expand Up @@ -253,6 +254,7 @@ fn get_all_rules_raw() -> Vec<Box<dyn LintRule>> {
Box::new(ban_untagged_ignore::BanUntaggedIgnore),
Box::new(ban_untagged_todo::BanUntaggedTodo),
Box::new(ban_unused_ignore::BanUnusedIgnore),
Box::new(button_has_type::ButtonHasType),
Box::new(camelcase::Camelcase),
Box::new(constructor_super::ConstructorSuper),
Box::new(default_param_last::DefaultParamLast),
Expand Down
Loading

0 comments on commit c9b8aec

Please sign in to comment.