question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

capitalized-comments' ignorePattern should default to no-fallthrough's commentPattern

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.2.0
  • Node Version: v8.9.4
  • npm Version: 5.6.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

Configuration
{
    "env": {
        "browser": true,
        "es6": true,
        "greasemonkey": true
    },
    "extends": "eslint:recommended",
    "globals": {
        "player": false,
        "PLAYER_STATE": false
    },
    "rules": {
        "no-fallthrough": [
            "error", {
                "commentPattern": "fall\\-through"
            }
        ],
        "capitalized-comments": "error"
    }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

var playerState = player.getPlayerState();

switch (playerState) {
    case PLAYER_STATE.Unstarted: // fall-through
    case PLAYER_STATE.Ended: // fall-through
    case PLAYER_STATE.Paused: // fall-through
    case PLAYER_STATE.Buffering: // fall-through
    case PLAYER_STATE.VideoCued: {
        player.playVideo();

        break;
    }
}
eslint scripts/**/*

What did you expect to happen?

capitalized-comments should have been loaded the ignorePattern (that I didn’t set) from the no-fallthrough’s commentPattern option, as it’s clear I’d be using that fall through pattern.

What actually happened? Please include the actual, raw output from ESLint.

.../scripts/Main/main.js
  4:34  error  Comments should not begin with a lowercase character  capitalized-comments
  5:30  error  Comments should not begin with a lowercase character  capitalized-comments
  6:31  error  Comments should not begin with a lowercase character  capitalized-comments
  7:34  error  Comments should not begin with a lowercase character  capitalized-comments

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, Jul 24, 2018

No worries – I just meant that it’s hard for me to predict how ESLint will change in the distant future.

Yes, I’ll go ahead and close it. We definitely appreciate you creating the issue!

To avoid duplication in your config, one option would be to use an .eslintrc.js file and use variables:

const FALL_THROUGH_PATTERN = "fall\\-through";

module.exports = {
    "rules": {
        "no-fallthrough": [
            "error", {
                "commentPattern": FALL_THROUGH_PATTERN
            }
        ],
        "capitalized-comments": [
            "error",
            "always", {
                "ignorePattern": FALL_THROUGH_PATTERN
            }
        ],
        "line-comment-position": [
            "error", {
                "position": "above",
                "ignorePattern": FALL_THROUGH_PATTERN
            }
        ]
    }
};
1reaction
kaicataldocommented, Jul 24, 2018

Hi, thanks for the issue. ESLint rules can’t know about each other by design, so this is not something capitalized-comments can do. A solution for this is to use the capitalized-comments rule’s ignorePattern option:

/* eslint capitalized-comments: ["error", "always", { "ignorePattern": "fall-through" }] */

I don’t think adding a case by default for the no-fallthrough comment is desirable here for two reasons:

  1. The pattern can be changed
  2. If someone isn’t using no-fallthrough, the capitalized-comments rule could be ignoring comments it shouldn’t be

Edit: Typo, meant to type no-fallthrough comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

capitalized-comments - ESLint - Pluggable JavaScript Linter
ignorePattern : A string representing a regular expression pattern of words that should be ignored by this rule. If the first word of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found