Steven Fukase 4 лет назад
Родитель
Сommit
4cd964042a

+ 1 - 0
packages/app/package.json

@@ -160,6 +160,7 @@
     "@atlaskit/navigation-next": "^8.0.5",
     "@handsontable/react": "=2.1.0",
     "@textlint/kernel": "^12.0.2",
+    "@textlint/module-interop": "^12.0.2",
     "@types/compression": "^1.7.0",
     "@types/express": "^4.17.11",
     "@types/multer": "^1.4.5",

+ 14 - 17
packages/app/src/client/util/codemirror/codemirror-textlint.js

@@ -1,30 +1,35 @@
 import { TextlintKernel } from '@textlint/kernel';
+import { moduleInterop } from '@textlint/module-interop';
 import textlintToCodeMirror from 'textlint-message-to-codemirror';
 
 const kernel = new TextlintKernel();
 
 let textlintOption = {};
 
-const createSetupRules = (rules, ruleOptions) => (
-  Object.keys(rules).map(ruleName => (
-    {
+const createSetupRules = (rules, ruleOptions) => {
+  return Object.keys(rules).map((ruleName) => {
+    console.log(ruleName);
+    return {
       ruleId: ruleName,
       rule: rules[ruleName],
       options: ruleOptions[ruleName],
-    }
-  ))
-);
+    };
+  });
+};
 
 
 export default function createValidator() {
   const enabledRules = [
     {
       name: 'max-comma',
-      rule: require('textlint-rule-max-comma').default,
+      rule: moduleInterop(require('textlint-rule-max-comma')),
+      options: {
+        max: 2,
+      },
     },
     {
       name: 'common-misspellings',
-      rule: require('textlint-rule-common-misspellings').default,
+      rule: moduleInterop(require('textlint-rule-common-misspellings')),
       options: {
         ignore: [
           'isnt',
@@ -33,7 +38,6 @@ export default function createValidator() {
         ],
       },
     },
-
   ];
 
 
@@ -43,20 +47,13 @@ export default function createValidator() {
   }, {});
 
   const rulesOption = enabledRules.reduce((rules, rule) => {
-    rules[rule.name] = rule.options;
+    rules[rule.name] = rule.options || {};
     return rules;
   }, {});
 
   textlintOption = Object.assign(
     {},
     {
-      // rules: [
-      //   {
-      //     ruleId: 'common-misspellings',
-      //     rule: require('textlint-rule-common-misspellings').default,
-      //     enable: true,
-      //   },
-      // ],
       rules: createSetupRules(rules, rulesOption),
       plugins: [
         {

+ 8 - 1
packages/app/src/components/PageEditor/CodeMirrorEditor.jsx

@@ -860,7 +860,14 @@ export default class CodeMirrorEditor extends AbstractEditor {
   render() {
     const mode = this.state.isGfmMode ? 'gfm-growi' : undefined;
     const additionalClasses = Array.from(this.state.additionalClassSet).join(' ');
-    const textlintValidator = createValidator();
+    const textlintValidator = createValidator([
+      {
+        name: 'max-comma',
+        options: {
+          max: 2,
+        },
+      },
+      'common-misspellings']);
     const placeholder = this.state.isGfmMode ? 'Input with Markdown..' : 'Input with Plane Text..';
 
     return (

+ 5 - 0
yarn.lock

@@ -2516,6 +2516,11 @@
     traverse "^0.6.6"
     unified "^6.2.0"
 
+"@textlint/module-interop@^12.0.2":
+  version "12.0.2"
+  resolved "https://registry.yarnpkg.com/@textlint/module-interop/-/module-interop-12.0.2.tgz#1edbf8caa5eba572cd9b20ba617968552de74290"
+  integrity sha512-jnFx7B7Q/au49n5Kt/ttPhecvnJGj7643KzPxRNXy422nmafi1EfOZDMGkNEJhlVsQ9WzAnliTTXTFTrBhtVYA==
+
 "@textlint/source-code-fixer@^12.0.2":
   version "12.0.2"
   resolved "https://registry.yarnpkg.com/@textlint/source-code-fixer/-/source-code-fixer-12.0.2.tgz#a41adcebde81592ff4c48bd5dc8133740b3a3ada"