sindresorhus/eslint-plugin-unicorn

Rule proposal: `prefer-private-class-fields`

Fechada

#979 aberto em 1 de jan. de 2021

 (7 comentários) (9 reações) (0 responsável)JavaScript (468 forks)user submission
help wantednew rule

Métricas do repositório

Stars
 (5.022 estrelas)
Métricas de merge de PR
 (Mesclagem média 4h 30m) (26 fundiu PRs em 30d)

Description

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields

Prefer private fields over the convention of underscore prefixed names.

This feature requires Node.js 12, so we cannot add it to the recommended preset until April 2021 (date of Node.js 10 obsoletion).

Does ESLint support this feature yet?

Fail

class Foo {
	static _PRIVATE_STATIC_FIELD

	_privateField

	_privateMethod() {
		return 'hello world'
	}
}

Pass

class Foo {
	static #PRIVATE_STATIC_FIELD

	#privateField

	#privateMethod() {
		return 'hello world'
	}
}

Guia do colaborador