Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add button_has_type rule #1350

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 1 addition & 1 deletion schemas/tags.v1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": ["fresh", "jsr", "recommended"]
"enum": ["fresh", "jsr", "jsx", "react", "recommended"]
}
2 changes: 2 additions & 0 deletions src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 @@ -244,6 +245,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
Loading