Skip to content

Commit

Permalink
chore: update rule configs for all plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 1, 2024
1 parent d76c5cd commit 7bb92bf
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 95 deletions.
2 changes: 2 additions & 0 deletions docs/eslint-base/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ Use spread syntax instead of `Function.prototype.apply`. Note however that this

We require all return statements to be either explicitly returning a value or implicitly returning `undefined` (in case of `void`-returning functions). Because most of our code is already type-checked by TypeScript, which surfaces the implicitly returned `undefined` in the return type, this rule is more for aesthetic purposes. It also helps us find all possible return values at a glance.

`return voidFunction()` is also not allowed. Use `voidFunction(); return;` instead. This makes it easier to tell if a function is returning a value or not. For this reason, we turn off the typescript-eslint rule `@typescript-eslint/consistent-return`, because it needs type information and is not useful for our style.

### [`no-useless-return`](https://eslint.org/docs/rules/no-useless-return)

- Severity: error
Expand Down
6 changes: 6 additions & 0 deletions docs/typescript/type-checked.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Never use bracket notation to access properties. In TypeScript, we don't use `pr

You should only await on values that may be thenable. A value that is definitely not thenable should not be awaited because it makes the code harder to track and also defers all remaining code to the next tick.

### [`use-unknown-in-catch-callback-variables`](https://typescript-eslint.io/rules/use-unknown-in-catch-callback-variables/)

- Severity: error

Caught errors should always use `unknown` instead of `any`. While `try...catch` is already enforced by the `useUnknownInCatchVariables` option, `Promise#catch` can only be checked by the linter.

## Modules

### [`consistent-type-exports`](https://typescript-eslint.io/rules/consistent-type-exports/)
Expand Down
15 changes: 9 additions & 6 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-jc",
"version": "5.1.0",
"version": "5.2.0",
"description": "Josh-Cena's personal coding style",
"type": "module",
"repository": {
Expand Down Expand Up @@ -36,20 +36,23 @@
"prepublishOnly": "yarn build"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-n": "^17.2.1",
"eslint-plugin-n": "^17.4.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-regexp": "^2.5.0",
"globals": "^15.0.0",
"typescript-eslint": "^7.7.0"
"typescript-eslint": "^7.8.0"
},
"devDependencies": {
"@types/eslint-config-prettier": "^6.11.3"
},
"peerDependencies": {
"eslint": "^8.57.0"
}
}
8 changes: 6 additions & 2 deletions packages/eslint-config/src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ export default tseslint.config({

"react/iframe-missing-sandbox": "error",

"react/jsx-boolean-value": ["error", "never"],
"react/jsx-boolean-value": [
"error",
"never",
{ assumeUndefinedIsFalse: false },
],

"react/jsx-child-element-spacing": "warn",

Expand Down Expand Up @@ -381,7 +385,7 @@ export default tseslint.config({
"react/no-unknown-property": [
"error",
{
// TODO: not released: requireDataLowercase: true,
requireDataLowercase: true,
},
],

Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-config/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export default tseslint.config({

"n/prefer-global/url-search-params": ["error", "always"],

"n/prefer-node-protocol": "error",

"n/prefer-promises/dns": "error",

"n/prefer-promises/fs": "error",
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-config/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export default tseslint.config({

"react/boolean-prop-naming": "off",

"react/checked-requires-onchange-or-readonly": [
"error",
{
ignoreExclusiveCheckedAttribute: false,
ignoreMissingProperties: false,
},
],

// Sometimes we do need `props` as a whole, e.g. for spreading
"react/destructuring-assignment": "off",

Expand Down
28 changes: 20 additions & 8 deletions packages/eslint-config/src/regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default tseslint.config({

"regexp/no-contradiction-with-assertion": "error",


"no-control-regex": "off",
"regexp/no-control-character": "error",

Expand All @@ -49,7 +48,6 @@ export default tseslint.config({

"regexp/no-empty-capturing-group": "error",


"no-empty-character-class": "off",
"regexp/no-empty-character-class": "error",

Expand All @@ -63,7 +61,6 @@ export default tseslint.config({

"regexp/no-extra-lookaround-assertions": "error",


"no-invalid-regexp": "off",
"regexp/no-invalid-regexp": "error",

Expand All @@ -78,7 +75,6 @@ export default tseslint.config({
{ reportBacktrackingEnds: true },
],


"no-misleading-character-class": "off",
"regexp/no-misleading-unicode-character": ["error", { fixable: false }],

Expand Down Expand Up @@ -108,11 +104,15 @@ export default tseslint.config({

"regexp/no-trivially-nested-quantifier": "error",

"regexp/no-unused-capturing-group": "warn",
"regexp/no-unused-capturing-group": [
"warn",
{
allowNamed: false,
},
],

"regexp/no-useless-assertions": "error",


"no-useless-backreference": "off",
"regexp/no-useless-backreference": "error",

Expand Down Expand Up @@ -157,7 +157,6 @@ export default tseslint.config({

"regexp/prefer-named-backreference": "error",


"prefer-named-capture-group": "off",
"regexp/prefer-named-capture-group": "warn",

Expand Down Expand Up @@ -190,7 +189,7 @@ export default tseslint.config({
"regexp/prefer-w": "error",

"require-unicode-regexp": "off",

"regexp/require-unicode-regexp": "error",

// Maybe in the future?
Expand All @@ -208,6 +207,19 @@ export default tseslint.config({

"regexp/unicode-escape": ["error", "unicodeEscape"],

"regexp/unicode-property": [
"error",
{
generalCategory: "never",
key: "short",
property: {
binary: "long",
generalCategory: "long",
script: "long",
},
},
],

"regexp/use-ignore-case": "error",
},
});
11 changes: 10 additions & 1 deletion packages/eslint-config/src/typescript-typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export default tseslint.config({
// https://jc-verse.github.io/js-style-guide/typescript/type-checked#await-thenable
"@typescript-eslint/await-thenable": "error",

// Not worth turning on
"@typescript-eslint/consistent-return": "off",

// Also enforced by --isolatedModules
// https://jc-verse.github.io/js-style-guide/typescript/type-checked#consistent-type-exports
"@typescript-eslint/consistent-type-exports": [
Expand Down Expand Up @@ -93,7 +96,10 @@ export default tseslint.config({

"@typescript-eslint/prefer-return-this-type": "warn",

"@typescript-eslint/prefer-string-starts-ends-with": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": [
"warn",
{ allowSingleElementEquality: "never" },
],

// Not useful. Sometimes we intentionally make the function non-async.
"@typescript-eslint/promise-function-async": "off",
Expand All @@ -108,6 +114,7 @@ export default tseslint.config({
"warn",
{
allowAny: false,
allowArray: false,
allowBoolean: false,
allowNullish: false,
allowNumber: true,
Expand All @@ -122,5 +129,7 @@ export default tseslint.config({

// Not very useful in practice... A lot of false-positives
"@typescript-eslint/unbound-method": "off",

"@typescript-eslint/use-unknown-in-catch-callback-variables": "error",
},
});
Loading

0 comments on commit 7bb92bf

Please sign in to comment.