Skip to content

Commit

Permalink
Fixes before initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
darwintantuco committed Apr 14, 2022
1 parent 907c8e1 commit b2f198b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Disallow form tags without method post

Prevents sensitive data appearing on URLs

![](demo.png)

## Installation

You'll first need to install [ESLint](http://eslint.org):
Expand All @@ -14,10 +18,18 @@ $ npm i eslint --save-dev

Next, install `eslint-plugin-require-form-method-post`:

### npm

```
$ npm install eslint-plugin-require-form-method-post --save-dev
```

### yarn

```
$ yarn add eslint-plugin-require-form-method-post --dev
```

## Usage

Add `require-form-method-post` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
Expand All @@ -27,3 +39,13 @@ Add `require-form-method-post` to the plugins section of your `.eslintrc` config
"plugins": ["require-form-method-post"]
}
```

Then configure the rules you want to use under the rules section.

```json
{
"rules": {
"require-form-method-post/require-form-method-post": "error"
}
}
```
Binary file added demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion lib/rules/require-form-method-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

function withMethodPost(attributes) {
const method = (attributes || []).find(
(attribute) => attribute.name.name.toLowerCase() === "method"
(attribute) =>
attribute.type === "JSXAttribute" &&
attribute.name.name.toLowerCase() === "method"
);

return method && method.value.value.toLowerCase() === "post";
Expand Down
10 changes: 9 additions & 1 deletion tests/lib/rules/require-form-method-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ const defaultErrors = [
ruleTester.run("require-form-method-post", rule, {
valid: [
{ code: `<form method="post" onSubmit={handleSubmit}></form>` },
{
code: `<form {...{ className }} data-testid='form' onSubmit={handleSubmit} method="post"></form>`,
},
{ code: `<form method="POST"></form>` },
{ code: `<form METHOD="POST"></form>` },
],
invalid: [
{ code: `<form onSubmit={handleSubmit}></form>`, errors: defaultErrors },
{ code: `<form></form>`, errors: defaultErrors },
{ code: `<form method="get"></form>`, errors: defaultErrors },
{ code: `<form onSubmit={handleSubmit}></form>`, errors: defaultErrors },
{
code: `<form {...{ className }} data-testid='form' onSubmit={handleSubmit}></form>`,
errors: defaultErrors,
},
],
});

0 comments on commit b2f198b

Please sign in to comment.