Просмотр исходного кода

Merge pull request #3950 from overleaf/msm-reenable-lint-prefer-regex-literals

Reenable `prefer-regex-literals` eslint rule

GitOrigin-RevId: 3c576d92a08dfcb745d447b1bf8c7b828753010d
Jakob Ackermann 5 лет назад
Родитель
Сommit
adfde7d26b

+ 0 - 1
services/web/.eslintrc

@@ -44,7 +44,6 @@
     "no-prototype-builtins": "off",
     "no-var": "off",
     "prefer-const": "off",
-    "prefer-regex-literals": "off",
     "array-callback-return": "off",
     "no-unreachable-loop": "off",
     "no-loss-of-precision": "off",

+ 2 - 1
services/web/app/src/Features/Compile/CompileController.js

@@ -258,7 +258,8 @@ module.exports = CompileController = {
   },
 
   _getSafeProjectName(project) {
-    const safeProjectName = project.name.replace(new RegExp('\\W', 'g'), '_')
+    const wordRegExp = /\W/g
+    const safeProjectName = project.name.replace(wordRegExp, '_')
     return sanitize.escape(safeProjectName)
   },
 

+ 3 - 0
services/web/app/src/Features/Project/SafePath.js

@@ -20,6 +20,7 @@
 
 const load = function () {
   let SafePath
+  // eslint-disable-next-line prefer-regex-literals
   const BADCHAR_RX = new RegExp(
     `\
 [\
@@ -35,6 +36,7 @@ const load = function () {
     'g'
   )
 
+  // eslint-disable-next-line prefer-regex-literals
   const BADFILE_RX = new RegExp(
     `\
 (^\\.$)\
@@ -52,6 +54,7 @@ const load = function () {
   //
   // The list of property names is taken from
   //   ['prototype'].concat(Object.getOwnPropertyNames(Object.prototype))
+  // eslint-disable-next-line prefer-regex-literals
   const BLOCKEDFILE_RX = new RegExp(`\
 ^(\
 prototype\

+ 3 - 2
services/web/frontend/js/features/file-tree/util/safe-path.js

@@ -4,7 +4,7 @@
 //   app/src/Features/Project/SafePath.js
 //   frontend/js/ide/directives/SafePath.js
 //   frontend/js/features/file-tree/util/safe-path.js
-
+// eslint-disable-next-line prefer-regex-literals
 const BADCHAR_RX = new RegExp(
   `\
 [\
@@ -19,7 +19,7 @@ const BADCHAR_RX = new RegExp(
 `,
   'g'
 )
-
+// eslint-disable-next-line prefer-regex-literals
 const BADFILE_RX = new RegExp(
   `\
 (^\\.$)\
@@ -37,6 +37,7 @@ const BADFILE_RX = new RegExp(
 //
 // The list of property names is taken from
 //   ['prototype'].concat(Object.getOwnPropertyNames(Object.prototype))
+// eslint-disable-next-line prefer-regex-literals
 const BLOCKEDFILE_RX = new RegExp(`\
 ^(\
 prototype\

+ 2 - 2
services/web/frontend/js/features/outline/outline-parser.js

@@ -49,8 +49,8 @@ function matchOutline(content) {
   return flatOutline
 }
 
-const DISPLAY_TITLE_REGEX = new RegExp('([^\\\\]*)\\\\([^{]+){([^}]+)}(.*)')
-const END_OF_TITLE_REGEX = new RegExp('^([^{}]*?({[^{}]*?}[^{}]*?)*)}')
+const DISPLAY_TITLE_REGEX = /([^\\]*)\\([^{]+){([^}]+)}(.*)/
+const END_OF_TITLE_REGEX = /^([^{}]*?({[^{}]*?}[^{}]*?)*)}/
 /*
  * Attempt to improve the display of the outline title for titles with commands.
  * Either skip the command (for labels) or display the command's content instead

+ 3 - 0
services/web/frontend/js/ide/directives/SafePath.js

@@ -18,6 +18,7 @@
 //   frontend/js/features/file-tree/util/safe-path.js
 
 let SafePath
+// eslint-disable-next-line prefer-regex-literals
 const BADCHAR_RX = new RegExp(
   `\
 [\
@@ -33,6 +34,7 @@ const BADCHAR_RX = new RegExp(
   'g'
 )
 
+// eslint-disable-next-line prefer-regex-literals
 const BADFILE_RX = new RegExp(
   `\
 (^\\.$)\
@@ -50,6 +52,7 @@ const BADFILE_RX = new RegExp(
 //
 // The list of property names is taken from
 //   ['prototype'].concat(Object.getOwnPropertyNames(Object.prototype))
+// eslint-disable-next-line prefer-regex-literals
 const BLOCKEDFILE_RX = new RegExp(`\
 ^(\
 prototype\

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor/spell-check/SpellCheckManager.js

@@ -1,3 +1,4 @@
+// eslint-disable-next-line prefer-regex-literals
 const BLACKLISTED_COMMAND_REGEX = new RegExp(
   `\
 \\\\\

+ 4 - 4
services/web/test/acceptance/src/ProjectInviteTests.js

@@ -209,7 +209,7 @@ const expectInvitePage = (user, link, callback) => {
   tryFollowInviteLink(user, link, (err, response, body) => {
     expect(err).not.to.exist
     expect(response.statusCode).to.equal(200)
-    expect(body).to.match(new RegExp('<title>Project Invite - .*</title>'))
+    expect(body).to.match(/<title>Project Invite - .*<\/title>/)
     callback()
   })
 }
@@ -219,7 +219,7 @@ const expectInvalidInvitePage = (user, link, callback) => {
   tryFollowInviteLink(user, link, (err, response, body) => {
     expect(err).not.to.exist
     expect(response.statusCode).to.equal(200)
-    expect(body).to.match(new RegExp('<title>Invalid Invite - .*</title>'))
+    expect(body).to.match(/<title>Invalid Invite - .*<\/title>/)
     callback()
   })
 }
@@ -229,7 +229,7 @@ const expectInviteRedirectToRegister = (user, link, callback) => {
   tryFollowInviteLink(user, link, (err, response) => {
     expect(err).not.to.exist
     expect(response.statusCode).to.equal(302)
-    expect(response.headers.location).to.match(new RegExp('^/register.*$'))
+    expect(response.headers.location).to.match(/^\/register.*$/)
     callback()
   })
 }
@@ -238,7 +238,7 @@ const expectLoginPage = (user, callback) => {
   tryFollowLoginLink(user, '/login', (err, response, body) => {
     expect(err).not.to.exist
     expect(response.statusCode).to.equal(200)
-    expect(body).to.match(new RegExp('<title>Login - .*</title>'))
+    expect(body).to.match(/<title>Login - .*<\/title>/)
     callback()
   })
 }

+ 1 - 1
services/web/test/acceptance/src/UserEmailsTests.js

@@ -937,7 +937,7 @@ describe('UserEmails', function () {
             expect(response.statusCode).to.equal(302)
             expect(response.headers)
               .to.have.property('location')
-              .to.match(new RegExp('^/login'))
+              .to.match(/^\/login/)
             done()
           }
         )