Explorar o código

Merge pull request #5171 from weseek/fix/84537-84709-add-test-and-lint

refs #84709: add test and lint
Yuki Takei %!s(int64=4) %!d(string=hai) anos
pai
achega
20f4aafece

+ 10 - 0
.eslintrc.js

@@ -12,6 +12,7 @@ module.exports = {
   },
   },
   plugins: [
   plugins: [
     'jest',
     'jest',
+    'regex',
   ],
   ],
   rules: {
   rules: {
     'import/prefer-default-export': 'off',
     'import/prefer-default-export': 'off',
@@ -30,5 +31,14 @@ module.exports = {
       'error',
       'error',
       { additionalTestBlockFunctions: ['each.test'] },
       { additionalTestBlockFunctions: ['each.test'] },
     ],
     ],
+    'regex/invalid': ['error', [
+      {
+        regex: '\\?\\<\\!',
+        message: 'Do not use any negative lookbehind',
+      }, {
+        regex: '\\?\\<\\=',
+        message: 'Do not use any Positive lookbehind',
+      },
+    ]],
   },
   },
 };
 };

+ 12 - 0
packages/app/.eslintrc.js

@@ -3,6 +3,9 @@ module.exports = {
     'weseek/react',
     'weseek/react',
     'weseek/typescript',
     'weseek/typescript',
   ],
   ],
+  plugins: [
+    'regex',
+  ],
   env: {
   env: {
     jquery: true,
     jquery: true,
   },
   },
@@ -25,6 +28,15 @@ module.exports = {
       name: 'axios',
       name: 'axios',
       message: 'Please use src/utils/axios instead.',
       message: 'Please use src/utils/axios instead.',
     }],
     }],
+    'regex/invalid': ['error', [
+      {
+        regex: '\\?\\<\\!',
+        message: 'Do not use any negative lookbehind',
+      }, {
+        regex: '\\?\\<\\=',
+        message: 'Do not use any Positive lookbehind',
+      },
+    ]],
     '@typescript-eslint/no-var-requires': 'off',
     '@typescript-eslint/no-var-requires': 'off',
 
 
     // set 'warn' temporarily -- 2021.08.02 Yuki Takei
     // set 'warn' temporarily -- 2021.08.02 Yuki Takei

+ 2 - 0
packages/app/package.json

@@ -91,6 +91,7 @@
     "entities": "^2.0.0",
     "entities": "^2.0.0",
     "esa-nodejs": "^0.0.7",
     "esa-nodejs": "^0.0.7",
     "escape-string-regexp": "=4.0.0",
     "escape-string-regexp": "=4.0.0",
+    "eslint-plugin-regex": "^1.8.0",
     "express": "^4.16.1",
     "express": "^4.16.1",
     "express-bunyan-logger": "^1.3.3",
     "express-bunyan-logger": "^1.3.3",
     "express-form": "~0.12.0",
     "express-form": "~0.12.0",
@@ -182,6 +183,7 @@
     "csv-to-markdown-table": "^1.0.1",
     "csv-to-markdown-table": "^1.0.1",
     "diff2html": "^3.1.2",
     "diff2html": "^3.1.2",
     "eazy-logger": "^3.1.0",
     "eazy-logger": "^3.1.0",
+    "eslint-plugin-regex": "^1.8.0",
     "file-loader": "^5.0.2",
     "file-loader": "^5.0.2",
     "handsontable": "=6.2.2",
     "handsontable": "=6.2.2",
     "hard-source-webpack-plugin": "^0.13.1",
     "hard-source-webpack-plugin": "^0.13.1",

+ 2 - 1
packages/app/src/components/Page/RevisionRenderer.jsx

