]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/src/rules/unicode-bom.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / rules / unicode-bom.md
CommitLineData
8f9d1d4d
DC
1---
2title: unicode-bom
8f9d1d4d
DC
3rule_type: layout
4---
5
6
eb39fafa
DC
7
8The Unicode Byte Order Mark (BOM) is used to specify whether code units are big
9endian or little endian. That is, whether the most significant or least
10significant bytes come first. UTF-8 does not require a BOM because byte ordering
11does not matter when characters are a single byte. Since UTF-8 is the dominant
12encoding of the web, we make `"never"` the default option.
13
14## Rule Details
15
16If the `"always"` option is used, this rule requires that files always begin
17with the Unicode BOM character U+FEFF. If `"never"` is used, files must never
18begin with U+FEFF.
19
20## Options
21
22This rule has a string option:
23
24* `"always"` files must begin with the Unicode BOM
25* `"never"` (default) files must not begin with the Unicode BOM
26
27### always
28
29Example of **correct** code for this rule with the `"always"` option:
30
8f9d1d4d
DC
31::: correct
32
eb39fafa
DC
33```js
34/*eslint unicode-bom: ["error", "always"]*/
35
36U+FEFF
37var abc;
38```
39
8f9d1d4d
DC
40:::
41
eb39fafa
DC
42Example of **incorrect** code for this rule with the `"always"` option:
43
8f9d1d4d
DC
44::: incorrect
45
eb39fafa
DC
46```js
47/*eslint unicode-bom: ["error", "always"]*/
48
49var abc;
50```
51
8f9d1d4d
DC
52:::
53
eb39fafa
DC
54### never
55
56Example of **correct** code for this rule with the default `"never"` option:
57
8f9d1d4d
DC
58::: correct
59
eb39fafa
DC
60```js
61/*eslint unicode-bom: ["error", "never"]*/
62
63var abc;
64```
65
8f9d1d4d
DC
66:::
67
eb39fafa
DC
68Example of **incorrect** code for this rule with the `"never"` option:
69
8f9d1d4d
DC
70::: incorrect
71
eb39fafa
DC
72```js
73/*eslint unicode-bom: ["error", "never"]*/
74
75U+FEFF
76var abc;
77```
78
8f9d1d4d
DC
79:::
80
eb39fafa
DC
81## When Not To Use It
82
83If you use some UTF-16 or UTF-32 files and you want to allow a file to
84optionally begin with a Unicode BOM, you should turn this rule off.