Checks are best shared using packages.

We recommend prefixing packages intended for open source or community use with commonality-checks. This will allow for a shorter path when configuring them in your project configuration.

Static checks

Checks that don’t require any configuration can be added to your project by adding the them to directly to your project configuration file.

sorted-dependencies.js
export default {
  name: 'sorted-dependencies',
  message: 'Dependencies must be sorted',
  validate: () => {
    // ...validation logic
  }
}

We recommend exporting static checks as separate entry points in your package.json.

package.json
{
  "name": "commonality-checks-myname",
  "exports": {
    "./has-code": "./has-code.js"
  }
}

Checks can then be configured using the full package name or shorthand if prefixed with commonality-checks.

.commonality/config.json
{
  "checks": {
    "*": [
      "commonality-checks-myname/sorted-dependencies",
      "myname/sorted-dependencies"
    ]
  }
}

Composed checks

Checks that are designed to be configured by the user can be exported as functions.

has-script.js
export const hasScript = (name, value) => ({
  name: 'has-script',
  message: `package.json must have script "${name}" with value "${value}"`,
  validate: () => {
    // ...validation logic
  }
});

These checks can be exported from as named exports from a single file.

index.js
export * from './has-script.js'

Composed checks can then be exported from package’s main entry point.

package.json
{
  "name": "commonality-checks-myname",
  "main": "index.js",
  "exports": {
    ".": "./index.js"
  }
}

Developers can then configure these checks and export them as static checks locally in their projects or as packages to standardize a toolchain across an organization.

.commonality/has-build-script.ts
import { hasScript }

export default {
  name: 'has-build-script',
  message: 'Package must have standard build script',
  validate
}