question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support class fields with lines-between-class-members

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.1.0
  • Node Version: 12.6.0
  • npm Version: 6.10.0

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint

Please show your full configuration:

Configuration
module.exports = {
  root: true,
  parser: 'babel-eslint',
  env: {
    node: true
  },
  extends: [
    'standard',
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:prettier/recommended'
  ],
  plugins: [],
  settings: {
    'import/resolver': {
      node: { extensions: ['.js', '.mjs'] }
    }
  },
  rules: {
    curly: ['error', 'all'],
    'dot-notation': 'error',
    'import/first': 'error',
    'import/no-mutable-exports': 'error',
    'import/no-unresolved': 'off',
    'import/order': 'error',
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-lonely-if': 'error',
    'no-useless-rename': 'error',
    'no-var': 'error',
    'object-shorthand': 'error',
    'padding-line-between-statements': [
      'error',
      { blankLine: 'always', prev: 'block-like', next: '*' },
      { blankLine: 'always', prev: 'break', next: '*' },
      { blankLine: 'always', prev: '*', next: 'class' },
      { blankLine: 'always', prev: '*', next: 'default' },
      { blankLine: 'always', prev: '*', next: 'do' },
      { blankLine: 'always', prev: '*', next: 'for' },
      { blankLine: 'always', prev: '*', next: 'function' },
      { blankLine: 'always', prev: '*', next: 'if' },
      { blankLine: 'always', prev: '*', next: 'iife' },
      { blankLine: 'always', prev: '*', next: 'switch' },
      { blankLine: 'always', prev: '*', next: 'try' },
      { blankLine: 'always', prev: '*', next: 'while' }
    ],
    'prefer-const': 'error',
    'require-await': 'error'
  }
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

class SocketServer {
  #closing = false
  #connections = []
  #logger
  #message = ''
  #messageHandler
  #port
  #server

  constructor() {}
}
npx eslint .

What did you expect to happen? I expected no error for the private class fields after the first.

What actually happened? Please include the actual, raw output from ESLint.

I got errors for all private class fields after the first.

/Users/aparajita/Developer/projects/clients/willsub/js/socket-server/index.js
  20:3  error  Expected blank line between class members  lines-between-class-members
  21:3  error  Expected blank line between class members  lines-between-class-members
  22:3  error  Expected blank line between class members  lines-between-class-members
  23:3  error  Expected blank line between class members  lines-between-class-members
  24:3  error  Expected blank line between class members  lines-between-class-members
  25:3  error  Expected blank line between class members  lines-between-class-members

✖ 6 problems (6 errors, 0 warnings)
  6 errors and 0 warnings potentially fixable with the `--fix` option.

This is related to #11153, which was closed in January because class fields are currently Stage 3.

However, since then support for this is out there by default, no --experimental flag required:

Babel 7.0+
Node 12
Public fields are enabled by default in Chrome 72 / V8 7.2
Private fields are enabled by default in Chrome 74 / V8 7.4
Partial, in-progress support in Firefox 67

Further implementations are on the way:

In progress in TypeScript
Out for review in Safari/JSC
In progress in Firefox/SpiderMonkey

Given the wide support for this language feature, I’m hoping you will reconsider waiting for it to reach Stage 4 before supporting it in eslint.

Are you willing to submit a pull request to fix this bug?

Maybe.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aparajitacommented, Aug 8, 2019

FYI, I submitted a PR at babel/eslint-plugin-babel.

1reaction
kaicataldocommented, Aug 7, 2019

There have been exceptions in the past, and we decided to clarify this policy in an effort to be clearer and more consistent. Is the rule currently crashing? If so, we would definitely want to fix that (as per our policy). Otherwise, I suggest making an issue in https://github.com/babel/eslint-plugin-babel to see if a modified version of the rule can be added there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

lines-between-class-members | typescript-eslint
This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the...
Read more >
lines-between-class-members - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
typescript-eslint/lines-between-class-members.md at main
This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the...
Read more >
"lines-between-class-members" ESLint Error When Declaring ...
Docs It will skips checks for empty lines after a single-line class member. ... https://eslint.org/docs/rules/lines-between-class-members.
Read more >
Require or disallow an empty line between class members ...
This rule extends the base eslint/lines-between-class-members rule. It adds support for ignoring overload methods in a class. See the ESLint ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found