Validator

A plugin type: Analyze assets and emit warnings and errors

Validators receive an asset, and can throw errors if that asset is invalid in some way, e.g. type errors or linting errors.

import { Validator } from "@parcel/plugin";

export default new Validator({
async validate({ asset }) {
// ...
throw error;
},
});

Some validators (such as @parcel/validator-typescript) may wish to maintain a project-wide cache for efficiency. For these cases, it is appropriate to use a different interface where parcel hands all changed files to the validator at the same time:

import { Validator } from "@parcel/plugin";

export default new Validator({
async validateAll({ assets }) {
// ...
throw error;
},
});

If your plugin implements validateAll, Parcel will make sure to always invoke this method on the same thread (so that your cache state is accessible).

Relevant API

ResolveConfigFn parcel/packages/core/types/index.js:621

Type
type ResolveConfigFn = (configNames: Array<FilePath>) => Promise<FilePath | null>;
Referenced by:
MultiThreadValidator

ResolveConfigWithPathFn parcel/packages/core/types/index.js:628

Type
type ResolveConfigWithPathFn = (configNames: Array<FilePath>, assetFilePath: string) => Promise<FilePath | null>;
Referenced by:
DedicatedThreadValidator

ValidateResult parcel/packages/core/types/index.js:636

type ValidateResult = {|
  warnings: Array<Diagnostic>,
  errors: Array<Diagnostic>,
|}
Referenced by:
DedicatedThreadValidator, MultiThreadValidator

DedicatedThreadValidator parcel/packages/core/types/index.js:644

type DedicatedThreadValidator = {|
  validateAll: ({|
    assets: Asset[],
    resolveConfigWithPath: ResolveConfigWithPathFn,
    options: PluginOptions,
    logger: PluginLogger,
  |}) => Async<Array<?ValidateResult>>,
|}
Referenced by:
Validator

MultiThreadValidator parcel/packages/core/types/index.js:656

type MultiThreadValidator = {|
  validate: ({|
    asset: Asset,
    config: ConfigResult | void,
    options: PluginOptions,
    logger: PluginLogger,
  |}) => Async<ValidateResult | void>,
  getConfig?: ({|
    asset: Asset,
    resolveConfig: ResolveConfigFn,
    options: PluginOptions,
    logger: PluginLogger,
  |}) => Async<ConfigResult | void>,
|}
Referenced by:
Validator