Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Feb 12, 2020
1 parent 937d2ca commit d8f0fa7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions espree.js
Expand Up @@ -62,7 +62,7 @@ const acorn = require("acorn");
const jsx = require("acorn-jsx");
const astNodeTypes = require("./lib/ast-node-types");
const espree = require("./lib/espree");
const { latestEcmaVersion, supportedEcmaVersions } = require("./lib/options");
const { getLatestEcmaVersion, getSupportedEcmaVersions } = require("./lib/options");

// To initialize lazily.
const parsers = {
Expand Down Expand Up @@ -172,6 +172,6 @@ exports.VisitorKeys = (function() {
return require("eslint-visitor-keys").KEYS;
}());

exports.latestEcmaVersion = latestEcmaVersion;
exports.getLatestEcmaVersion = getLatestEcmaVersion;

exports.supportedEcmaVersions = supportedEcmaVersions;
exports.getSupportedEcmaVersions = getSupportedEcmaVersions;

This comment has been minimized.

Copy link
@nzakas

nzakas Feb 12, 2020

Member

Another thought: because these values don’t change during the life of the object, you could export the final values rather than the functions, like:

exports.latestEcmaVersion = getLatestEcmaVersion();
10 changes: 5 additions & 5 deletions lib/options.js
Expand Up @@ -82,15 +82,15 @@ function normalizeOptions(options) {
* Get the latest ECMAScript version supported by Espree.
* @returns {number} The latest ECMAScript version.
*/
function latestEcmaVersion() {
return Math.max(...SUPPORTED_VERSIONS);
function getLatestEcmaVersion() {
return SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.length - 1];
}

/**
* Get the list of ECMAScript versions supported by Espree.
* @returns {number[]} An array containing the supported ECMAScript versions.
*/
function supportedEcmaVersions() {
function getSupportedEcmaVersions() {
return [...SUPPORTED_VERSIONS];
}

Expand All @@ -100,6 +100,6 @@ function supportedEcmaVersions() {

module.exports = {
normalizeOptions,
latestEcmaVersion,
supportedEcmaVersions
getLatestEcmaVersion,
getSupportedEcmaVersions
};
14 changes: 7 additions & 7 deletions tests/lib/supported-ecmaversions.js
@@ -1,5 +1,5 @@
/**
* @fileoverview Tests for latestEcmaVersion() & supportedEcmaVersions().
* @fileoverview Tests for getLatestEcmaVersion() & getSupportedEcmaVersions().
* @author Kai Cataldo
*/

Expand All @@ -16,25 +16,25 @@ const assert = require("assert"),
// Tests
//------------------------------------------------------------------------------

describe("latestEcmaVersion()", () => {
describe("getLatestEcmaVersion()", () => {
it("should return the latest supported ecmaVersion", () => {
assert.strictEqual(espree.latestEcmaVersion(), 11);
assert.strictEqual(espree.getLatestEcmaVersion(), 11);
});
});

describe("supportedEcmaVersions()", () => {
describe("getSupportedEcmaVersions()", () => {
it("should return an array of all supported versions", () => {
assert.deepStrictEqual(
espree.supportedEcmaVersions(),
espree.getSupportedEcmaVersions(),
[3, 5, 6, 7, 8, 9, 10, 11]
);
});

it("the array of supported versions should not be mutable by reference", () => {
const supportedVersions = espree.supportedEcmaVersions();
const supportedVersions = espree.getSupportedEcmaVersions();
const originalValue = [...supportedVersions];

supportedVersions.push("a", "b", "c");
assert.deepStrictEqual(espree.supportedEcmaVersions(), originalValue);
assert.deepStrictEqual(espree.getSupportedEcmaVersions(), originalValue);
});
});

0 comments on commit d8f0fa7

Please sign in to comment.