Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce no-underscore-dangle in method names and class fields #79

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ module.exports = {
'no-throw-literal': 'error',
'no-undef-init': 'error',
// 'no-undefined': 'error',
// 'no-underscore-dangle': 'error',
'no-underscore-dangle': [
'error',
{
enforceInMethodNames: true,
enforceInClassFields: true,
},
],
'no-unneeded-ternary': 'error',
'no-unused-expressions': 'error',
'no-useless-call': 'error',
Expand Down
37 changes: 37 additions & 0 deletions packages/test-eslint-config/noUnderscoreDangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable no-unused-expressions, no-unused-vars */

const [_first, _second, third] = [];
const { _foo, _bar, baz } = {
_foo: 'foo',
_bar: 'bar',
baz: 'baz',
};

// eslint-disable-next-line no-underscore-dangle
const _qux = '_qux';
const qux = 'qux';

class MyClass {
// eslint-disable-next-line no-underscore-dangle
_variable = 'foo';
#variable = 'bar';

constructor() {
// eslint-disable-next-line no-underscore-dangle
this._variable;
this.#variable;

// eslint-disable-next-line no-underscore-dangle
this._privateMethod();
this.#privateMethod();
}

// eslint-disable-next-line no-underscore-dangle
_privateMethod() {
this.#variable = Math.random();
}

#privateMethod() {
this.#variable = Math.random();
}
}
5 changes: 4 additions & 1 deletion packages/test-eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"eslint": "^8.28.0"
},
"eslintConfig": {
"extends": "@mediamonks/eslint-config"
"extends": "@mediamonks/eslint-config",
"parserOptions": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need this in the docs, or was this only for the #private stuff in the test code?

Copy link
Collaborator Author

@leroykorterink leroykorterink Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was needed to support new private field syntax, I don't think we should explain how to configure the language options for eslint because this can vary between projects. eslint has a full page about configuring the language options.

"ecmaVersion": "latest"
}
}
}