Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unicode-bom.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @fileoverview Require or disallow Unicode BOM
  3. * @author Andrew Johnston <https://github.com/ehjay>
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. module.exports = {
  10. meta: {
  11. type: "layout",
  12. docs: {
  13. description: "require or disallow Unicode byte order mark (BOM)",
  14. category: "Stylistic Issues",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/unicode-bom"
  17. },
  18. fixable: "whitespace",
  19. schema: [
  20. {
  21. enum: ["always", "never"]
  22. }
  23. ]
  24. },
  25. create(context) {
  26. //--------------------------------------------------------------------------
  27. // Public
  28. //--------------------------------------------------------------------------
  29. return {
  30. Program: function checkUnicodeBOM(node) {
  31. const sourceCode = context.getSourceCode(),
  32. location = { column: 0, line: 1 },
  33. requireBOM = context.options[0] || "never";
  34. if (!sourceCode.hasBOM && (requireBOM === "always")) {
  35. context.report({
  36. node,
  37. loc: location,
  38. message: "Expected Unicode BOM (Byte Order Mark).",
  39. fix(fixer) {
  40. return fixer.insertTextBeforeRange([0, 1], "\uFEFF");
  41. }
  42. });
  43. } else if (sourceCode.hasBOM && (requireBOM === "never")) {
  44. context.report({
  45. node,
  46. loc: location,
  47. message: "Unexpected Unicode BOM (Byte Order Mark).",
  48. fix(fixer) {
  49. return fixer.removeRange([-1, 0]);
  50. }
  51. });
  52. }
  53. }
  54. };
  55. }
  56. };