Skip to content

Commit

Permalink
feat: streamlined eslint.config.js with better tseslint.config usage (#…
Browse files Browse the repository at this point in the history
…1697)

## PR Checklist

- [x] Addresses an existing open issue: fixes #1690
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Applies the changes in the issue. This brings the file line count
-including comments- from 166 to 140.

Removes the `files: ["**/*.md/*.ts"],` from this repo's
`eslint.config.js` because there's no `ts` codeblock in the README.md.

Updates the `typescript-eslint` package by necessity for the
`defaultProject` default.

💖
  • Loading branch information
JoshuaKGoldberg authored Nov 25, 2024
1 parent a8d9c3c commit f43d17f
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 257 deletions.
52 changes: 13 additions & 39 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default tseslint.config(
packageJson,
perfectionist.configs["recommended-natural"],
regexp.configs["flat/recommended"],
...tseslint.config({
{
extends: [
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
Expand All @@ -59,23 +59,13 @@ export default tseslint.config(
parserOptions: {
projectService: {
allowDefaultProject: ["*.config.*s", "bin/*.js", "script/*.ts"],
defaultProject: "./tsconfig.json",
},
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
// These off-by-default rules work well for this repo and we like them on.
"logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
],
"operator-assignment": "error",

// These on-by-default rules don't work well for this repo and we like them off.
"jsdoc/lines-before-block": "off",
"no-constant-condition": "off",

// These on-by-default rules work well for this repo if configured
"@typescript-eslint/no-unnecessary-condition": [
Expand All @@ -84,7 +74,6 @@ export default tseslint.config(
allowConstantLoopConditions: true,
},
],
"@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }],
"@typescript-eslint/prefer-nullish-coalescing": [
"error",
{ ignorePrimitives: true },
Expand All @@ -97,47 +86,32 @@ export default tseslint.config(
"error",
{ allowExperimental: true },
],
"perfectionist/sort-objects": [
"error",
{
order: "asc",
partitionByComment: true,
type: "natural",
},
],

// Stylistic concerns that don't interfere with Prettier
"logical-assignment-operators": [
"error",
"always",
{ enforceForIfStatements: true },
],
"no-useless-rename": "error",
"object-shorthand": "error",
"operator-assignment": "error",
},
}),
{
files: ["*.jsonc"],
rules: {
"jsonc/comma-dangle": "off",
"jsonc/no-comments": "off",
"jsonc/sort-keys": "error",
settings: {
perfectionist: {
partitionByComment: true,
type: "natural",
},
},
},
{
extends: [tseslint.configs.disableTypeChecked],
files: ["**/*.md/*.ts"],
rules: {
"n/no-missing-import": [
"error",
{ allowModules: ["create-typescript-app"] },
],
},
},
{
extends: [vitest.configs.recommended],
files: ["**/*.test.*"],
languageOptions: {
globals: vitest.environments.env.globals,
},
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,

// These on-by-default rules aren't useful in test files.
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"tsup": "^8.3.0",
"tsx": "^4.17.0",
"typescript": "^5.6.2",
"typescript-eslint": "^8.1.0",
"typescript-eslint": "^8.15.0",
"vitest": "^2.1.0"
},
"engines": {
Expand Down
Loading

0 comments on commit f43d17f

Please sign in to comment.