Skip to content

Commit

Permalink
refactor: migrate from @remix-run/eslint-config (#809)
Browse files Browse the repository at this point in the history
* refactor: migrate from @remix-run/eslint-config

* lint: remove unused vars

* lint: noopener -> noreferrer

* lint: misc small stuff (deprecated functions, whitespace, ...)
  • Loading branch information
chohner committed May 16, 2024
1 parent 4e69dfe commit fa0bf98
Show file tree
Hide file tree
Showing 17 changed files with 725 additions and 572 deletions.
130 changes: 97 additions & 33 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,46 +1,110 @@
// based on https://github.com/remix-run/indie-stack/blob/main/.eslintrc.js

/** @type {import('eslint').Linter.Config} */
module.exports = {
ignorePatterns: ["/*", "!/app", "!/tests", "*.generated.ts"],
extends: [
"@remix-run/eslint-config",
"@remix-run/eslint-config/node",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:sonarjs/recommended-legacy",
"plugin:storybook/recommended",
"plugin:jsx-a11y/strict",
],
plugins: ["sonarjs", "@typescript-eslint"],
root: true,
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.json"],
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
rules: {
"react/jsx-no-target-blank": "off",
"sonarjs/no-duplicate-string": "warn",
"sonarjs/no-small-switch": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"react/prefer-read-only-props": "warn",
camelcase: ["error", { properties: "always", allow: ["^v2_", "^V2_"] }],
"import/no-unused-modules": [
1,
{
unusedExports: true,
ignoreExports: ["app/routes/*", "app/root.tsx", "app/entry.server.tsx"],
},
],
env: {
browser: true,
commonjs: true,
es6: true,
},

// Base config
extends: ["eslint:recommended"],

overrides: [
// React
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: ["react", "jsx-a11y"],
extends: [
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
],
settings: {
react: {
version: "detect",
},
formComponents: ["Form"],
linkComponents: [
{ name: "Link", linkAttribute: "to" },
{ name: "NavLink", linkAttribute: "to" },
],
},
rules: {
"react/jsx-no-leaked-render": ["off", { validStrategies: ["ternary"] }], // enable later
},
},

// Typescript
{
files: ["tests/**/*.{ts,tsx}"],
files: ["**/*.{ts,tsx}"],
plugins: ["@typescript-eslint", "import", "sonarjs"],
parser: "@typescript-eslint/parser",
settings: {
"import/internal-regex": "^~/",
"import/resolver": {
node: { extensions: [".ts", ".tsx"] },
typescript: { alwaysTryTypes: true },
},
},
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/stylistic",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:sonarjs/recommended-legacy",
],
rules: {
"sonarjs/no-duplicate-string": "off",
"@typescript-eslint/ban-ts-comment": "off", // enable later
"@typescript-eslint/consistent-type-definitions": "off", // enable later
"@typescript-eslint/array-type": "off", // enable later
"@typescript-eslint/consistent-indexed-object-style": "off", // enable later
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],

"import/order": [
"off", // enable later
{
alphabetize: { caseInsensitive: true, order: "asc" },
groups: ["builtin", "external", "internal", "parent", "sibling"],
"newlines-between": "always",
},
],
},
},

// Jest/Vitest
{
files: ["tests/**/*.test.{js,jsx,ts,tsx}"],
plugins: ["jest", "jest-dom"],
extends: ["plugin:jest/recommended", "plugin:jest-dom/recommended"],
env: { "jest/globals": true },
rules: {
"jest/valid-title": "off", // enable later
"jest/no-standalone-expect": "off", // enable later
},
},

// Node
{
files: [".eslintrc.js", "mocks/**/*.js"],
env: {
node: true,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion app/components/CourtDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CourtDetails = ({
<p>
<a
href={normalizeURL(website)}
rel="noopener"
rel="noreferrer"
target="_blank"
className="text-link"
>
Expand Down
24 changes: 12 additions & 12 deletions app/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ export default function Footer({
const linksFirstColumn: typeof links = links.slice(0, linksMiddleIndex);
const linksSecondColumn: typeof links = links.slice(linksMiddleIndex);

const renderLink = (link: LinkProps) => (
<li key={link.url} className="leading-snug">
<a
href={link.url}
className="text-link increase-tap-area"
target={link.openInNewTab ? "_blank" : undefined}
rel={link.openInNewTab ? "noopener" : undefined}
>
{link.text}
</a>
</li>
);
const renderLink = (link: LinkProps) => {
const opts = link.openInNewTab
? { target: "_blank", rel: "noreferer" }
: {};

return (
<li key={link.url} className="leading-snug">
<a href={link.url} className="text-link increase-tap-area" {...opts}>
{link.text}
</a>
</li>
);
};
const renderLinks = (links: LinkProps[]) => (
<ul className="list-none m-0 p-0 ds-stack-8" key={links[0]?.url}>
{links.map(renderLink)}
Expand Down
2 changes: 1 addition & 1 deletion app/components/MigrationDataOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function MigrationDataOverview(props: MigrationDataProps) {
if (typeof value === "object" && value !== null) {
const objectProperties = Object.entries(value)
.map(
([subKey, subValue]) =>
([_, subValue]) =>
`${lookupOrKey(
subValue as string,
props.translations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export const loader = async ({
courts.push(court);
}
}
} catch (err) {}
} catch (err) {
console.error(err);
}
});

const slug = pathname;
Expand Down
2 changes: 1 addition & 1 deletion app/services/openSourceLicenses/LicenseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const renderLicenseEntry = (dependencyString: string, infos: Dependency) => {
href={infos.repository}
className="text-link"
target="_blank"
rel="noopener"
rel="noreferrer"
>
{dependencyString}
</a>
Expand Down
2 changes: 1 addition & 1 deletion app/services/openSourceLicenses/generate.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const stripLocalPath = (path: string) =>
const dropVersion = (dependency: string) =>
dependency.substring(0, dependency.lastIndexOf("@"));

export async function allRelevantLicenses(path = "./") {
export async function allRelevantLicenses() {
// 1. Get license info for all and direct dependencies
// 2. Mark direct dependencies with {direct: true}
// 3. Only keep mentionable licenses (either direct or not in 'notMentionableLicenses')
Expand Down
4 changes: 2 additions & 2 deletions app/services/session.server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function createDatabaseSessionStorage({
}) {
return createSessionStorage({
cookie,
async createData(data, expires) {
async createData(data) {
const uuid = crypto.randomUUID();
await setDataForSession(fullId(context, uuid), data);
return uuid;
},
async readData(id) {
return await getDataForSession(fullId(context, id));
},
async updateData(id, data, expires) {
async updateData(id, data) {
await updateDataForSession(fullId(context, id), data);
},
async deleteData(id) {
Expand Down
2 changes: 1 addition & 1 deletion app/services/validation/YesNoAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { z } from "zod";
import type { ZodErrorMap } from "zod";

export const customRequiredErrorMessage: { errorMap: ZodErrorMap } = {
errorMap: (issue, ctx) => ({ message: "required" }),
errorMap: () => ({ message: "required" }),
};
export const YesNoAnswer = z.enum(["yes", "no"], customRequiredErrorMessage);

0 comments on commit fa0bf98

Please sign in to comment.