@@ -64,7 +64,7 @@ class LegacyRevisionRenderer extends React.PureComponent {
    */
    */
   getHighlightedBody(body, keywords) {
   getHighlightedBody(body, keywords) {
     const normalizedKeywordsArray = [];
     const normalizedKeywordsArray = [];
-    // !!TODO!!: add test code
+    // !!TODO!!: add test code refs: https://redmine.weseek.co.jp/issues/86841
     // Separate keywords
     // Separate keywords
     // - Surrounded by double quotation
     // - Surrounded by double quotation
     // - Split by both full-width and half-width spaces
     // - Split by both full-width and half-width spaces
@@ -84,6 +84,7 @@ class LegacyRevisionRenderer extends React.PureComponent {
 
 
     // for non-chrome browsers compatibility
     // for non-chrome browsers compatibility
     try {
     try {
+      // eslint-disable-next-line regex/invalid
       keywordRegexp2 = new RegExp(`(?<!<)${normalizedKeywords}(?!(.*?("|>)))`, 'ig'); // inferior (this doesn't work well when html tags exist a lot) https://regex101.com/r/Dfi61F/1
       keywordRegexp2 = new RegExp(`(?<!<)${normalizedKeywords}(?!(.*?("|>)))`, 'ig'); // inferior (this doesn't work well when html tags exist a lot) https://regex101.com/r/Dfi61F/1
     }
     }
     catch (err) {
     catch (err) {

+ 1 - 0
packages/codemirror-textlint/package.json

@@ -15,6 +15,7 @@
     "@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.8",
     "@textlint-rule/textlint-rule-no-unmatched-pair": "^1.0.8",
     "@textlint/kernel": "^12.0.2",
     "@textlint/kernel": "^12.0.2",
     "@types/codemirror": "^5.60.2",
     "@types/codemirror": "^5.60.2",
+    "eslint-plugin-regex": "^1.8.0",
     "textlint-message-to-codemirror": "^1.0.0",
     "textlint-message-to-codemirror": "^1.0.0",
     "textlint-plugin-markdown": "^4.0.6",
     "textlint-plugin-markdown": "^4.0.6",
     "textlint-rule-common-misspellings": "^1.0.1",
     "textlint-rule-common-misspellings": "^1.0.1",

+ 3 - 2
packages/core/package.json

@@ -19,6 +19,7 @@
     "lint": "npm-run-all -p lint:*",
     "lint": "npm-run-all -p lint:*",
     "test": "jest --verbose"
     "test": "jest --verbose"
   },
   },
-  "dependencies": {},
-  "devDependencies": {}
+  "devDependencies": {
+    "eslint-plugin-regex": "^1.8.0"
+  }
 }
 }

+ 1 - 0
packages/core/src/models/devided-page-path.js

@@ -34,6 +34,7 @@ export class DevidedPagePath {
 
 
     let PATTERN_DEFAULT = /^((.*)\/)?(.+)$/; // this will not ignore html end tags https://regex101.com/r/jpZwIe/1
     let PATTERN_DEFAULT = /^((.*)\/)?(.+)$/; // this will not ignore html end tags https://regex101.com/r/jpZwIe/1
     try { // for non-chrome browsers
     try { // for non-chrome browsers
+      // eslint-disable-next-line regex/invalid
       PATTERN_DEFAULT = new RegExp('^((.*)(?<!<)\\/)?(.+)$'); // https://regex101.com/r/HJNvMW/1
       PATTERN_DEFAULT = new RegExp('^((.*)(?<!<)\\/)?(.+)$'); // https://regex101.com/r/HJNvMW/1
     }
     }
     catch (err) {
     catch (err) {

+ 1 - 0
packages/plugin-attachment-refs/package.json

@@ -30,6 +30,7 @@
     "universal-bunyan": "^0.9.2"
     "universal-bunyan": "^0.9.2"
   },
   },
   "devDependencies": {
   "devDependencies": {
+    "eslint-plugin-regex": "^1.8.0",
     "npm-run-all": "^4.1.5",
     "npm-run-all": "^4.1.5",
     "react": "^16.8.3",
     "react": "^16.8.3",
     "react-dom": "^16.8.3"
     "react-dom": "^16.8.3"

+ 1 - 0
packages/plugin-lsx/package.json

@@ -23,6 +23,7 @@
   },
   },
   "dependencies": {},
   "dependencies": {},
   "devDependencies": {
   "devDependencies": {
+    "eslint-plugin-regex": "^1.8.0",
     "react": "^16.8.3",
     "react": "^16.8.3",
     "react-dom": "^16.8.3"
     "react-dom": "^16.8.3"
   }
   }

+ 1 - 0
packages/plugin-pukiwiki-like-linker/package.json

@@ -22,6 +22,7 @@
   },
   },
   "devDependencies": {
   "devDependencies": {
     "browser-bunyan": "^1.6.3",
     "browser-bunyan": "^1.6.3",
+    "eslint-plugin-regex": "^1.8.0",
     "tsc-alias": "^1.2.9"
     "tsc-alias": "^1.2.9"
   }
   }
 }
 }

+ 1 - 0
packages/slack/package.json

@@ -24,6 +24,7 @@
   },
   },
   "devDependencies": {
   "devDependencies": {
     "@types/express": "^4.17.11",
     "@types/express": "^4.17.11",
+    "eslint-plugin-regex": "^1.8.0",
     "tsc-alias": "^1.2.9"
     "tsc-alias": "^1.2.9"
   }
   }
 }
 }

+ 1 - 0
packages/slackbot-proxy/package.json

@@ -56,6 +56,7 @@
     "@tsed/schema": "^6.43.0",
     "@tsed/schema": "^6.43.0",
     "bootstrap": "^5.0.2",
     "bootstrap": "^5.0.2",
     "browser-bunyan": "^1.6.3",
     "browser-bunyan": "^1.6.3",
+    "eslint-plugin-regex": "^1.8.0",
     "morgan": "^1.10.0",
     "morgan": "^1.10.0",
     "ts-node-dev": "^1.1.6",
     "ts-node-dev": "^1.1.6",
     "tsc-alias": "^1.2.9"
     "tsc-alias": "^1.2.9"

+ 1 - 1
packages/ui/package.json

@@ -15,8 +15,8 @@
     "lint": "npm-run-all -p lint:*",
     "lint": "npm-run-all -p lint:*",
     "test": "jest --verbose"
     "test": "jest --verbose"
   },
   },
-  "dependencies": {},
   "devDependencies": {
   "devDependencies": {
+    "eslint-plugin-regex": "^1.8.0",
     "react": "^16.8.3"
     "react": "^16.8.3"
   }
   }
 }
 }

+ 5 - 0
yarn.lock

@@ -7656,6 +7656,11 @@ eslint-plugin-react@^7.24.0:
     resolve "^2.0.0-next.3"
     resolve "^2.0.0-next.3"
     string.prototype.matchall "^4.0.5"
     string.prototype.matchall "^4.0.5"
 
 
+eslint-plugin-regex@^1.8.0:
+  version "1.8.0"
+  resolved "https://registry.yarnpkg.com/eslint-plugin-regex/-/eslint-plugin-regex-1.8.0.tgz#4bd111cf5235fb76a4a7f77d7ffcb7b3777b8a77"
+  integrity sha512-rmzVvpoxHKgvcYDo9d1X9RMFOtyOV3A6taD3KWE6gIID2dHoc8RPd0YAjDSJ0LG35wnehQBfsNB+F7q4eYqXqw==
+
 eslint-restricted-globals@^0.1.1:
 eslint-restricted-globals@^0.1.1:
   version "0.1.1"
   version "0.1.1"
   resolved "https://registry.yarnpkg.com/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz#35f0d5cbc64c2e3ed62e93b4b1a7af05ba7ed4d7"
   resolved "https://registry.yarnpkg.com/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz#35f0d5cbc64c2e3ed62e93b4b1a7af05ba7ed4d7"