Skip to content

Commit

Permalink
hide linterMapSymbol
Browse files Browse the repository at this point in the history
  • Loading branch information
fa93hws committed Jun 21, 2020
1 parent 66d011f commit 78a1393
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
4 changes: 1 addition & 3 deletions lib/rule-tester/index.js
@@ -1,5 +1,3 @@
"use strict";

module.exports = {
RuleTester: require("./rule-tester")
};
module.exports = require("./rule-tester");
25 changes: 21 additions & 4 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -100,6 +100,12 @@ const espreePath = require.resolve("espree");
* @property {number} [endColumn] The 1-based column number of the reported end location.
*/

/**
* The private data for `RuleTester` instance.
* @typedef {Object} RuleTesterInternalSlots
* @property {symbol} injectedLinterMapSymbol symbol key for injected linterMap
*/

//------------------------------------------------------------------------------
// Private Members
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -312,6 +318,14 @@ function describeDefaultHandler(text, method) {
return method.call(this);
}

/**
* The map to store private data.
* @type {RuleTesterInternalSlots}
*/
const internalSlotsMap = {
injectedLinterMapSymbol: Symbol("linterMap")
};

class RuleTester {

/**
Expand Down Expand Up @@ -417,9 +431,9 @@ class RuleTester {
* @param {{
* valid: (ValidTestCase | string)[],
* invalid: InvalidTestCase[],
* linterMapDevOnly?: Map<string | undefined, Linter>
* Symbol("linterMap")?: Map<string | undefined, Linter>
* }} test The collection of tests to run.
* test.linterMapDevOnly is for testing purpose
* test.[Symbol.for("linterMap")] is for testing purpose
* @returns {void}
*/
run(ruleName, rule, test) {
Expand All @@ -438,7 +452,7 @@ class RuleTester {
* Injection of value in `test` is for test purpose.
* @type {Map<string | undefined, Linter>}
*/
const { linterMapDevOnly: linterMap = new Map() } = test;
const { [internalSlotsMap.injectedLinterMapSymbol]: linterMap = new Map() } = test;

requiredScenarios.forEach(scenarioType => {
if (lodash.isNil(test[scenarioType])) {
Expand Down Expand Up @@ -912,4 +926,7 @@ class RuleTester {

RuleTester[DESCRIBE] = RuleTester[IT] = null;

module.exports = RuleTester;
module.exports = {
RuleTester,
internalSlotsMap
};
7 changes: 4 additions & 3 deletions tests/lib/rule-tester/rule-tester.js
Expand Up @@ -9,7 +9,7 @@
//------------------------------------------------------------------------------
const sinon = require("sinon"),
EventEmitter = require("events"),
{ RuleTester } = require("../../../lib/rule-tester"),
{ RuleTester, internalSlotsMap } = require("../../../lib/rule-tester"),
{ Linter } = require("../../../lib/linter"),
assert = require("chai").assert,
nodeAssert = require("assert"),
Expand Down Expand Up @@ -759,7 +759,8 @@ describe("RuleTester", () => {
[undefined, linter]
]);

// ruleTester = new RuleTester({ linterMapDevOnly: linterMap });
const { injectedLinterMapSymbol } = internalSlotsMap;

ruleTester = new RuleTester();
ruleTester.run("no-eval", require("../../fixtures/testers/rule-tester/no-eval"), {
valid: [
Expand All @@ -774,7 +775,7 @@ describe("RuleTester", () => {
errors: [{ line: 1 }]
}
],
linterMapDevOnly: linterMap
[injectedLinterMapSymbol]: linterMap
});
assert.strictEqual(spy.args[1][1].parser, require.resolve("esprima"));
});
Expand Down

0 comments on commit 78a1393

Please sign in to comment.