Sha256: 8548e63b730fdb209e9ac0d5488ebb3b794dca8d6a5dc664aee5b85125ac6602

Contents?: true

Size: 1.28 KB

Versions: 45

Compression:

Stored size: 1.28 KB

Contents

/**
 * @fileoverview Rule to count multiple spaces in regular expressions
 * @author Matt DuVall <http://www.mattduvall.com/>
 */

"use strict";

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

module.exports = {
    meta: {
        docs: {
            description: "disallow multiple spaces in regular expression literals",
            category: "Possible Errors",
            recommended: true
        },

        schema: []
    },

    create: function(context) {
        var sourceCode = context.getSourceCode();

        return {

            Literal: function(node) {
                var token = sourceCode.getFirstToken(node),
                    nodeType = token.type,
                    nodeValue = token.value,
                    multipleSpacesRegex = /( {2,})+?/,
                    regexResults;

                if (nodeType === "RegularExpression") {
                    regexResults = multipleSpacesRegex.exec(nodeValue);

                    if (regexResults !== null) {
                        context.report(node, "Spaces are hard to count. Use {" + regexResults[0].length + "}.");
                    }
                }
            }
        };

    }
};

Version data entries

45 entries across 45 versions & 2 rubygems

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