1/** 2 * @fileoverview Provide the function that emits deprecation warnings. 3 * @author Toru Nagashima <http://github.com/mysticatea> 4 */ 5"use strict"; 6 7//------------------------------------------------------------------------------ 8// Requirements 9//------------------------------------------------------------------------------ 10 11const path = require("path"); 12const lodash = require("lodash"); 13 14//------------------------------------------------------------------------------ 15// Private 16//------------------------------------------------------------------------------ 17 18// Defitions for deprecation warnings. 19const deprecationWarningMessages = { 20 ESLINT_LEGACY_ECMAFEATURES: 21 "The 'ecmaFeatures' config file property is deprecated and has no effect.", 22 ESLINT_PERSONAL_CONFIG_LOAD: 23 "'~/.eslintrc.*' config files have been deprecated. " + 24 "Please use a config file per project or the '--config' option.", 25 ESLINT_PERSONAL_CONFIG_SUPPRESS: 26 "'~/.eslintrc.*' config files have been deprecated. " + 27 "Please remove it or add 'root:true' to the config files in your " + 28 "projects in order to avoid loading '~/.eslintrc.*' accidentally." 29}; 30 31/** 32 * Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted 33 * for each unique file path, but repeated invocations with the same file path have no effect. 34 * No warnings are emitted if the `--no-deprecation` or `--no-warnings` Node runtime flags are active. 35 * @param {string} source The name of the configuration source to report the warning for. 36 * @param {string} errorCode The warning message to show. 37 * @returns {void} 38 */ 39const emitDeprecationWarning = lodash.memoize((source, errorCode) => { 40 const rel = path.relative(process.cwd(), source); 41 const message = deprecationWarningMessages[errorCode]; 42 43 process.emitWarning( 44 `${message} (found in "${rel}")`, 45 "DeprecationWarning", 46 errorCode 47 ); 48}, (...args) => JSON.stringify(args)); 49 50//------------------------------------------------------------------------------ 51// Public Interface 52//------------------------------------------------------------------------------ 53 54module.exports = { 55 emitDeprecationWarning 56}; 57