"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const StorageUtilities_1 = require("../../storage/StorageUtilities");
const IInfoItemData_1 = require("../IInfoItemData");
const ProjectInfoItem_1 = require("../ProjectInfoItem");
const ProjectInfoUtilities_1 = require("../ProjectInfoUtilities");
var CheckNoBOMGeneratorTest;
(function (CheckNoBOMGeneratorTest) {
    CheckNoBOMGeneratorTest[CheckNoBOMGeneratorTest["NoByteOrderMarkAllowedInJsonFile"] = 101] = "NoByteOrderMarkAllowedInJsonFile";
})(CheckNoBOMGeneratorTest || (CheckNoBOMGeneratorTest = {}));
/**********
 * Generator that generates error results if Byte Order Marks are found within .json files
 *
 *********/
class CheckNoBOMGenerator {
    id = "NOBOM";
    title = "No Byte Order Mark allowed in json file.";
    canAlwaysProcess = true;
    severity = IInfoItemData_1.InfoItemType.error;
    generate(_project, projectFile) {
        const results = [];
        if (StorageUtilities_1.default.isJsonFile(projectFile) && this.hasByteOrderMark(projectFile)) {
            results.push(this.getNewBOMResult(projectFile));
        }
        return Promise.resolve(results);
    }
    getTopicData(topicId) {
        return {
            title: ProjectInfoUtilities_1.default.getTitleFromEnum(CheckNoBOMGeneratorTest, topicId),
        };
    }
    summarize() { }
    hasByteOrderMark(file) {
        const bytes = StorageUtilities_1.default.getContentsAsBinary(file);
        const hasBOM = StorageUtilities_1.default.hasUTF8ByteOrderMark(bytes);
        return hasBOM;
    }
    getNewBOMResult(file) {
        return new ProjectInfoItem_1.default(this.severity, this.id, CheckNoBOMGeneratorTest.NoByteOrderMarkAllowedInJsonFile, `Byte Order Marks found in file: ${file.name}`);
    }
}
exports.default = CheckNoBOMGenerator;

//# sourceMappingURL=../../maps/info/fileGenerators/CheckNoBOMGenerator.js.map
