Sha256: bd1acc9a9b908ce850f299f1510d957979a3d6291603273eaaa86d28ba349a75

Contents?: true

Size: 1.81 KB

Versions: 45

Compression:

Stored size: 1.81 KB

Contents

/**
 * @fileoverview Require file to end with single newline.
 * @author Nodeca Team <https://github.com/nodeca>
 */
"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
    meta: {
        docs: {
            description: "enforce at least one newline at the end of files",
            category: "Stylistic Issues",
            recommended: false
        },

        fixable: "whitespace",

        schema: [
            {
                enum: ["unix", "windows"]
            }
        ]
    },

    create: function(context) {

        //--------------------------------------------------------------------------
        // Public
        //--------------------------------------------------------------------------

        return {

            Program: function checkBadEOF(node) {

                var sourceCode = context.getSourceCode(),
                    src = sourceCode.getText(),
                    location = {column: 1},
                    linebreakStyle = context.options[0] || "unix",
                    linebreak = linebreakStyle === "unix" ? "\n" : "\r\n";

                if (src[src.length - 1] !== "\n") {

                    // file is not newline-terminated
                    location.line = src.split(/\n/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);
                        }
                    });
                }
            }

        };

    }
};

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.21.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.20.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.19.1 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.19.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.18.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.17.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.16.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.15.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.14.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.13.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.12.2 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.12.1 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.12.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.11.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.10.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.9.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.8.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.7.0 node_modules/eslint/lib/rules/eol-last.js
govuk_publishing_components-17.6.1 node_modules/eslint/lib/rules/eol-last.js