Repository: eslint/eslint
Pull request #8097 (2017-02-17 23:30:23)

Fix: check output in RuleTester when errors is a number (fixes #7640)
**What is the purpose of this pull request? (put an "X" next to item)**

[ ] Documentation update
[X] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))
[ ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-proposal.md))
[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-change-proposal.md))
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (http://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**
Ensure `output` is checked when `errors` is a number in `RuleTester`.

The change revealed a couple of tests in `spaced-comments` where the output was wrong (there is no output because there is a parsing error) so I fixed those, too.

**Is there anything you'd like reviewers to focus on?**
No.



jsf-clabot: [![CLA assistant check](https://cla.js.foundation/pull/badge/not_signed)](https://cla.js.foundation/eslint/eslint?pullRequest=8097) <br/>Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla.js.foundation/eslint/eslint?pullRequest=8097) before we can accept your contribution.<br/><hr/>**Alberto Rodríguez Lozano** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).
eslintbot: LGTM
mention-bot: @alberto, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @not-an-aardvark and @gyandeeps to be potential reviewers.
eslintbot: LGTM

Patch:
diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md
index 758ef00e7..60148ce4e 100644
--- a/docs/developer-guide/nodejs-api.md
+++ b/docs/developer-guide/nodejs-api.md
@@ -164,7 +164,7 @@ The `CLIEngine` is a constructor, and you can create a new instance by passing i
 * `configFile` - The configuration file to use (default: null). Corresponds to `-c`.
 * `cwd` - Path to a directory that should be considered as the current working directory.
 * `envs` - An array of environments to load (default: empty array). Corresponds to `--env`.
-* `extensions` - An array of filename extensions that should be checked for code. The default is an array containing just `".js"`. Corresponds to `--ext`.
+* `extensions` - An array of filename extensions that should be checked for code. The default is an array containing just `".js"`. Corresponds to `--ext`. It is only used in conjunction with directories, not with filenames or glob patterns.
 * `fix` - True indicates that fixes should be included with the output report, and that errors and warnings should not be listed if they can be fixed. However, the files on disk will not be changed. To persist changes to disk, call [`outputFixes()`](#outputfixes).
 * `globals` - An array of global variables to declare (default: empty array). Corresponds to `--global`.
 * `ignore` - False disables use of `.eslintignore`, `ignorePath` and `ignorePattern` (default: true). Corresponds to `--no-ignore`.
diff --git a/docs/developer-guide/working-with-rules.md b/docs/developer-guide/working-with-rules.md
index 81e33f932..defa52a4e 100644
--- a/docs/developer-guide/working-with-rules.md
+++ b/docs/developer-guide/working-with-rules.md
@@ -280,18 +280,21 @@ Once you have an instance of `SourceCode`, you can use the methods on it to work
 * `getLastTokensBetween(nodeOrToken1, nodeOrToken2, countOptions)` - returns the last `count` tokens between two nodes or tokens.
 * `getTokens(node)` - returns all tokens for the given node.
 * `getTokensBetween(nodeOrToken1, nodeOrToken2)` - returns all tokens between two nodes.
-* `getTokenByRangeStart(index)` - returns the token whose range starts at the given index in the source.
+* `getTokenByRangeStart(index, rangeOptions)` - returns the token whose range starts at the given index in the source.
 * `getNodeByRangeIndex(index)` - returns the deepest node in the AST containing the given source index.
 
 > `skipOptions` is an object which has 3 properties; `skip`, `includeComments`, and `filter`. Default is `{skip: 0, includeComments: false, filter: null}`.
-> - The `skip` is a positive integer, the number of skipping tokens. If `filter` option is given at the same time, it doesn't count filtered tokens as skipped.
-> - The `includeComments` is a boolean value, the flag to include comment tokens into the result.
-> - The `filter` is a function which gets a token as the first argument, if the function returns `false` then the result excludes the token.
+> - `skip` is a positive integer, the number of skipping tokens. If `filter` option is given at the same time, it doesn't count filtered tokens as skipped.
+> - `includeComments` is a boolean value, the flag to include comment tokens into the result.
+> - `filter` is a function which gets a token as the first argument, if the function returns `false` then the result excludes the token.
 >
 > `countOptions` is an object which has 3 properties; `count`, `includeComments`, and `filter`. Default is `{count: 0, includeComments: false, filter: null}`.
-> - The `count` is a positive integer, the maximum number of returning tokens.
-> - The `includeComments` is a boolean value, the flag to include comment tokens into the result.
-> - The `filter` is a function which gets a token as the first argument, if the function returns `false` then the result excludes the token.
+> - `count` is a positive integer, the maximum number of returning tokens.
+> - `includeComments` is a boolean value, the flag to include comment tokens into the result.
+> - `filter` is a function which gets a token as the first argument, if the function returns `false` then the result excludes the token.
+>
+> `rangeOptions` is an object which has 1 property: `includeComments`.
+> - `includeComments` is a boolean value, the flag to include comment tokens into the result.
 
 There are also some properties you can access:
 
diff --git a/docs/maintainer-guide/governance.md b/docs/maintainer-guide/governance.md
index eea276e8b..098f11598 100644
--- a/docs/maintainer-guide/governance.md
+++ b/docs/maintainer-guide/governance.md
@@ -122,6 +122,10 @@ members of the TSC. TSC members can add any items they like to the
 agenda at the beginning of each meeting. The moderator and the TSC
 cannot veto or remove items.
 
+No binding votes on TSC agenda items can take place without a quorum of
+TSC members present in the meeting. Quorum is achieved when more than
+half of the TSC members are present.
+
 The TSC may invite persons or representatives from certain projects to
 participate in a non-voting capacity.
 
diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md
index d72e883d7..98214c3f5 100644
--- a/docs/user-guide/command-line-interface.md
+++ b/docs/user-guide/command-line-interface.md
@@ -80,9 +80,9 @@ Options that accept array values can be specified by repeating the option or wit
 
 Example:
 
-    eslint --ext .jsx --ext .js file.js
+    eslint --ext .jsx --ext .js lib/
 
-    eslint --ext .jsx,.js file.js
+    eslint --ext .jsx,.js lib/
 
 ### Basic configuration
 
@@ -137,7 +137,8 @@ Examples:
     # Also use both .js and .js2
     eslint . --ext .js,.js2
 
-**Note:** If you use a glob pattern, then `--ext` is ignored
+**Note:** `--ext` is only used when the arguments are directories. If you use glob patterns or file names, then `--ext` is ignored.
+
 For example, `eslint lib/* --ext .js` will match all files within the `lib/` directory, regardless of extension.
 
 #### `--global`
diff --git a/docs/user-guide/configuring.md b/docs/user-guide/configuring.md
index 1a87f446e..d425d7467 100644
--- a/docs/user-guide/configuring.md
+++ b/docs/user-guide/configuring.md
@@ -728,7 +728,7 @@ Both the JSON and YAML configuration file formats support comments (`package.jso
 
 ## Specifying File extensions to Lint
 
-Currently the sole method for telling ESLint which file extensions to lint is by specifying a comma separated list of extensions using the [`--ext`](./command-line-interface#ext) command line option.
+Currently the sole method for telling ESLint which file extensions to lint is by specifying a comma separated list of extensions using the [`--ext`](./command-line-interface#ext) command line option. Note this flag only takes effect in conjunction with directories, and will be ignored if used with filenames or glob patterns.
 
 ## Ignoring Files and Directories
 
diff --git a/lib/rules/no-lone-blocks.js b/lib/rules/no-lone-blocks.js
index 48296bf79..95a5b334c 100644
--- a/lib/rules/no-lone-blocks.js
+++ b/lib/rules/no-lone-blocks.js
@@ -32,26 +32,22 @@ module.exports = {
          * @returns {void}
         */
         function report(node) {
-            const parent = context.getAncestors().pop();
+            const message = node.parent.type === "BlockStatement" ? "Nested block is redundant." : "Block is redundant.";
 
-            context.report({ node, message: parent.type === "Program"
-                ? "Block is redundant."
-                : "Nested block is redundant."
-            });
+            context.report({ node, message });
         }
 
         /**
-         * Checks for any ocurrence of BlockStatement > BlockStatement or Program > BlockStatement
-         * @returns {boolean} True if the current node is a lone block.
+         * Checks for any ocurrence of a BlockStatement in a place where lists of statements can appear
+         * @param {ASTNode} node The node to check
+         * @returns {boolean} True if the node is a lone block.
         */
-        function isLoneBlock() {
-            const parent = context.getAncestors().pop();
-
-            /*
-             * Note: astUtils.STATEMENT_LIST_PARENTS is not used here because blocks in SwitchCases are not checked.
-             * https://github.com/eslint/eslint/issues/8047
-             */
-            return parent.type === "BlockStatement" || parent.type === "Program";
+        function isLoneBlock(node) {
+            return node.parent.type === "BlockStatement" ||
+                node.parent.type === "Program" ||
+
+                // Don't report blocks in switch cases if the block is the only statement of the case.
+                node.parent.type === "SwitchCase" && !(node.parent.consequent[0] === node && node.parent.consequent.length === 1);
         }
 
         /**
diff --git a/lib/token-store/backward-token-comment-cursor.js b/lib/token-store/backward-token-comment-cursor.js
index 0fd8ccbe6..7c2137a17 100644
--- a/lib/token-store/backward-token-comment-cursor.js
+++ b/lib/token-store/backward-token-comment-cursor.js
@@ -17,7 +17,6 @@ const utils = require("./utils");
 
 /**
  * The cursor which iterates tokens and comments in reverse.
- * @private
  */
 module.exports = class BackwardTokenCommentCursor extends Cursor {
 
diff --git a/lib/token-store/backward-token-cursor.js b/lib/token-store/backward-token-cursor.js
index 4daf1ab23..caa117fae 100644
--- a/lib/token-store/backward-token-cursor.js
+++ b/lib/token-store/backward-token-cursor.js
@@ -17,7 +17,6 @@ const utils = require("./utils");
 
 /**
  * The cursor which iterates tokens only in reverse.
- * @private
  */
 module.exports = class BackwardTokenCursor extends Cursor {
 
diff --git a/lib/token-store/cursor.js b/lib/token-store/cursor.js
index de33237a9..4e1595c6d 100644
--- a/lib/token-store/cursor.js
+++ b/lib/token-store/cursor.js
@@ -30,7 +30,6 @@
  *     - SkipCursor .............. The cursor which ignores the first few tokens.
  *     - LimitCursor ............. The cursor which limits the count of tokens.
  *
- * @private
  */
 module.exports = class Cursor {
 
diff --git a/lib/token-store/cursors.js b/lib/token-store/cursors.js
index 4d7749bd9..b315c7e65 100644
--- a/lib/token-store/cursors.js
+++ b/lib/token-store/cursors.js
@@ -37,7 +37,24 @@ class CursorFactory {
     }
 
     /**
-     * Creates the cursor iterates tokens with normalized options.
+     * Creates a base cursor instance that can be decorated by createCursor.
+     *
+     * @param {Token[]} tokens - The array of tokens.
+     * @param {Comment[]} comments - The array of comments.
+     * @param {Object} indexMap - The map from locations to indices in `tokens`.
+     * @param {number} startLoc - The start location of the iteration range.
+     * @param {number} endLoc - The end location of the iteration range.
+     * @param {boolean} includeComments - The flag to iterate comments as well.
+     * @returns {Cursor} The created base cursor.
+     */
+    createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments) {
+        const Cursor = includeComments ? this.TokenCommentCursor : this.TokenCursor;
+
+        return new Cursor(tokens, comments, indexMap, startLoc, endLoc);
+    }
+
+    /**
+     * Creates a cursor that iterates tokens with normalized options.
      *
      * @param {Token[]} tokens - The array of tokens.
      * @param {Comment[]} comments - The array of comments.
@@ -49,11 +66,9 @@ class CursorFactory {
      * @param {number} skip - The count of tokens the cursor skips.
      * @param {number} count - The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
      * @returns {Cursor} The created cursor.
-     * @private
      */
     createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, count) {
-        const Cursor = includeComments ? this.TokenCommentCursor : this.TokenCursor;
-        let cursor = new Cursor(tokens, comments, indexMap, startLoc, endLoc);
+        let cursor = this.createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments);
 
         if (filter) {
             cursor = new FilterCursor(cursor, filter);
diff --git a/lib/token-store/decorative-cursor.js b/lib/token-store/decorative-cursor.js
index 0368e8009..f0bff9c51 100644
--- a/lib/token-store/decorative-cursor.js
+++ b/lib/token-store/decorative-cursor.js
@@ -16,7 +16,6 @@ const Cursor = require("./cursor");
 
 /**
  * The abstract class about cursors which manipulate another cursor.
- * @private
  */
 module.exports = class DecorativeCursor extends Cursor {
 
diff --git a/lib/token-store/filter-cursor.js b/lib/token-store/filter-cursor.js
index 0c6bd28aa..7133627bd 100644
--- a/lib/token-store/filter-cursor.js
+++ b/lib/token-store/filter-cursor.js
@@ -16,7 +16,6 @@ const DecorativeCursor = require("./decorative-cursor");
 
 /**
  * The decorative cursor which ignores specified tokens.
- * @private
  */
 module.exports = class FilterCursor extends DecorativeCursor {
 
diff --git a/lib/token-store/forward-token-comment-cursor.js b/lib/token-store/forward-token-comment-cursor.js
index 21dd74d6c..be0855297 100644
--- a/lib/token-store/forward-token-comment-cursor.js
+++ b/lib/token-store/forward-token-comment-cursor.js
@@ -17,7 +17,6 @@ const utils = require("./utils");
 
 /**
  * The cursor which iterates tokens and comments.
- * @private
  */
 module.exports = class ForwardTokenCommentCursor extends Cursor {
 
diff --git a/lib/token-store/forward-token-cursor.js b/lib/token-store/forward-token-cursor.js
index 978b7333f..5748cb45a 100644
--- a/lib/token-store/forward-token-cursor.js
+++ b/lib/token-store/forward-token-cursor.js
@@ -17,7 +17,6 @@ const utils = require("./utils");
 
 /**
  * The cursor which iterates tokens only.
- * @private
  */
 module.exports = class ForwardTokenCursor extends Cursor {
 
diff --git a/lib/token-store/index.js b/lib/token-store/index.js
index bd523fdaa..86d05cf7b 100644
--- a/lib/token-store/index.js
+++ b/lib/token-store/index.js
@@ -236,10 +236,20 @@ module.exports = class TokenStore {
     /**
      * Gets the token starting at the specified index.
      * @param {number} offset - Index of the start of the token's range.
+     * @param {Object} [options=0] - The option object.
+     * @param {boolean} [options.includeComments=false] - The flag to iterate comments as well.
      * @returns {Token|null} The token starting at index, or null if no such token.
      */
-    getTokenByRangeStart(offset) {
-        const token = this.tokens[this.indexMap[offset]] || null;
+    getTokenByRangeStart(offset, options) {
+        const includeComments = options && options.includeComments;
+        const token = cursors.forward.createBaseCursor(
+            this.tokens,
+            this.comments,
+            this.indexMap,
+            offset,
+            -1,
+            includeComments
+        ).getOneToken();
 
         if (token && token.range[0] === offset) {
             return token;
diff --git a/lib/token-store/limit-cursor.js b/lib/token-store/limit-cursor.js
index a0bdae16d..efb46cf0e 100644
--- a/lib/token-store/limit-cursor.js
+++ b/lib/token-store/limit-cursor.js
@@ -16,7 +16,6 @@ const DecorativeCursor = require("./decorative-cursor");
 
 /**
  * The decorative cursor which limits the number of tokens.
- * @private
  */
 module.exports = class LimitCursor extends DecorativeCursor {
 
diff --git a/lib/token-store/padded-token-cursor.js b/lib/token-store/padded-token-cursor.js
index cf91b8b7e..c083aed1e 100644
--- a/lib/token-store/padded-token-cursor.js
+++ b/lib/token-store/padded-token-cursor.js
@@ -17,7 +17,6 @@ const ForwardTokenCursor = require("./forward-token-cursor");
 /**
  * The cursor which iterates tokens only, with inflated range.
  * This is for the backward compatibility of padding options.
- * @private
  */
 module.exports = class PaddedTokenCursor extends ForwardTokenCursor {
 
diff --git a/lib/token-store/skip-cursor.js b/lib/token-store/skip-cursor.js
index f22844535..ab34dfab0 100644
--- a/lib/token-store/skip-cursor.js
+++ b/lib/token-store/skip-cursor.js
@@ -16,7 +16,6 @@ const DecorativeCursor = require("./decorative-cursor");
 
 /**
  * The decorative cursor which ignores the first few tokens.
- * @private
  */
 module.exports = class SkipCursor extends DecorativeCursor {
 
diff --git a/lib/token-store/utils.js b/lib/token-store/utils.js
index 2f6cff1c7..f83b6cf69 100644
--- a/lib/token-store/utils.js
+++ b/lib/token-store/utils.js
@@ -36,7 +36,6 @@ function getStartLocation(token) {
  * @param {(Token|Comment)[]} tokens - It searches the token in this list.
  * @param {number} location - The location to search.
  * @returns {number} The found index or `tokens.length`.
- * @private
  */
 exports.search = function search(tokens, location) {
     return lodash.sortedIndexBy(
@@ -54,7 +53,6 @@ exports.search = function search(tokens, location) {
  * @param {Object} indexMap - The map from locations to indices.
  * @param {number} startLoc - The location to get an index.
  * @returns {number} The index.
- * @private
  */
 exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
     if (startLoc in indexMap) {
@@ -82,7 +80,6 @@ exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
  * @param {Object} indexMap - The map from locations to indices.
  * @param {number} endLoc - The location to get an index.
  * @returns {number} The index.
- * @private
  */
 exports.getLastIndex = function getLastIndex(tokens, indexMap, endLoc) {
     if (endLoc in indexMap) {


Test patch:
diff --git a/lib/testers/rule-tester.js b/lib/testers/rule-tester.js
index e8442f079..16e463789 100644
--- a/lib/testers/rule-tester.js
+++ b/lib/testers/rule-tester.js
@@ -494,13 +494,12 @@ RuleTester.prototype = {
                         assert.fail(messages[i], null, "Error should be a string or object.");
                     }
                 }
+            }
 
-                if (item.hasOwnProperty("output")) {
-                    const fixResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);
-
-                    assert.equal(fixResult.output, item.output, "Output is incorrect.");
-                }
+            if (item.hasOwnProperty("output")) {
+                const fixResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);
 
+                assert.equal(fixResult.output, item.output, "Output is incorrect.");
             }
 
             assertASTDidntChange(result.beforeAST, result.afterAST);
diff --git a/tests/lib/rules/no-lone-blocks.js b/tests/lib/rules/no-lone-blocks.js
index a3a0a4ab1..8205ba7d4 100644
--- a/tests/lib/rules/no-lone-blocks.js
+++ b/tests/lib/rules/no-lone-blocks.js
@@ -31,7 +31,32 @@ ruleTester.run("no-lone-blocks", rule, {
         { code: "{ function bar() {} }", parserOptions: { ecmaVersion: 6, ecmaFeatures: { impliedStrict: true } } },
         { code: "{ class Bar {} }", parserOptions: { ecmaVersion: 6 } },
 
-        { code: "{ {let y = 1;} let x = 1; }", parserOptions: { ecmaVersion: 6 } }
+        { code: "{ {let y = 1;} let x = 1; }", parserOptions: { ecmaVersion: 6 } },
+        `
+          switch (foo) {
+            case bar: {
+              baz;
+            }
+          }
+        `,
+        `
+          switch (foo) {
+            case bar: {
+              baz;
+            }
+            case qux: {
+              boop;
+            }
+          }
+        `,
+        `
+          switch (foo) {
+            case bar:
+            {
+              baz;
+            }
+          }
+        `
     ],
     invalid: [
         { code: "{}", errors: [{ message: "Block is redundant.", type: "BlockStatement" }] },
@@ -69,6 +94,30 @@ ruleTester.run("no-lone-blocks", rule, {
                 { message: "Nested block is redundant.", type: "BlockStatement", line: 2 },
                 { message: "Block is redundant.", type: "BlockStatement", line: 4 }
             ]
+        },
+        {
+            code: `
+              switch (foo) {
+                case 1:
+                    foo();
+                    {
+                        bar;
+                    }
+              }
+            `,
+            errors: [{ message: "Block is redundant.", type: "BlockStatement", line: 5 }]
+        },
+        {
+            code: `
+              switch (foo) {
+                case 1:
+                {
+                    bar;
+                }
+                foo();
+              }
+            `,
+            errors: [{ message: "Block is redundant.", type: "BlockStatement", line: 4 }]
         }
     ]
 });
diff --git a/tests/lib/rules/spaced-comment.js b/tests/lib/rules/spaced-comment.js
index 4639f3d37..04359158d 100644
--- a/tests/lib/rules/spaced-comment.js
+++ b/tests/lib/rules/spaced-comment.js
@@ -385,18 +385,6 @@ ruleTester.run("spaced-comment", rule, {
                 markers: ["/", "!<"]
             }]
         },
-        {
-            code: invalidShebangProgram,
-            output: "#!/path/to/node\n#!/second/shebang\nvar a = 3;",
-            errors: 1,
-            options: ["always"]
-        },
-        {
-            code: invalidShebangProgram,
-            output: "#!/path/to/node\n#!/second/shebang\nvar a = 3;",
-            errors: 1,
-            options: ["never"]
-        },
         {
             code: "var a = 1; /* A valid comment starting with space */",
             output: "var a = 1; /*A valid comment starting with space */",
@@ -584,6 +572,18 @@ ruleTester.run("spaced-comment", rule, {
                 message: "Unexpected space or tab before '*/' in comment.",
                 type: "Block"
             }]
+        },
+
+        // Parser errors
+        {
+            code: invalidShebangProgram,
+            errors: 1,
+            options: ["always"]
+        },
+        {
+            code: invalidShebangProgram,
+            errors: 1,
+            options: ["never"]
         }
     ]
 
diff --git a/tests/lib/testers/rule-tester.js b/tests/lib/testers/rule-tester.js
index e7a44dda6..8342a9f24 100644
--- a/tests/lib/testers/rule-tester.js
+++ b/tests/lib/testers/rule-tester.js
@@ -181,6 +181,20 @@ describe("RuleTester", () => {
         }, /Output is incorrect/);
     });
 
+    it("should throw an error when the expected output doesn't match and errors is just a number", () => {
+
+        assert.throws(() => {
+            ruleTester.run("no-var", require("../../fixtures/testers/rule-tester/no-var"), {
+                valid: [
+                    "bar = baz;"
+                ],
+                invalid: [
+                    { code: "var foo = bar;", output: "foo = bar", errors: 1 }
+                ]
+            });
+        }, /Output is incorrect/);
+    });
+
     it("should throw an error if invalid code specifies wrong type", () => {
 
         assert.throws(() => {
diff --git a/tests/lib/token-store.js b/tests/lib/token-store.js
index 063beda45..a465918f6 100644
--- a/tests/lib/token-store.js
+++ b/tests/lib/token-store.js
@@ -1132,6 +1132,25 @@ describe("TokenStore", () => {
             assert.isNull(result);
         });
 
+        it("should return a comment token when includeComments is true", () => {
+            const result = store.getTokenByRangeStart(15, { includeComments: true });
+
+            assert.equal(result.type, "Block");
+            assert.equal(result.value, "B");
+        });
+
+        it("should not return a comment token at the supplied index when includeComments is false", () => {
+            const result = store.getTokenByRangeStart(15, { includeComments: false });
+
+            assert.isNull(result);
+        });
+
+        it("should not return comment tokens by default", () => {
+            const result = store.getTokenByRangeStart(15);
+
+            assert.isNull(result);
+        });
+
     });
 
     describe("when calling getTokenOrCommentBefore", () => {
diff --git a/tests/lib/util/source-code.js b/tests/lib/util/source-code.js
index e26335255..ef4864f37 100644
--- a/tests/lib/util/source-code.js
+++ b/tests/lib/util/source-code.js
@@ -77,7 +77,7 @@ describe("SourceCode", () => {
 
         });
 
-        it("should throw an error when called with an AST that's missing comments", () => {
+        it("should throw an error when called with an AST that's missing location", () => {
 
             assert.throws(() => {
                 new SourceCode("foo;", { comments: [], tokens: [], range: [] });
@@ -85,7 +85,7 @@ describe("SourceCode", () => {
 
         });
 
-        it("should throw an error when called with an AST that's missing comments", () => {
+        it("should throw an error when called with an AST that's missing range", () => {
 
             assert.throws(() => {
                 new SourceCode("foo;", { comments: [], tokens: [], loc: {} });