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 website/generate-api-docs/example.flow:623
Type
type ResolveConfigFn = (configNames: Array<FilePath>) => Promise<FilePath | null>;
Referenced by:
MultiThreadValidatorResolveConfigWithPathFn website/generate-api-docs/example.flow:630
Type
type ResolveConfigWithPathFn = (configNames: Array<FilePath>, assetFilePath: string) => Promise<FilePath | null>;
Referenced by:
DedicatedThreadValidatorValidateResult website/generate-api-docs/example.flow:638
type ValidateResult = {|
warnings: Array<Diagnostic>,
errors: Array<Diagnostic>,
|}
Referenced by:
DedicatedThreadValidator, MultiThreadValidatorDedicatedThreadValidator website/generate-api-docs/example.flow:646
type DedicatedThreadValidator = {|
validateAll: ({|
assets: Asset[],
resolveConfigWithPath: ResolveConfigWithPathFn,
options: PluginOptions,
logger: PluginLogger,
|}) => Async<Array<?ValidateResult>>,
|}
Referenced by:
ValidatorMultiThreadValidator website/generate-api-docs/example.flow:658
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:
ValidatorValidator website/generate-api-docs/example.flow:676
Type
type Validator = DedicatedThreadValidator | MultiThreadValidator;