Skip to content

feat: enforce V0Error over bare Error in packages/0/src via no-restricted-syntax#269

Open
sridhar-3009 wants to merge 1 commit into
vuetifyjs:masterfrom
sridhar-3009:feat/eslint-v0error-rule
Open

feat: enforce V0Error over bare Error in packages/0/src via no-restricted-syntax#269
sridhar-3009 wants to merge 1 commit into
vuetifyjs:masterfrom
sridhar-3009:feat/eslint-v0error-rule

Conversation

@sridhar-3009
Copy link
Copy Markdown

Problem

Closes #248.

PR #247 converted all 8 existing throw new Error(...) sites in packages/0/src to use V0Error with a typed code from V0ErrorDetails. The convention was described in the philosophy but enforced only by author discipline — nothing in CI would catch a future PR landing a bare throw new Error(...).

Fix

Add a no-restricted-syntax block in eslint.config.js scoped to packages/0/src/**/*.ts (with carve-outs for *.test.ts and *.bench.ts):

{
  name: 'vuetify/no-bare-error-throw',
  files: ['packages/0/src/**/*.ts'],
  ignores: ['packages/0/src/**/*.test.ts', 'packages/0/src/**/*.bench.ts'],
  rules: {
    'no-restricted-syntax': ['error',
      {
        selector: 'ThrowStatement > NewExpression[callee.name="Error"]',
        message: 'Use V0Error with a code from V0ErrorDetails instead of bare Error. See packages/0/src/utilities/errors.ts.',
      },
    ],
  },
},

Notes

  • Uses no-restricted-syntax — no custom plugin, no new dependency, mirrors the existing withDefaults guard on line 29.
  • Re-throws (throw err where err is a caught binding) are not flagged — the selector only matches new Error(...) constructor calls.
  • Test and bench files are excluded per the issue spec.
  • The rule fires at error severity so it blocks CI on a violation.

Adds a 'no-restricted-syntax' block scoped to packages/0/src/**/*.ts
(excluding *.test.ts and *.bench.ts) that flags any bare
'throw new Error(...)' and instructs the author to use V0Error with a
code from V0ErrorDetails instead.

This closes the enforcement gap noted in vuetifyjs#248: PR vuetifyjs#247 covered all 8
existing throw sites, but nothing prevented future authors from landing
a bare Error throw that bypasses the typed error registry.

Using no-restricted-syntax keeps the rule dependency-free — it mirrors
the existing withDefaults guard in eslint.config.js and requires no
custom plugin.

Closes vuetifyjs#248
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.

[Feature Request] Enforce V0Error on throws in packages/0/src via eslint-plugin-vuetify

1 participant