in src/linter.js [380:452]
async scanFile(filename) {
let scanResult = { linterMessages: [], scannedFiles: [] };
const ScannerClass = this.getScanner(filename);
const fileData = await this.io.getFile(
filename,
ScannerClass.fileResultType
);
// First: check that this file is under our 2MB parsing limit. Otherwise
// it will be very slow and may crash the lint with an out-of-memory
// error.
const fileSize =
typeof this.io.files[filename].size !== 'undefined'
? this.io.files[filename].size
: this.io.files[filename].uncompressedSize;
const maxSize = 1024 * 1024 * constants.MAX_FILE_SIZE_TO_PARSE_MB;
if (
ScannerClass !== BinaryScanner &&
ScannerClass !== FilenameScanner &&
fileSize >= maxSize
) {
const filesizeError = {
...messages.FILE_TOO_LARGE,
file: filename,
type: constants.VALIDATION_ERROR,
};
scanResult = {
linterMessages: [filesizeError],
scannedFiles: [filename],
};
} else {
if (ScannerClass !== BinaryScanner && ScannerClass !== FilenameScanner) {
// Check for coin miners
this._markCoinMinerUsage(filename, fileData);
if (this.addonMetadata) {
this.addonMetadata.totalScannedFileSize += fileSize;
}
}
const scanner = new ScannerClass(fileData, filename, {
addonMetadata: this.addonMetadata,
// This is for the JSONScanner, which is a bit of an anomaly and
// accesses the collector directly.
// TODO: Bring this in line with other scanners, see:
// https://github.com/mozilla/addons-linter/issues/895
collector: this.collector,
// list of disabled rules for js scanner
disabledRules: this.config.disableLinterRules,
existingFiles: this.io.files,
enterprise: this.config.enterprise,
privileged: this.config.privileged,
});
scanResult = await scanner.scan();
}
// messages should be a list of raw message data objects.
const { linterMessages, scannedFiles } = scanResult;
linterMessages.forEach((message) => {
if (typeof message.type === 'undefined') {
throw new Error('message.type must be defined');
}
this.collector._addMessage(message.type, message);
});
scannedFiles.forEach((_filename) => {
this.collector.recordScannedFile(_filename, ScannerClass.scannerName);
});
}