UNPKG

eclint

Version:

Validate or fix code that doesn't adhere to EditorConfig settings or infer settings from existing code.

57 lines 1.48 kB
"use strict"; var EditorConfigError = require("../editor-config-error"); var newlines = { '\n': 'lf', '\r': 'cr', '\r\n': 'crlf', 'cr': '\r', 'crlf': '\r\n', 'lf': '\n', }; function resolve(settings) { switch (settings.end_of_line) { case 'lf': case 'crlf': case 'cr': return settings.end_of_line; default: return void (0); } } function check(settings, line) { var configSetting = resolve(settings); if (!configSetting) { return; } var inferredSetting = infer(line); if (!inferredSetting) { return; } if (inferredSetting !== configSetting) { var error = new EditorConfigError('invalid newline: %s, expected: %s', inferredSetting, configSetting); error.lineNumber = line.number; error.columnNumber = line.text.length + 1; error.rule = 'end_of_line'; error.source = line.text + line.ending; return error; } } function fix(settings, line) { var configSetting = resolve(settings); if (line.ending && configSetting) { line.ending = newlines[configSetting]; } return line; } function infer(line) { return newlines[line.ending]; } var EndOfLineRule = { check: check, fix: fix, infer: infer, resolve: resolve, type: 'LineRule', }; module.exports = EndOfLineRule; //# sourceMappingURL=end_of_line.js.map