npm.io
2.7.1 • Published 1 month ago

@slhs/eslint-config

Licence
Version
2.7.1
Deps
11
Size
26 kB
Vulns
0
Weekly
0

@slhs/eslint-config

This is the SLHS ESLint configuration.

npm Version Build Status

Requirements

This config uses the new "Flat Config" format and comes with some requirements:

  • Node.js 20.0.0 or newer
  • ESLint 8.57.0 or newer
  • Your project to be in native ESM ("type": "module" in your package.json)
  • VSCode must be configured to use the Flat Config file (eslint.config.js). You'll probably want to enable this as a workspace setting (not a user setting) and check it in to source control:

VSCode Settings Screenshot

Install

pnpm add -D @slhs/eslint-config

Be sure to install the appropriately versioned eslint peer dependency as well.

Usage

Follow the ESLint documentation on shared configurations. See the documentation on ignoring files if you need to ignore anything the config doesn't already ignore by default.

Examples
eslint.config.js
import { defineConfig } from "eslint/config";
import slhsConfig from "@slhs/eslint-config";

const config = defineConfig([
  slhsConfig,
  {
    // your optional overrides here
  },
]);

export default config;
package.json
{
  "scripts": {
    ...
    "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
    ...
  }
}
Optional: module boundaries helper

If your app uses the SLHS app/modules/<module>/ pattern, this package also exposes an opt-in helper for enforcing module boundaries. It is not part of the base config.

import { defineConfig } from "eslint/config";
import slhsConfig from "@slhs/eslint-config";
import { createModuleBoundaryConfig } from "@slhs/eslint-config/module-boundaries";

export default defineConfig([slhsConfig, ...createModuleBoundaryConfig()]);

This helper is intentionally opinionated and follows the SLHS convention:

  • modules live in app/modules
  • public module entrypoints are {module}.ts and {module}.server.ts
  • files outside modules may only import those public entrypoints
  • files inside modules may import other modules only through those public entrypoints via #/app/modules/... subpath aliases
  • files outside modules must use #/ imports instead of non-local ../ imports

Example structure:

app/
  modules/
    identity/
      identity.ts
      identity.server.ts
      identity-session.server.ts
    reporting/
      reporting.ts
      reporting-persistence.server.ts

With the helper enabled:

  • #/app/modules/identity/identity is allowed outside modules
  • #/app/modules/identity/identity.server is allowed outside modules
  • #/app/modules/identity/identity-session.server is rejected outside the module
  • ../identity/identity-session.server is rejected from another module
  • ../identity/identity.server is rejected from another module
  • #/app/modules/identity/identity.server is allowed from another module
  • same-module internals are not restricted by this helper