main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
2.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview Require or disallow Unicode BOM
|
---|
| 3 | * @author Andrew Johnston <https://github.com/ehjay>
|
---|
| 4 | */
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | //------------------------------------------------------------------------------
|
---|
| 8 | // Rule Definition
|
---|
| 9 | //------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | /** @type {import('../shared/types').Rule} */
|
---|
| 12 | module.exports = {
|
---|
| 13 | meta: {
|
---|
| 14 | type: "layout",
|
---|
| 15 |
|
---|
| 16 | docs: {
|
---|
| 17 | description: "Require or disallow Unicode byte order mark (BOM)",
|
---|
| 18 | recommended: false,
|
---|
| 19 | url: "https://eslint.org/docs/latest/rules/unicode-bom"
|
---|
| 20 | },
|
---|
| 21 |
|
---|
| 22 | fixable: "whitespace",
|
---|
| 23 |
|
---|
| 24 | schema: [
|
---|
| 25 | {
|
---|
| 26 | enum: ["always", "never"]
|
---|
| 27 | }
|
---|
| 28 | ],
|
---|
| 29 | messages: {
|
---|
| 30 | expected: "Expected Unicode BOM (Byte Order Mark).",
|
---|
| 31 | unexpected: "Unexpected Unicode BOM (Byte Order Mark)."
|
---|
| 32 | }
|
---|
| 33 | },
|
---|
| 34 |
|
---|
| 35 | create(context) {
|
---|
| 36 |
|
---|
| 37 | //--------------------------------------------------------------------------
|
---|
| 38 | // Public
|
---|
| 39 | //--------------------------------------------------------------------------
|
---|
| 40 |
|
---|
| 41 | return {
|
---|
| 42 |
|
---|
| 43 | Program: function checkUnicodeBOM(node) {
|
---|
| 44 |
|
---|
| 45 | const sourceCode = context.sourceCode,
|
---|
| 46 | location = { column: 0, line: 1 },
|
---|
| 47 | requireBOM = context.options[0] || "never";
|
---|
| 48 |
|
---|
| 49 | if (!sourceCode.hasBOM && (requireBOM === "always")) {
|
---|
| 50 | context.report({
|
---|
| 51 | node,
|
---|
| 52 | loc: location,
|
---|
| 53 | messageId: "expected",
|
---|
| 54 | fix(fixer) {
|
---|
| 55 | return fixer.insertTextBeforeRange([0, 1], "\uFEFF");
|
---|
| 56 | }
|
---|
| 57 | });
|
---|
| 58 | } else if (sourceCode.hasBOM && (requireBOM === "never")) {
|
---|
| 59 | context.report({
|
---|
| 60 | node,
|
---|
| 61 | loc: location,
|
---|
| 62 | messageId: "unexpected",
|
---|
| 63 | fix(fixer) {
|
---|
| 64 | return fixer.removeRange([-1, 0]);
|
---|
| 65 | }
|
---|
| 66 | });
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | }
|
---|
| 73 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.