Skip to content

Commit 2c8d77b

Browse files
authored
Add no-invalid-file-input-accept rule (#3047)
1 parent 8acfea1 commit 2c8d77b

10 files changed

Lines changed: 1387 additions & 1 deletion
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# no-invalid-file-input-accept
2+
3+
📝 Disallow invalid `accept` values on file inputs.
4+
5+
🚫 This rule is _disabled_ in the following [configs](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config): ✅ `recommended`, ☑️ `unopinionated`.
6+
7+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
8+
9+
<!-- end auto-generated rule header -->
10+
<!-- Do not manually modify this header. Run: `npm run fix:eslint-docs` -->
11+
12+
This rule enforces static `accept` values made up of comma-separated filename extensions, MIME types, or the wildcard MIME types `audio/*`, `image/*`, and `video/*`. It rejects invalid tokens and empty entries, and normalizes casing, spacing, duplicates, and common MIME type mistakes.
13+
14+
This rule checks JSX file inputs and HTML file inputs parsed by [`yeonjuan/html-eslint`](https://github.com/yeonjuan/html-eslint).
15+
16+
## Examples
17+
18+
```jsx
19+
//
20+
<input type="file" accept="image/jpg" />;
21+
22+
//
23+
<input type="file" accept="image/jpeg" />;
24+
```
25+
26+
```html
27+
<!---->
28+
<input type="file" accept="image/jpg">
29+
30+
<!---->
31+
<input type="file" accept="image/jpeg">
32+
```
33+
34+
```jsx
35+
//
36+
<input type="file" accept="png" />;
37+
38+
//
39+
<input type="file" accept=".png" />;
40+
```
41+
42+
```jsx
43+
//
44+
<input type="file" accept="IMAGE/*" />;
45+
46+
//
47+
<input type="file" accept="image/*" />;
48+
```
49+
50+
```jsx
51+
//
52+
<input type="file" accept="IMAGE/PNG,.PNG, image/png" />;
53+
54+
//
55+
<input type="file" accept="image/png, .png" />;
56+
```
57+
58+
```jsx
59+
//
60+
<input type="file" accept={allowedTypes} />;
61+
62+
//
63+
<input type="file" accept="image/png, .png" />;
64+
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"@eslint/json": "^1.2.0",
8080
"@eslint/markdown": "^8.0.2",
8181
"@html-eslint/eslint-plugin": "^0.61.0",
82+
"@html-eslint/parser": "^0.61.0",
8283
"@lubien/fixture-beta-package": "^1.0.0-beta.1",
8384
"@typescript-eslint/parser": "^8.57.2",
8485
"@typescript-eslint/types": "^8.57.2",

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export default [
105105
| [no-immediate-mutation](docs/rules/no-immediate-mutation.md) | Disallow immediate mutation after variable assignment. || 🔧 | 💡 |
106106
| [no-instanceof-builtins](docs/rules/no-instanceof-builtins.md) | Disallow `instanceof` with built-in objects | ✅ ☑️ | 🔧 | 💡 |
107107
| [no-invalid-fetch-options](docs/rules/no-invalid-fetch-options.md) | Disallow invalid options in `fetch()` and `new Request()`. | ✅ ☑️ | | |
108+
| [no-invalid-file-input-accept](docs/rules/no-invalid-file-input-accept.md) | Disallow invalid `accept` values on file inputs. | | 🔧 | |
108109
| [no-invalid-remove-event-listener](docs/rules/no-invalid-remove-event-listener.md) | Prevent calling `EventTarget#removeEventListener()` with the result of an expression. | ✅ ☑️ | | |
109110
| [no-keyword-prefix](docs/rules/no-keyword-prefix.md) | Disallow identifiers starting with `new` or `class`. | | | |
110111
| [no-late-current-target-access](docs/rules/no-late-current-target-access.md) | Disallow accessing `event.currentTarget` after the synchronous event dispatch has finished. || | |

rules/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export {default as 'no-hex-escape'} from './no-hex-escape.js';
4646
export {default as 'no-immediate-mutation'} from './no-immediate-mutation.js';
4747
export {default as 'no-instanceof-builtins'} from './no-instanceof-builtins.js';
4848
export {default as 'no-invalid-fetch-options'} from './no-invalid-fetch-options.js';
49+
export {default as 'no-invalid-file-input-accept'} from './no-invalid-file-input-accept.js';
4950
export {default as 'no-invalid-remove-event-listener'} from './no-invalid-remove-event-listener.js';
5051
export {default as 'no-keyword-prefix'} from './no-keyword-prefix.js';
5152
export {default as 'no-late-current-target-access'} from './no-late-current-target-access.js';

0 commit comments

Comments
 (0)