简体   繁体   中英

eslint rule for empty line before the closing bracket

Hi I'm trying to find an eslint rule for empty lines before closing bracket: I'm using react, here there is the example:

const test = () => (
 <div>
  Hello
 </div>
// This should show an error
)

eslint config: package.json

"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.11.1",

.eslintrc

{
  "extends": "airbnb",
  "parser": "babel-eslint",
  "rules": {
    "max-len": ["error", { "code": 80, "ignoreUrls": true }],
    "no-console": [2]
  },
  "env": {
    "browser": true
  }
}

This is specialized enough that there I could not find a standard rule handling it. The closest is padded-blocks for handling empty lines at both the beginning and end of a block. padded-blocks: ["error", "never"] is a default for airbnb and triggers for empty lines. Unfortunately, it applies to braces, not parentheses.

spaces-in-parens does handle the beginnings and ends of parens, but only enforces/bars spaces, not whitespace such as newlines. padding-lines-between-statements would help if there was any way to define the two components as statements - but they are not.

I did not spot a plugin with this functionality, though there are [plenty to look through]. The easiest solution would be to make a custom rule (package) based on padded-blocks , with braces replaced by parens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM