You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"rules": {"en-capitalization": {// allow lower-case words in Header"allowHeading": true,// allow lower-case words in Image alt"allowFigures": true,// allow lower-case words in ListItem"allowLists": true,// allow lower-case words in anywhere"allowWords": []}}}
However, the user passed an invalid option like "allowHead: true and textlint does not show any error.
textlint does not know that the rule has what options.
Rule Options Schema
To resolve this, we need to introduce rule's options schema.
ESLint has similar one - Options Schemas.
Each rule defines JSON Schema and ESLint use it for validation.
As a various rule author, I do not want to write JSON Schema by handwriting 😞
Instead of it, We can write a rule in TypeScript and We can use Type for JSON Schema.
Recently, I've created @textlint/config-loader package.
We create a new @textlint/config-validator package that validates the rule option with the config.
Pasado code
import{loadConfig}from"@textlint/config-loader";import{validate}from"@textlint/config-validator";(asyncfunction(){constconfigResult=awaitloadConfig({cwd: process.cwd()});if(!configResult.ok){console.error(configResult.error.message,configResult.error.errors);return;}// config includes .textlint opsions and rule instanceconstvalidateResult=awaitvalidate(configResult.config);if(!result.ok){console.error(validateResult.error.message,validateResult.error.errors);return;}});
Currently, textlint does not check the actual option.
So, the user pass an invalid option and does not show any errors.
For example, textlint-rule-en-capitalization support folllowing options.
However, the user passed an invalid option like
"allowHead: true
and textlint does not show any error.textlint does not know that the rule has what options.
Rule Options Schema
To resolve this, we need to introduce rule's options schema.
ESLint has similar one - Options Schemas.
Each rule defines JSON Schema and ESLint use it for validation.
As a various rule author, I do not want to write JSON Schema by handwriting 😞
Instead of it, We can write a rule in TypeScript and We can use Type for JSON Schema.
I've created babel-plugin-textlint-scripts.
This babel plugin converts TypeScript type to JSON Schema.
In
Out
This plugin will help us to integrate Options schema.
Of course, we can write JSON by handwriting.
TODO
meta
objecttextlint
@textlint/core
?The text was updated successfully, but these errors were encountered: