Blame view
node_modules/eslint/lib/rules/eol-last.js
1.53 KB
c39994410
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/** * @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}, linebreakStyle = context.options[0] || "unix", linebreak = linebreakStyle === "unix" ? " " : "\r "; if (src.length === 0) { return; } if (src[src.length - 1] !== " ") { // file is not newline-terminated location.line = src.split(/ /g).length; context.report({ node: node, loc: location, message: "Newline required at end of file but not found.", fix: function(fixer) { return fixer.insertTextAfterRange([0, src.length], linebreak); } }); } } }; }; module.exports.schema = [ { "enum": ["unix", "windows"] } ]; |