Skip to content

chore: port custom lint rules into local plugin + airbnb correctness set#55

Open
varin-nair-factory wants to merge 2 commits into
mainfrom
vn/lint-custom-plugin
Open

chore: port custom lint rules into local plugin + airbnb correctness set#55
varin-nair-factory wants to merge 2 commits into
mainfrom
vn/lint-custom-plugin

Conversation

@varin-nair-factory
Copy link
Copy Markdown
Contributor

What & why

Ports 5 self-contained custom ESLint rules from the private factory-mono-alpha monorepo into a local plugin (eslint-rules/), making the public SDK the source of truth for these rules. This is Phase 1 of the same source-of-truth strategy we applied to the protocol schemas.

Rules are authored in CommonJS (.cjs, since this repo is ESM) so they work in both ESLint 8 (monorepo) and ESLint 9 (here). In Phase 2 (separate follow-up), the monorepo eslint plugin can import these rules from the published package and delete its local copies — requires the monorepo to consume the public package first.

Rules ported

Modernized for ESLint 9 (context.filename / context.sourceCode with fallbacks):

Rule Scope Severity
local/no-shell-injection src + tests error
local/no-unsafe-json-parse src + tests error
local/vi-mock-absolute-paths tests error
local/no-unstable-mock-module tests error
local/vi-mock-import-actual tests error (fixable)

no-unsafe-json-parse is off-by-default upstream (the monorepo is mid-migration); enabled here as error because the SDK core job is parsing untrusted JSON-RPC off the wire.

Real bug found

no-unsafe-json-parse flagged src/api.ts: factoryFetch discarded the response body on JSON parse failure, so non-JSON error responses (HTML error pages, gateway timeouts) surfaced as opaque errors. Fixed: read text first, then JSON.parse, and include rawBody in the error. Test mocks updated to provide .text().

Airbnb correctness rules added (config-only)

eqeqeq (smart), no-throw-literal, array-callback-return, @typescript-eslint/no-unused-expressions, @typescript-eslint/no-shadow. Zero violations in existing code.

Deferred

require-test-files and test-imports-source assume tests are colocated with source (src/foo.test.ts). This repo uses a separate tests/ dir that does not map 1:1, so porting them needs a path-logic rewrite with false-positive risk — deferred to a focused follow-up.

Verification

  • npm run lint — clean (0 errors)
  • npm run typecheck — pass
  • npm run typecheck:examples — pass
  • npm run format:check — pass
  • npm test911 passed / 911

No eslint-disable or per-file overrides added.

Generated with Droid

varin-nair-factory and others added 2 commits May 29, 2026 16:15
Port the portable, non-custom, non-React rules from factory-mono-alpha's
shared @factory/eslint-config into our ESLint 9 flat config, so the public
SDK enforces the same standards as the internal source of truth.

Added rules: no-empty-object-type (error), no-require-imports, no-barrel-files,
import/no-default-export, import/named, import/no-extraneous-dependencies,
import/extensions, eslint-comments/no-unused-disable, no-void, default-case,
no-constant-condition, no-param-reassign, no-promise-executor-return,
prefer-promise-reject-errors, prefer-arrow-callback, no-restricted-syntax
(incl. ExportAllDeclaration ban), and vitest/expect-expect + valid-expect
for tests.

Excluded the monorepo's factory/* custom-plugin rules (not installable from
npm) and React/Next rules (no React here). Refactored to comply: deleted the
unused src/protocol/index.ts export* barrel and converted src/index.ts to
explicit named re-exports. Public-API barrels are exempted from no-barrel-files
(matching the monorepo's index.ts exemption). Fixed all resulting violations.

New devDeps: eslint-plugin-no-barrel-files, eslint-plugin-eslint-comments,
@vitest/eslint-plugin.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
…ess set

Ports 5 self-contained custom ESLint rules from the private monorepo into a
local plugin (eslint-rules/) so the public SDK becomes the source of truth for
them (Phase 1). Rules authored in CJS so the monorepo can later consume them
and drop its copies (Phase 2).

Rules ported (ESLint 9-modernized: context.filename / context.sourceCode):
- no-shell-injection, no-unsafe-json-parse (error)
- vi-mock-absolute-paths, no-unstable-mock-module, vi-mock-import-actual (tests)

Enabled no-unsafe-json-parse as error (off-by-default upstream): caught a real
bug in src/api.ts where the response body was discarded on JSON parse failure;
now reads text first and surfaces rawBody in the error.

Added airbnb correctness rules: eqeqeq(smart), no-throw-literal,
array-callback-return, @typescript-eslint/no-unused-expressions,
@typescript-eslint/no-shadow.

Deferred: require-test-files and test-imports-source (assume colocated tests;
this repo uses a separate tests/ dir). Verified: lint, typecheck,
typecheck:examples, format, 911 tests all pass.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@varin-nair-factory varin-nair-factory self-assigned this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant