softarc-consulting/sheriff

automatic Tagging / `noTag`

Closed this issue · 0 comments

Many developers are struggling to integrate Sheriff into an existing, large project. Sheriff requires that all modules (directories with index.ts) be tagged. If just a single untagged module exists, Sheriff immediately throws an error "No assigned tag for..." and doesn't even start.

Sheriff should automatically add the tag noTag to untagged modules by default. The noTag acts as any other tag that can be used in the dependency rules.

Let's consider that we have a lot of modules inside src/app/common, but we can't tag them. Still, modules of rootand type:feature should be able to access them:

export const sheriffConfig: SheriffConfig = {
  excludeRoot: true,
  version: 1,
  tagging: {
    'src/app/domains/<domain>': {
      'feature-<feature>': ['domain:<domain>', 'type:feature'],
      'ui-<ui>': ['domain:<domain>', 'type:ui'],
      data: ['domain:<domain>', 'type:data'],
      service: ['domain:<domain>', 'type:service'],
      util: ['domain:<domain>', 'type:util'],
    },
  },

  depRules: {
    root: [({to}) => to.startsWith('domain'), 'type:feature', noTag]
    'domain:*': [sameTag, 'shared'],
    'type:feature': [noTag, 'type:ui', 'type:data', 'type:util'],
    // ...
  },
};

The "automatic tagging" with noTag is enabled by default. One can opt-out via autoTagging in the config. That would give you the guarantee that you have all your modules tagged and no noTag exists:

export const sheriffConfig: SheriffConfig = {
  excludeRoot: true,
  version: 1,
  autoTagging: false,
  tagging: {
    'src/app/domains/<domain>': {
      'feature-<feature>': ['domain:<domain>', 'type:feature'],
      'ui-<ui>': ['domain:<domain>', 'type:ui'],
      data: ['domain:<domain>', 'type:data'],
      service: ['domain:<domain>', 'type:service'],
      util: ['domain:<domain>', 'type:util'],
    },
  },

  depRules: {
    root: [({to}) => to.startsWith('domain'), 'type:feature']
    'domain:*': [sameTag, 'shared'],
    'type:feature': ['type:ui', 'type:data', 'type:util'],
    // ...
  },
};