node/tools/eslint/lib/rules/eol-last.js
Roman Reiss d91e10b3bd tools: update eslint to 0.24.0
PR-URL: https://github.com/nodejs/io.js/pull/2072
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-by: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alex Kocharin <alex@kocharin.ru>
2015-06-29 19:02:17 +02:00

38 lines
1.1 KiB
JavaScript

/**
* @fileoverview Require file to end with single newline.
* @author Nodeca Team <https://github.com/nodeca>
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = function(context) {
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
return {
"Program": function checkBadEOF(node) {
// Get the whole source code, not for node only.
var src = context.getSource(), location = {column: 1};
if (src.length === 0) {
return;
}
if (src[src.length - 1] !== "\n") {
// file is not newline-terminated
location.line = src.split(/\n/g).length;
context.report(node, location, "Newline required at end of file but not found.");
}
}
};
};
module.exports.schema = [];