Skip to content

Commit

Permalink
feat!: drop support for string configurations in flat config array (#…
Browse files Browse the repository at this point in the history
…17717)

Drops support for "eslint:recommended" and "eslint:all" string
configurations in flat config arrays.

Fixes #17488
  • Loading branch information
mdjermanovic committed Dec 20, 2023
1 parent c314fd6 commit c2cf85a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 55 deletions.
20 changes: 0 additions & 20 deletions lib/config/flat-config-array.js
Expand Up @@ -13,7 +13,6 @@ const { ConfigArray, ConfigArraySymbol } = require("@humanwhocodes/config-array"
const { flatConfigSchema } = require("./flat-config-schema");
const { RuleValidator } = require("./rule-validator");
const { defaultConfig } = require("./default-config");
const jsPlugin = require("@eslint/js");

//-----------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -134,25 +133,6 @@ class FlatConfigArray extends ConfigArray {
* @returns {Object} The preprocessed config.
*/
[ConfigArraySymbol.preprocessConfig](config) {
if (config === "eslint:recommended") {

// if we are in a Node.js environment warn the user
if (typeof process !== "undefined" && process.emitWarning) {
process.emitWarning("The 'eslint:recommended' string configuration is deprecated and will be replaced by the @eslint/js package's 'recommended' config.");
}

return jsPlugin.configs.recommended;
}

if (config === "eslint:all") {

// if we are in a Node.js environment warn the user
if (typeof process !== "undefined" && process.emitWarning) {
process.emitWarning("The 'eslint:all' string configuration is deprecated and will be replaced by the @eslint/js package's 'all' config.");
}

return jsPlugin.configs.all;
}

/*
* If `shouldIgnore` is false, we remove any ignore patterns specified
Expand Down
41 changes: 6 additions & 35 deletions tests/lib/config/flat-config-array.js
Expand Up @@ -11,10 +11,6 @@

const { FlatConfigArray } = require("../../../lib/config/flat-config-array");
const assert = require("chai").assert;
const {
all: allConfig,
recommended: recommendedConfig
} = require("@eslint/js").configs;
const stringify = require("json-stable-stringify-without-jsonify");
const espree = require("espree");

Expand Down Expand Up @@ -127,24 +123,6 @@ async function assertInvalidConfig(values, message) {
}, message);
}

/**
* Normalizes the rule configs to an array with severity to match
* how Flat Config merges rule options.
* @param {Object} rulesConfig The rules config portion of a config.
* @returns {Array} The rules config object.
*/
function normalizeRuleConfig(rulesConfig) {
const rulesConfigCopy = {
...rulesConfig
};

for (const ruleId of Object.keys(rulesConfigCopy)) {
rulesConfigCopy[ruleId] = [2];
}

return rulesConfigCopy;
}

//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -630,24 +608,17 @@ describe("FlatConfigArray", () => {

});

describe("Special configs", () => {
it("eslint:recommended is replaced with an actual config", async () => {
const configs = new FlatConfigArray(["eslint:recommended"]);

await configs.normalize();
const config = configs.getConfig("foo.js");
describe("Config array elements", () => {
it("should error on 'eslint:recommended' string config", async () => {

assert.deepStrictEqual(config.rules, normalizeRuleConfig(recommendedConfig.rules));
await assertInvalidConfig(["eslint:recommended"], "All arguments must be objects.");
});

it("eslint:all is replaced with an actual config", async () => {
const configs = new FlatConfigArray(["eslint:all"]);
it("should error on 'eslint:all' string config", async () => {

await configs.normalize();
const config = configs.getConfig("foo.js");

assert.deepStrictEqual(config.rules, normalizeRuleConfig(allConfig.rules));
await assertInvalidConfig(["eslint:all"], "All arguments must be objects.");
});

});

describe("Config Properties", () => {
Expand Down

0 comments on commit c2cf85a

Please sign in to comment.