space-before-keywords
在关键字之前强制执行一致的间距。
(已移除)该规则在 ESLint v2.0 中被移除并被 keyword-spacing 规则所取代。
(可修复)命令行 上的 --fix
选项自动修复了此规则报告的问题。
关键字是 JavaScript 的语法元素,例如 function
和 if
。这些标识符对语言具有特殊意义,因此在代码编辑器中经常以不同的颜色出现。作为语言的重要组成部分,样式指南通常指的是应该在关键字周围使用的间距。例如,您可能有一个样式指南说关键字应该始终以空格开头,这意味着 if-else
语句必须如下所示:
if (foo) {
// ...
} else {
// ...
}
当然,您也可以有一个不允许关键字前有空格的样式指南。
规则详情
MHkc3V+u0VsYb84n2E+vCcH7hmcszXaNPtzUKE6BhC0fvROcwwMITAgDLsDm/Yyvz7Ga18GxZIo+xa85Y6r8TFPFcLbdtdYYm4DxR8ZbOmpyAY2I4v0wEth4A7pUdcDvdlC/Rdqk+WbaTyEmKB4kxtJMtNrSvW9q8YzvvpsdTPjibF88f3K3xUkK+yzUIMlptkQZmQ+Ng5Dp159upNvbdLltTNMgrco0ODvpS3cuEa2L57QiHRQcgeZ91SNube9gLLNgLtrjEuY4RLe1tePdbInz4MZ5jqYb/AsGW5DDkzm+8d6ha6/QeDCsmiIXzjFJ/Z73uUxfeP3hv65HmRk7tMDLTsrZi2qdMyrn37DIf24l5n7fT4SBkJNpWcOOEoJX3NBuM1EKxu9jgcjjiwS01M94wJIv/Wa814T+jxgzbW2J7JFuQWIUYsduess9YHXVhLPtrYbOeb3IPEpDtRCQAGC7WEuF5j8g2KEDyj9BI2kI3Sb5CdacZEBBSvufpKEzhKndyDCU3u+6zOkgdS82zHnTrBrdQAr8nEWFb3rv+VgGZugCfgVu0HJvGXa+Arj8JA2hxPL+fCzznY9u6vi1eUdUyT3912G8BSZnTrpOQ6yX3I/1J1oZN47aFggtkyyfj4+NSU4osBaYRThQFrRtkSs65vwfQUA1IZHDQ/lKhtE=
lv76LUpwk80ZWNWSi3TH8nxMBEV6Fj2GzNQsREwZv9qlKeDtdRxI8xyDEElUlbcZQ3Spkt1EC5UTjNOpWLBbq3ftK0hYxWZQjfx+OLV0Gip0Gb8E3W8M0GjD2vFZ5boTaJUL2zcV7teTwPem2bzqi+Gs5sD02MfrMrnlnNxexmR1m2cthmyXtNHqLrmSBI29JLqvoWzSnAeEHezlVvh4ZPryslXuq8m7xhYTz70m7EK5ZfzvttFiIwEt/V3nexfIAQbW56L1mjkVje6yVWgCM1rcJNcYgyRzAtqp2uTMTJYIotsi5wZ6ubDUTVDVVlJwPuBzn7QBBX4TvQ/dnsQVQC1iRzPGP+5LN5sLYrhLp4zn4wxNxHkjisa7Ls3cZg4nNuB9Fyfpwp/XBQy1OGDijVDT3umXCPjND8DPCOjOdn8tvjuAzn7hn7bUXzIj+CBVIeWjI4bJn93D6feebLResc4y/i60yv0JooX16ZjwFU8Ptrlb83VWVbzA0SvWK31f
Jz/PGC0KioZIYWAquTSNrEfuuZYnwyEEXqUlG/0IpRnAacvntnBfE61L+9brRhvlCRJEV5WvaRsGpvYTfwSyehrOEdS8zpFCmsrhSPnGW0LJ6uxDTQU//ysv4+ArAHlMunO2sMfBPVLS8kOnNZZx5wOzTNLs3PT7/wj7FIq69JYNX3+RC5Z4DQvmeCcMGm8uEtPvNUb+iHTG3Pd0wnkotMGtd12g3Y5W7Hz7+kKEJpwXThAM67CASHIEr5HWufZP1Az12jLcNvQ3OGhYbWqItg==
6OjE+A1hvEglXN51x/s/8uZtOgB+xUuBU8wX5Pw6bMlgFgYyiCngBbb9IXR0IzxRqvgTUPD6/Z3CWcx8D3ijpAwjZYsueQ3Vhvdcqf+mHdY=
/*eslint space-before-keywords: ["error", "always"]*/
/*eslint-env es6*/
if (foo) {
// ...
}else {}
const foo = 'bar';let baz = 'qux';
var foo =function bar () {}
function bar() {
if (foo) {return; }
}
6OjE+A1hvEglXN51x/s/8uZtOgB+xUuBU8wX5Pw6bMlgFgYyiCngBbb9IXR0IzxRqM2u9+zXH+sOX5Zvln60C1/4tETr3VM+M2ewWx+mdgs=
/*eslint space-before-keywords: ["error", "always"]*/
/*eslint-env es6*/
if (foo) {
// ...
} else {}
(function() {})()
<Foo onClick={function bar() {}} />
for (let foo of ['bar', 'baz', 'qux']) {}
7xDYtjDnSQq8pZ502SNO6iSbSSgf88JvINV+VW/7mjjjFiN9kgk1SZeCsyIjd2Dk8k6MmZcA+2HbZXyreFXjTqy/sqwbdiiEliJLfZHfH0U=
/*eslint space-before-keywords: ["error", "never"]*/
if (foo) {
// ...
} else {}
do {
}
while (foo)
try {} finally {}
try {} catch(e) {}
7xDYtjDnSQq8pZ502SNO6iSbSSgf88JvINV+VW/7mjglYsFdA9pWHwqRpV9joLGkNKHwlcyw6ZkK4XHAI0leF18G96W/FEOjyH7wSDDTYP0=
/*eslint space-before-keywords: ["error", "never"]*/
if (foo) {
// ...
}else {}
do {}while (foo)
try {}finally {}
try{}catch(e) {}
何时不使用
nPPcnFY3jOorTAT9QdglgGP3blPJz97ytas6AOEB9wJnYIX/VxwrBswhuaZSH7JX8nR0At7kOZIJc2Fa3ABueA==