Skip to content

Commit

Permalink
feat(remix-eslint-config): extend from typescript-eslint/recommended (#…
Browse files Browse the repository at this point in the history
…6248)

Co-authored-by: Matt Brophy <matt@brophy.org>
  • Loading branch information
JoshuaKGoldberg and brophdawg11 committed Jun 15, 2023
1 parent 2932981 commit 4a617f6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 47 deletions.
2 changes: 1 addition & 1 deletion packages/remix-dev/__tests__/cli-test.ts
Expand Up @@ -289,7 +289,7 @@ function defer() {
async function interactWithShell(
proc: childProcess.ChildProcessWithoutNullStreams,
qAndA: Array<
| { question: RegExp; type: Array<String>; answer?: never }
| { question: RegExp; type: Array<string>; answer?: never }
| { question: RegExp; answer: RegExp; type?: never }
>
) {
Expand Down
1 change: 0 additions & 1 deletion packages/remix-dev/server-build.ts
@@ -1,4 +1,3 @@
/* eslint-disable no-unreachable */
import type { ServerBuild } from "@remix-run/server-runtime";

throw new Error(
Expand Down
9 changes: 4 additions & 5 deletions packages/remix-eslint-config/index.js
Expand Up @@ -62,15 +62,14 @@ const config = {
overrides: [
{
files: ["**/*.ts?(x)"],
extends: ["plugin:import/typescript"],
extends: [
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
ecmaVersion: 2019,
ecmaFeatures: {
jsx: true,
},
warnOnUnsupportedTypeScriptVersion: true,
},
plugins: ["@typescript-eslint"],
rules: {
Expand Down
1 change: 1 addition & 0 deletions packages/remix-eslint-config/rules/import.js
Expand Up @@ -5,5 +5,6 @@ const ERROR = 2;
module.exports = {
"import/first": ERROR,
"import/no-amd": ERROR,
"import/no-duplicates": ERROR,
"import/no-webpack-loader-syntax": ERROR,
};
59 changes: 29 additions & 30 deletions packages/remix-eslint-config/rules/typescript.js
@@ -1,54 +1,53 @@
const OFF = 0;
const WARN = 1;
const ERROR = 2;

module.exports = {
"no-dupe-class-members": OFF,
"no-undef": OFF,

// Add TypeScript specific rules (and turn off ESLint equivalents)
"@typescript-eslint/consistent-type-assertions": WARN,
"@typescript-eslint/consistent-type-imports": WARN,

"no-array-constructor": OFF,
"@typescript-eslint/no-array-constructor": WARN,

// There is a bug w/ @typescript-eslint/no-duplicate-imports triggered
// by multiple imports inside of module declarations. We should reenable
// this rule when the bug is fixed.
// https://github.com/typescript-eslint/typescript-eslint/issues/3071
"no-duplicate-imports": OFF,
// "@typescript-eslint/no-duplicate-imports": WARN,
// TODO: These rules might be nice to enable... we should investigate eventually!
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"no-var": "off",
"prefer-rest-params": "off",

"no-redeclare": OFF,
"@typescript-eslint/no-redeclare": ERROR,
"no-use-before-define": OFF,
// These rules are nice and we want to configure over the defaults
"@typescript-eslint/no-use-before-define": [
WARN,
"error",
{
functions: false,
classes: false,
variables: false,
typedefs: false,
},
],
"no-unused-expressions": OFF,
"@typescript-eslint/no-unused-expressions": [
WARN,
"error",
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
},
],
"no-unused-vars": OFF,
"@typescript-eslint/no-unused-vars": [
WARN,
"error",
{
args: "none",
ignoreRestSiblings: true,
},
],
"no-useless-constructor": OFF,
"@typescript-eslint/no-useless-constructor": WARN,

// These rules are turned on in the core rules but aren't needed for TypeScript code
"no-dupe-class-members": "off",
"no-undef": "off",

// These stylistic rules don't match our preferences
"no-use-before-define": "off",
"prefer-const": "off",

// These rules should eventually come from @typescript-eslint/stylistic
// in typescript-eslint@6
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/consistent-type-imports": "warn",
};
4 changes: 0 additions & 4 deletions packages/remix-netlify/__tests__/server-test.ts
Expand Up @@ -2,10 +2,6 @@ import fsp from "fs/promises";
import path from "path";
import lambdaTester from "lambda-tester";
import {
// This has been added as a global in node 15+, but we expose it here while we
// support Node 14
// eslint-disable-next-line @typescript-eslint/no-unused-vars
AbortController,
createRequestHandler as createRemixRequestHandler,
Response as NodeResponse,
} from "@remix-run/node";
Expand Down
1 change: 0 additions & 1 deletion packages/remix-node/__tests__/fetch-test.ts
@@ -1,4 +1,3 @@
import { PassThrough } from "stream";
import { ReadableStream } from "@remix-run/web-stream";

import { Request } from "../fetch";
Expand Down
7 changes: 2 additions & 5 deletions packages/remix-server-runtime/responses.ts
Expand Up @@ -24,17 +24,14 @@ export type DeferFunction = <Data extends Record<string, unknown>>(
init?: number | ResponseInit
) => TypedDeferredData<Data>;

export type JsonFunction = <Data extends unknown>(
export type JsonFunction = <Data>(
data: Data,
init?: number | ResponseInit
) => TypedResponse<Data>;

// must be a type since this is a subtype of response
// interfaces must conform to the types they extend
export type TypedResponse<T extends unknown = unknown> = Omit<
Response,
"json"
> & {
export type TypedResponse<T = unknown> = Omit<Response, "json"> & {
json(): Promise<T>;
};

Expand Down

0 comments on commit 4a617f6

Please sign in to comment.