Skip to content

Commit

Permalink
Revert "replace rulesMeta by getRuleMeta (refs eslint/rfcs#47)"
Browse files Browse the repository at this point in the history
This reverts commit 0d6afaf.
  • Loading branch information
mysticatea committed Feb 22, 2020
1 parent 1d8beae commit 53f6407
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 164 deletions.
103 changes: 0 additions & 103 deletions lib/cli-engine/formatter-metadata.js

This file was deleted.

4 changes: 1 addition & 3 deletions lib/cli-engine/index.js
@@ -1,9 +1,7 @@
"use strict";

const { CLIEngine } = require("./cli-engine");
const { FormatterMetadata } = require("./formatter-metadata");

module.exports = {
CLIEngine,
FormatterMetadata
CLIEngine
};
15 changes: 13 additions & 2 deletions lib/cli.js
Expand Up @@ -17,7 +17,7 @@

const fs = require("fs"),
path = require("path"),
{ CLIEngine, FormatterMetadata } = require("./cli-engine"),
{ CLIEngine } = require("./cli-engine"),
options = require("./options"),
log = require("./shared/logging"),
RuntimeInfo = require("./shared/runtime-info");
Expand Down Expand Up @@ -83,6 +83,7 @@ function translateOptions(cliOptions) {
*/
function printResults(engine, results, format, outputFile) {
let formatter;
let rulesMeta;

try {
formatter = engine.getFormatter(format);
Expand All @@ -91,7 +92,17 @@ function printResults(engine, results, format, outputFile) {
return false;
}

const output = formatter(results, new FormatterMetadata(engine));
const output = formatter(results, {
get rulesMeta() {
if (!rulesMeta) {
rulesMeta = {};
for (const [ruleId, rule] of engine.getRules()) {
rulesMeta[ruleId] = rule.meta;
}
}
return rulesMeta;
}
});

if (output) {
if (outputFile) {
Expand Down
19 changes: 2 additions & 17 deletions lib/shared/deprecation-warnings.js
Expand Up @@ -31,13 +31,7 @@ const deprecationWarningMessages = {
"ESLint may use plugins that have the same name but different " +
"implementations in each target file. This method will be confused in " +
"such a case. " +
"Please use 'CLIEngine::getRulesForFile(filePath)' method instead.",
ESLINT_LEGACY_RULES_META:
"'metadata.rulesMeta' property in formatters has been deprecated. " +
"ESLint may use plugins that have the same name but different " +
"implementations in each target file. This method will be confused in " +
"such a case. " +
"Please use 'metadata.getRuleMeta(ruleId, filePath)' method instead."
"Please use 'CLIEngine::getRulesForFile(filePath)' method instead."
};

/**
Expand All @@ -59,19 +53,10 @@ const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
);
}, (...args) => JSON.stringify(args));

/**
* Reset warning emission counts.
* @returns {void}
*/
function resetDeprecationWarning() {
emitDeprecationWarning.cache.clear();
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

module.exports = {
emitDeprecationWarning,
resetDeprecationWarning
emitDeprecationWarning
};
2 changes: 0 additions & 2 deletions tests/lib/cli-engine/cli-engine.js
Expand Up @@ -18,7 +18,6 @@ const assert = require("chai").assert,
os = require("os"),
hash = require("../../../lib/cli-engine/hash"),
{ CascadingConfigArrayFactory } = require("../../../lib/cli-engine/cascading-config-array-factory"),
{ resetDeprecationWarning } = require("../../../lib/shared/deprecation-warnings"),
{ unIndent } = require("../_utils"),
{ defineCLIEngineWithInMemoryFileSystem } = require("./_utils");

Expand Down Expand Up @@ -4554,7 +4553,6 @@ describe("CLIEngine", () => {

describe("getRules()", () => {
it("should emit deprecation warning on called.", async() => {
resetDeprecationWarning();
const warningListener = sinon.spy();

process.on("warning", warningListener);
Expand Down
51 changes: 14 additions & 37 deletions tests/lib/cli.js
Expand Up @@ -15,8 +15,7 @@
//------------------------------------------------------------------------------

const assert = require("chai").assert,
{ CLIEngine, FormatterMetadata } = require("../../lib/cli-engine"),
{ resetDeprecationWarning } = require("../../lib/shared/deprecation-warnings"),
CLIEngine = require("../../lib/cli-engine/index").CLIEngine,
path = require("path"),
sinon = require("sinon"),
fs = require("fs"),
Expand Down Expand Up @@ -60,7 +59,7 @@ describe("cli", () => {
sinon.stub(fakeCLIEngine.prototype, "getFormatter").returns(sinon.spy());

const localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -232,28 +231,6 @@ describe("cli", () => {
});

describe("when given a valid built-in formatter name that uses rules meta.", () => {
it("should emit deprecation warning on 'rulesMeta' is used.", async() => {
resetDeprecationWarning();
const warningListener = sinon.spy();

process.on("warning", warningListener);
try {
const filePath = getFixturePath("passing.js");

cli.execute(`-f json-with-metadata ${filePath} --no-eslintrc`);

// Wait for event emission.
await new Promise(resolve => setTimeout(resolve, 0));

// deprecated `rulesMeta` calls deprecated `getRules()` as well.
assert.strictEqual(warningListener.callCount, 2);
assert.strictEqual(warningListener.args[0][0].code, "ESLINT_LEGACY_RULES_META");
assert.strictEqual(warningListener.args[1][0].code, "ESLINT_LEGACY_GET_RULES");
} finally {
process.removeListener("warning", warningListener);
}
});

it("should execute without any errors", () => {
const filePath = getFixturePath("passing.js");
const exit = cli.execute(`-f json-with-metadata ${filePath} --no-eslintrc`);
Expand Down Expand Up @@ -834,7 +811,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.stub();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand All @@ -857,7 +834,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.stub();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -892,7 +869,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().once();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -930,7 +907,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().withExactArgs(report);

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -968,7 +945,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().withExactArgs(report);

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand All @@ -984,7 +961,7 @@ describe("cli", () => {
const fakeCLIEngine = sinon.mock().never();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -1018,7 +995,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().never();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -1049,7 +1026,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.stub();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -1085,7 +1062,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().never();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -1123,7 +1100,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().never();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down Expand Up @@ -1160,7 +1137,7 @@ describe("cli", () => {
fakeCLIEngine.outputFixes = sinon.mock().never();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand All @@ -1175,7 +1152,7 @@ describe("cli", () => {
const fakeCLIEngine = sinon.mock().never();

localCLI = proxyquire("../../lib/cli", {
"./cli-engine/index": { CLIEngine: fakeCLIEngine, FormatterMetadata },
"./cli-engine/index": { CLIEngine: fakeCLIEngine },
"./shared/logging": log
});

Expand Down

0 comments on commit 53f6407

Please sign in to comment.