【问题标题】:Eslint configuration for padded-blocks and lines-around-comment rule填充块和行环绕评论规则的 Eslint 配置
【发布时间】:2020-06-25 06:40:20
【问题描述】:

我正在尝试使用 eslint 的 padded-blockslines-around-comment 评论规则。

这是我的 eslint 配置文件。

var OFF = 0, WARN = 1, ERROR = 2;
module.exports = exports = {
    "env": {
        "es6": true,
        "node": true,
        "browser": false,
        "jest": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "ecmaVersion": 2017,
        "sourceType": "module",
        "ecmaFeatures": {
            "modules": false
        }
    },
    "rules": {
		"padded-blocks": [WARN, "never"],
		"lines-around-comment": [WARN, { "beforeBlockComment": true}],
		
    }
};

如果我这样写

class MyClass {

	/**
	 * Creates an instance of MyClass.
	 * @param {Object} arg1 dependency object
	 * @memberof MyClass
	 */
	constructor(arg1) {
		this.var1 = arg1;
	}

	/**
	 * My function
	 *
	 * @memberof MyClass
	 */
	myFunction() {

	}
}

module.exports = MyClass;
我收到 eslint 错误
1:15  warning  Block must not be padded by blank lines  padded-blocks

如果我这样写

class MyClass {
	/**
	 * Creates an instance of MyClass.
	 * @param {Object} arg1 dependency object
	 * @memberof MyClass
	 */
	constructor(arg1) {
		this.var1 = arg1;
	}

	/**
	 * My function
	 *
	 * @memberof MyClass
	 */
	myFunction() {

	}
}

module.exports = MyClass;

我收到这个错误

2:2  warning  Expected line before comment  lines-around-comment

似乎这些规则在课程开始时彼此相反。

我如何忽略 padded-blocks 构造函数命名的规则?

【问题讨论】:

    标签: eslint eslintrc


    【解决方案1】:

    考虑将 ESLint 升级到最新版本。现在应该解决与规则“lines-around-comment”和“padded-blocks”相互冲突的问题。见https://github.com/eslint/eslint/issues/6526

    其实在目前的6.8.0版本中,你的代码的第一个变种lints without warnings

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 1970-01-01
      • 2019-11-10
      • 2017-07-24
      • 2010-10-03
      • 1970-01-01
      • 2017-12-04
      • 2020-09-01
      • 1970-01-01
      相关资源
      最近更新 更多