Skip to content

Commit

Permalink
Update for typescript-eslint v6 (#48)
Browse files Browse the repository at this point in the history
### Public-Facing Changes

- Update package version to 1.0.0 since the package has been stable for
quite a while.

**Breaking changes:**

- Updated peer and dev dependencies to v6 of typescript-eslint packages
- Updated `plugin:@foxglove/typescript` config to be based on new
`strict-type-checked` and `stylistic-type-checked` configs from upstream
  - This adds several new rules that may require disabling or fixing.
- Deleted `no-private-identifier` rule (see #46)
- Enabled `prefer-hash-private` by default

### Description

See typescript-eslint v6 release notes:
https://typescript-eslint.io/blog/announcing-typescript-eslint-v6/

- `checkCompoundAssignments: true` is now the default for
`restrict-plus-operands`
- Switched from `@typescript-eslint/recommended` +
`@typescript-eslint/recommended-requiring-type-checking` to
`@typescript-eslint/strict-type-checked` +
`@typescript-eslint/stylistic-type-checked`
- `prefer-nullish-coalescing` and `prefer-optional-chain` are now on by
default
- Switched to `@typescript-eslint/rule-tester` for `RuleTester`
  • Loading branch information
jtbandes authored Sep 5, 2023
1 parent df51e99 commit e4c9661
Show file tree
Hide file tree
Showing 12 changed files with 1,835 additions and 1,928 deletions.
1 change: 1 addition & 0 deletions configs/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
// require double equal for null and undefined, triple equal everywhere else
"@foxglove/strict-equality": "error",
"@foxglove/no-return-promise-resolve": "error",
"@foxglove/prefer-hash-private": "error",

// require curly braces everywhere
curly: "error",
Expand Down
10 changes: 9 additions & 1 deletion configs/typescript.example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

void (async () => {
await 1; // eslint-disable-line @typescript-eslint/await-thenable
await (function () {})(); // eslint-disable-line @typescript-eslint/await-thenable, @typescript-eslint/no-empty-function
await (function () {})(); // eslint-disable-line @typescript-eslint/await-thenable, @typescript-eslint/no-empty-function, @typescript-eslint/no-confusing-void-expression
await (async function () {})(); // eslint-disable-line @typescript-eslint/no-empty-function
})();

Expand Down Expand Up @@ -34,5 +34,13 @@ void undefined; // eslint-disable-line @typescript-eslint/no-meaningless-void-op
42; // eslint-disable-line @typescript-eslint/no-unused-expressions
<></>; // eslint-disable-line @typescript-eslint/no-unused-expressions

class C {
private x = 1; // eslint-disable-line @foxglove/prefer-hash-private
constructor() {
void this.x;
}
}
void C;

// keep isolatedModules happy
export default {};
26 changes: 17 additions & 9 deletions configs/typescript.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
module.exports = {
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:import/typescript",
],
parser: "@typescript-eslint/parser",
rules: {
// Avoid #member syntax for performance
"@foxglove/no-private-identifier": "error",
"@typescript-eslint/no-meaningless-void-operator": [
"error",
{ checkNever: true },
Expand Down Expand Up @@ -52,16 +50,11 @@ module.exports = {
],

"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/promise-function-async": "error",

// Async functions without await are used to satisfy interface requirements
"@typescript-eslint/require-await": "off",

// both sides of `+` must be either string or number
"@typescript-eslint/restrict-plus-operands": "error",

"@typescript-eslint/return-await": ["error", "always"],

// require all cases to be checked in switch statements
Expand All @@ -81,5 +74,20 @@ module.exports = {
allowAny: false,
},
],

"@typescript-eslint/prefer-nullish-coalescing": [
"error",
{ ignoreConditionalTests: true },
],

// We find the following rules from the strict/stylistic configs to be overly pedantic and not
// so useful
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/array-type": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/unified-signatures": "off",
},
};
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
rules: {
"license-header": require("./rules/license-header"),
"no-private-identifier": require("./rules/no-private-identifier"),
"strict-equality": require("./rules/strict-equality"),
"no-return-promise-resolve": require("./rules/no-return-promise-resolve"),
"no-boolean-parameters": require("./rules/no-boolean-parameters"),
Expand Down
Loading

0 comments on commit e4c9661

Please sign in to comment.