Skip to content

Commit

Permalink
Update: emit a warning for ecmaFeatures rather than throwing an error (
Browse files Browse the repository at this point in the history
…#8974)

(refs eslint/tsc-meetings#51 (comment))

Starting in 4.0.0, ESLint has been throwing a fatal error when encountering unexpected config file properties, including `ecmaFeatures`. However, many old configs still have the top-level `ecmaFeatures` option, which has had no effect since ESLint 1.x. This commit updates ESLint to emit a warning when it encounters a config with `ecmaFeatures`, rather than throwing an error.
  • Loading branch information
not-an-aardvark committed Jul 24, 2017
1 parent d2f8f9f commit 3d020b9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conf/config-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const baseConfigProperties = {
parserOptions: { type: "object" },
plugins: { type: "array" },
rules: { type: "object" },
settings: { type: "object" }
settings: { type: "object" },

ecmaFeatures: { type: "object" } // deprecated; logs a warning when used
};

const overrideProperties = Object.assign(
Expand Down
24 changes: 24 additions & 0 deletions lib/config/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//------------------------------------------------------------------------------

const ajv = require("../util/ajv"),
lodash = require("lodash"),
configSchema = require("../../conf/config-schema.js"),
util = require("util");

Expand Down Expand Up @@ -179,6 +180,25 @@ function formatErrors(errors) {
}).map(message => `\t- ${message}.\n`).join("");
}

/**
* Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
* for each unique file path, but repeated invocations with the same file path have no effect.
* No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active.
* @param {string} source The name of the configuration source to report the warning for.
* @returns {void}
*/
const emitEcmaFeaturesWarning = lodash.memoize(source => {

/*
* util.deprecate seems to be the only way to emit a warning in Node 4.x while respecting the --no-warnings flag.
* (In Node 6+, process.emitWarning could be used instead.)
*/
util.deprecate(
() => {},
`[eslint] The 'ecmaFeatures' config file property is deprecated, and has no effect. (found in ${source})`
)();
});

/**
* Validates the top level properties of the config object.
* @param {Object} config The config object to validate.
Expand All @@ -191,6 +211,10 @@ function validateConfigSchema(config, source) {
if (!validateSchema(config)) {
throw new Error(`ESLint configuration in ${source} is invalid:\n${formatErrors(validateSchema.errors)}`);
}

if (Object.prototype.hasOwnProperty.call(config, "ecmaFeatures")) {
emitEcmaFeaturesWarning(source);
}
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ describe("bin/eslint.js", () => {
});
});


describe("emitting a warning for ecmaFeatures", () => {
it("does not emit a warning when it does not find an ecmaFeatures option", () => {
const child = runESLint(["Makefile.js"]);

const exitCodePromise = assertExitCode(child, 0);
const outputPromise = getOutput(child).then(output => assert.strictEqual(output.stderr, ""));

return Promise.all([exitCodePromise, outputPromise]);
});
it("emits a warning when it finds an ecmaFeatures option", () => {
const child = runESLint(["-c", "tests/fixtures/config-file/ecma-features/.eslintrc.yml", "Makefile.js"]);

const exitCodePromise = assertExitCode(child, 0);
const outputPromise = getOutput(child).then(output => {
assert.include(output.stderr, "The 'ecmaFeatures' config file property is deprecated, and has no effect.");
});

return Promise.all([exitCodePromise, outputPromise]);
});
});

afterEach(() => {

// Clean up all the processes after every test.
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/config-file/ecma-features/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ecmaFeatures: {}

0 comments on commit 3d020b9

Please sign in to comment.