]>
Commit | Line | Data |
---|---|---|
8f9d1d4d DC |
1 | --- |
2 | title: unicode-bom | |
8f9d1d4d DC |
3 | rule_type: layout |
4 | --- | |
5 | ||
6 | ||
eb39fafa DC |
7 | |
8 | The Unicode Byte Order Mark (BOM) is used to specify whether code units are big | |
9 | endian or little endian. That is, whether the most significant or least | |
10 | significant bytes come first. UTF-8 does not require a BOM because byte ordering | |
11 | does not matter when characters are a single byte. Since UTF-8 is the dominant | |
12 | encoding of the web, we make `"never"` the default option. | |
13 | ||
14 | ## Rule Details | |
15 | ||
16 | If the `"always"` option is used, this rule requires that files always begin | |
17 | with the Unicode BOM character U+FEFF. If `"never"` is used, files must never | |
18 | begin with U+FEFF. | |
19 | ||
20 | ## Options | |
21 | ||
22 | This 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 | ||
29 | Example 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 | ||
36 | U+FEFF | |
37 | var abc; | |
38 | ``` | |
39 | ||
8f9d1d4d DC |
40 | ::: |
41 | ||
eb39fafa DC |
42 | Example 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 | ||
49 | var abc; | |
50 | ``` | |
51 | ||
8f9d1d4d DC |
52 | ::: |
53 | ||
eb39fafa DC |
54 | ### never |
55 | ||
56 | Example 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 | ||
63 | var abc; | |
64 | ``` | |
65 | ||
8f9d1d4d DC |
66 | ::: |
67 | ||
eb39fafa DC |
68 | Example 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 | ||
75 | U+FEFF | |
76 | var abc; | |
77 | ``` | |
78 | ||
8f9d1d4d DC |
79 | ::: |
80 | ||
eb39fafa DC |
81 | ## When Not To Use It |
82 | ||
83 | If you use some UTF-16 or UTF-32 files and you want to allow a file to | |
84 | optionally begin with a Unicode BOM, you should turn this rule off. |