feature-sliced / steiger

Universal file structure and project architecture linter
https://www.npmjs.com/package/steiger
MIT License
62 stars 5 forks source link

Implement the type safety utilities for plugin authors #71

Open illright opened 2 months ago

illright commented 2 months ago

Test cases:

illright commented 2 weeks ago

Code for the test case:

import fsd, { type FSDConfigObject } from '@feature-sliced/steiger-plugin'
import { createConfigs, createPlugin, enableAllRules, type ConfigObjectOf } from '@steiger/toolkit'

const sda = createPlugin({
  meta: {
    name: 'sda',
    version: '1.0.0',
  },
  ruleDefinitions: [
    {
      name: "a-rule",
      check(root, ruleOptions: { foo?: "bar" | "baz" }) {
        return {
          diagnostics: [],
        }
      },
    }
  ]
})

const sdaConfigs = createConfigs({
  all: enableAllRules(sda),
  handpicked: [
    sda,
    {
      rules: {
        "a-rule": "off"
      },
    }
  ]
})

export default [
  ...fsd.configs.recommended,
  {
    rules: {
      "fsd/no-public-api-sidestep": "off",
    }
  } satisfies FSDConfigObject,
  sda,
  ...sdaConfigs.handpicked,
  {
    rules: {
      "a-rule": ["error", { foo: "baz" }]
    }
  } satisfies ConfigObjectOf<typeof sda>
]