canonical
Version:
Canonical code style linter and formatter for JavaScript, SCSS, CSS and JSON.
67 lines (48 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _find2 = require('lodash/find');
var _find3 = _interopRequireDefault(_find2);
var _eslint = require('eslint');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var cli = new _eslint.CLIEngine({
allowInlineConfig: true,
baseConfig: false,
configFile: require.resolve('./eslintrc.json'),
envs: [],
extensions: [],
fix: true,
globals: [],
parser: require.resolve('babel-eslint'),
rulePaths: [],
useEslintrc: false
});
var fixText = function fixText(text) {
var report = cli.executeOnText(text).results[0];
var fatalError = (0, _find3.default)(report.messages, {
fatal: true
});
if (fatalError) {
throw new Error(fatalError.message + ' (line: ' + fatalError.line + ', column: ' + fatalError.column + ').');
}
return report.output || text;
};
exports.default = function (text) {
var input = undefined,
maxIterationCount = undefined,
output = undefined;
maxIterationCount = 100;
output = text;
// @see https://github.com/eslint/eslint/issues/5004
do {
input = output;
output = fixText(input);
if (--maxIterationCount < 0) {
throw new Error('Max iteration count.');
}
} while (output !== input);
return output;
};
module.exports = exports['default'];
//# sourceMappingURL=fixText.js.map