Sha256: c519004f42179d6c61f00a20094245305a7e1c1e032f105c7fcbd83139c33b6d

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

/**
 * @fileoverview Require spaces following return, throw, and case
 * @author Michael Ficarra
 */
"use strict";

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

module.exports = function(context) {

    /**
     * Check if the node for spaces
     * @param {ASTNode} node node to evaluate
     * @returns {void}
     * @private
     */
    function check(node) {
        var tokens = context.getFirstTokens(node, 2),
            value = tokens[0].value;

        if (tokens[0].range[1] >= tokens[1].range[0]) {
            context.report({
                node: node,
                message: "Keyword \"" + value + "\" must be followed by whitespace.",
                fix: function(fixer) {
                    return fixer.insertTextAfterRange(tokens[0].range, " ");
                }
            });
        }
    }

    return {
        "ReturnStatement": function(node) {
            if (node.argument) {
                check(node);
            }
        },
        "SwitchCase": function(node) {
            if (node.test) {
                check(node);
            }
        },
        "ThrowStatement": check
    };

};

module.exports.schema = [];

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/lib/rules/space-return-throw-case.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/lib/rules/space-return-throw-case.js