|
@@ -5,16 +5,48 @@ const kernel = new TextlintKernel();
|
|
|
|
|
|
|
|
let textlintOption = {};
|
|
let textlintOption = {};
|
|
|
|
|
|
|
|
|
|
+const createSetupRules = (rules, ruleOptions) => (
|
|
|
|
|
+ Object.keys(rules).map(ruleName => (
|
|
|
|
|
+ {
|
|
|
|
|
+ ruleId: ruleName,
|
|
|
|
|
+ rule: rules[ruleName],
|
|
|
|
|
+ options: ruleOptions[ruleName],
|
|
|
|
|
+ }
|
|
|
|
|
+ ))
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
export default function createValidator() {
|
|
export default function createValidator() {
|
|
|
|
|
+ const enabledRules = [{
|
|
|
|
|
+ name: 'common-misspellings',
|
|
|
|
|
+ rule: require('textlint-rule-common-misspellings').default,
|
|
|
|
|
+ enable: true,
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const rules = enabledRules.reduce((rules, rule) => {
|
|
|
|
|
+ rules[rule.name] = rule.rule;
|
|
|
|
|
+ return rules;
|
|
|
|
|
+ }, {});
|
|
|
|
|
+
|
|
|
|
|
+ const rulesOption = enabledRules.reduce((rules, rule) => {
|
|
|
|
|
+ rules[rule.name] = rule.options || true;
|
|
|
|
|
+ return rules;
|
|
|
|
|
+ }, {});
|
|
|
|
|
+
|
|
|
|
|
+ console.log(createSetupRules(rules, rulesOption));
|
|
|
|
|
+
|
|
|
textlintOption = Object.assign(
|
|
textlintOption = Object.assign(
|
|
|
{},
|
|
{},
|
|
|
{
|
|
{
|
|
|
- rules: [
|
|
|
|
|
- {
|
|
|
|
|
- ruleId: 'common-misspellings',
|
|
|
|
|
- rule: require('textlint-rule-common-misspellings').default,
|
|
|
|
|
- },
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ // rules: [
|
|
|
|
|
+ // {
|
|
|
|
|
+ // ruleId: 'common-misspellings',
|
|
|
|
|
+ // rule: require('textlint-rule-common-misspellings').default,
|
|
|
|
|
+ // enable: true,
|
|
|
|
|
+ // },
|
|
|
|
|
+ // ],
|
|
|
|
|
+ rules: createSetupRules(rules, rulesOption),
|
|
|
plugins: [
|
|
plugins: [
|
|
|
{
|
|
{
|
|
|
pluginId: 'markdown',
|
|
pluginId: 'markdown',
|
|
@@ -24,6 +56,8 @@ export default function createValidator() {
|
|
|
ext: '.md',
|
|
ext: '.md',
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
return (text, callback) => {
|
|
return (text, callback) => {
|
|
|
if (!text) {
|
|
if (!text) {
|
|
|
callback([]);
|
|
callback([]);
|