summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/eol-last.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/eol-last.js')
-rw-r--r--tools/eslint/lib/rules/eol-last.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/eol-last.js b/tools/eslint/lib/rules/eol-last.js
new file mode 100644
index 0000000000..96c78c18b4
--- /dev/null
+++ b/tools/eslint/lib/rules/eol-last.js
@@ -0,0 +1,36 @@
+/**
+ * @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.");
+ }
+ }
+
+ };
+
+};