diff --git a/.eslintrc.yml b/.eslintrc.yml index 927262197..e20b2b87f 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -35,4 +35,5 @@ rules: - error - never - exceptRange: true + unicorn/new-for-builtins: error unicorn/prefer-includes: error diff --git a/scripts/build/build.js b/scripts/build/build.js index e775029fb..e99f2ef9f 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -29,7 +29,7 @@ function fitTerminal(input) { const columns = Math.min(process.stdout.columns || 40, 80); const WIDTH = columns - stringWidth(OK) + 1; if (input.length < WIDTH) { - input += Array(WIDTH - input.length).join(chalk.dim(".")); + input += new Array(WIDTH - input.length).join(chalk.dim(".")); } return input; } diff --git a/scripts/release/steps/check-git-status.js b/scripts/release/steps/check-git-status.js index 779addb83..94f27da3c 100644 --- a/scripts/release/steps/check-git-status.js +++ b/scripts/release/steps/check-git-status.js @@ -6,7 +6,7 @@ module.exports = async function() { const status = await execa.stdout("git", ["status", "--porcelain"]); if (status) { - throw Error( + throw new Error( "Uncommitted local changes. " + "Please revert or commit all local changes before making a release." ); diff --git a/scripts/release/steps/generate-bundles.js b/scripts/release/steps/generate-bundles.js index 2b96073b7..16051f512 100644 --- a/scripts/release/steps/generate-bundles.js +++ b/scripts/release/steps/generate-bundles.js @@ -8,7 +8,7 @@ module.exports = async function({ version }) { const builtPkg = await readJson("dist/package.json"); if (builtPkg.version !== version) { - throw Error( + throw new Error( `Expected ${version} in dist/package.json but found ${builtPkg.version}` ); } diff --git a/scripts/release/steps/install-dependencies.js b/scripts/release/steps/install-dependencies.js index 07c5be28d..89453c081 100644 --- a/scripts/release/steps/install-dependencies.js +++ b/scripts/release/steps/install-dependencies.js @@ -9,7 +9,7 @@ async function install() { const status = await execa.stdout("git", ["ls-files", "-m"]); if (status) { - throw Error( + throw new Error( "The lockfile needs to be updated, commit it before making the release." ); } diff --git a/scripts/release/steps/update-changelog.js b/scripts/release/steps/update-changelog.js index d45d5b1b1..b0a61210e 100644 --- a/scripts/release/steps/update-changelog.js +++ b/scripts/release/steps/update-changelog.js @@ -10,8 +10,8 @@ const { waitForEnter } = require("../utils"); function getBlogPostInfo(version) { const date = new Date(); const year = date.getFullYear(); - const month = new String(date.getMonth() + 1).padStart(2, "0"); - const day = new String(date.getDate()).padStart(2, "0"); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const day = String(date.getDate()).padStart(2, "0"); return { file: `website/blog/${year}-${month}-${day}-${version}.md`, diff --git a/scripts/release/steps/validate-new-version.js b/scripts/release/steps/validate-new-version.js index 3f529c0be..65b5323bf 100644 --- a/scripts/release/steps/validate-new-version.js +++ b/scripts/release/steps/validate-new-version.js @@ -5,10 +5,12 @@ const semver = require("semver"); module.exports = async function({ version, previousVersion }) { if (!semver.valid(version)) { - throw Error(`Invalid version specified`); + throw new Error(`Invalid version specified`); } if (!semver.gt(version, previousVersion)) { - throw Error(`Version ${chalk.yellow(version)} has already been published`); + throw new Error( + `Version ${chalk.yellow(version)} has already been published` + ); } }; diff --git a/scripts/release/utils.js b/scripts/release/utils.js index 55a7d940d..833c4aa90 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -14,7 +14,7 @@ function fitTerminal(input) { const columns = Math.min(process.stdout.columns, 80); const WIDTH = columns - stringWidth(OK) + 1; if (input.length < WIDTH) { - input += Array(WIDTH - input.length).join(chalk.dim(".")); + input += new Array(WIDTH - input.length).join(chalk.dim(".")); } return input; } @@ -38,7 +38,7 @@ function runYarn(script) { script = [script]; } return execa("yarn", ["--silent"].concat(script)).catch(error => { - throw Error(`\`yarn ${script}\` failed\n${error.stdout}`); + throw new Error(`\`yarn ${script}\` failed\n${error.stdout}`); }); } @@ -56,7 +56,7 @@ function waitForEnter() { process.stdin.pause(); resolve(); } else if (key.ctrl && key.name === "c") { - reject(Error("Process terminated by the user")); + reject(new Error("Process terminated by the user")); } } }); diff --git a/src/language-css/printer-postcss.js b/src/language-css/printer-postcss.js index 722311ed8..8b3f7f7c0 100644 --- a/src/language-css/printer-postcss.js +++ b/src/language-css/printer-postcss.js @@ -907,7 +907,7 @@ const STRING_REGEX = /(['"])(?:(?!\1)[^\\]|\\[\s\S])*\1/g; const NUMBER_REGEX = /(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?/g; const STANDARD_UNIT_REGEX = /[a-zA-Z]+/g; const WORD_PART_REGEX = /[$@]?[a-zA-Z_\u0080-\uFFFF][\w\-\u0080-\uFFFF]*/g; -const ADJUST_NUMBERS_REGEX = RegExp( +const ADJUST_NUMBERS_REGEX = new RegExp( STRING_REGEX.source + `|` + `(${WORD_PART_REGEX.source})?` + diff --git a/src/language-js/embed.js b/src/language-js/embed.js index 0e5454648..f556ebc4b 100644 --- a/src/language-js/embed.js +++ b/src/language-js/embed.js @@ -615,7 +615,7 @@ function printHtmlTemplateLiteral( return "``"; } - const placeholderRegex = RegExp(composePlaceholder("(\\d+)"), "g"); + const placeholderRegex = new RegExp(composePlaceholder("(\\d+)"), "g"); const contentDoc = mapDoc( stripTrailingHardline(textToDoc(text, { parser })), diff --git a/website/playground/markdown.js b/website/playground/markdown.js index 4f469754f..b1bf85320 100644 --- a/website/playground/markdown.js +++ b/website/playground/markdown.js @@ -72,7 +72,7 @@ function codeBlock(content, syntax) { backtickSequences.map(backticks => backticks.length) ); const fenceLength = Math.max(3, longestBacktickSequenceLength + 1); - const fence = Array(fenceLength + 1).join("`"); + const fence = new Array(fenceLength + 1).join("`"); return [fence + (syntax || ""), content, fence].join("\n"); }