Sha256: b90502c3ab4f854c29ffe7759f301162a14dc4bba94d9d6e7328bd1e7cbaa3fe

Contents?: true

Size: 1.9 KB

Versions: 43

Compression:

Stored size: 1.9 KB

Contents

/**
 * @author Toru Nagashima <https://github.com/mysticatea>
 * See LICENSE file in root directory for full license.
 */
"use strict"

const { isCommaToken } = require("../utils")

module.exports = {
    meta: {
        docs: {
            description:
                "disallow trailing commas in parameter/argument lists.",
            category: "ES2017",
            recommended: false,
            url:
                "http://mysticatea.github.io/eslint-plugin-es/rules/no-trailing-function-commas.html",
        },
        fixable: "code",
        schema: [],
        messages: {
            forbidden:
                "ES2017 trailing commas in parameter/argument lists are forbidden.",
        },
    },
    create(context) {
        const sourceCode = context.getSourceCode()
        return {
            ":function"(node) {
                const length = node.params.length
                if (length === 0) {
                    return
                }

                const lastParam = node.params[length - 1]
                const token = sourceCode.getTokenAfter(lastParam)
                if (isCommaToken(token)) {
                    context.report({
                        loc: token.loc,
                        messageId: "forbidden",
                        fix(fixer) {
                            return fixer.remove(token)
                        },
                    })
                }
            },
            "CallExpression, NewExpression"(node) {
                const token = sourceCode.getLastToken(node, 1)
                if (node.arguments.length >= 1 && isCommaToken(token)) {
                    context.report({
                        loc: token.loc,
                        messageId: "forbidden",
                        fix(fixer) {
                            return fixer.remove(token)
                        },
                    })
                }
            },
        }
    },
}

Version data entries

43 entries across 43 versions & 1 rubygems

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