ESLintify Part 1 (#837)

* ESLint-ify

* Allow empty try/catch

* Escape regexp
This commit is contained in:
Yangshun Tay 2018-07-08 09:13:18 -07:00 committed by GitHub
parent 128dbfca0a
commit e8e3f42685
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 466 additions and 555 deletions

View file

@ -8,18 +8,16 @@
*/
const chalk = require('chalk');
const program = require('commander');
const escapeStringRegexp = require('escape-string-regexp');
const fs = require('fs');
const glob = require('glob');
const path = require('path');
const metadataUtils = require('./server/metadataUtils.js');
const CWD = process.cwd();
// escape appropriate characters in a string to be used in a regex
RegExp.escape = function(s) {
return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
};
// generate a doc header from metadata
function makeHeader(metadata) {
let header = '---\n';
@ -30,9 +28,8 @@ function makeHeader(metadata) {
return header;
}
let currentVersion, newVersion;
const program = require('commander');
let currentVersion;
let newVersion;
program
.arguments('<version_name> <new_version_name>')
@ -123,7 +120,7 @@ if (fs.existsSync(currentSidebarFile)) {
fs.renameSync(currentSidebarFile, newSidebarFile);
let sidebarContent = fs.readFileSync(newSidebarFile, 'utf8');
sidebarContent = sidebarContent.replace(
new RegExp(`version-${RegExp.escape(currentVersion)}-`, 'g'),
new RegExp(`version-${escapeStringRegexp(currentVersion)}-`, 'g'),
`version-${newVersion}-`
);
fs.writeFileSync(newSidebarFile, sidebarContent);