From 1b8b15693f2b02bf2c018863278a9fd39ec0ef66 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sun, 5 May 2019 22:27:01 -0700 Subject: [PATCH] Replace assign/clone helpers with object spread syntax. --- .eslintrc.json | 2 +- .gitignore | 1 + helpers/helpers.js | 14 -------- lib/markdownlint.js | 17 +++++++--- package.json | 4 +-- test/markdownlint-test.js | 68 ++++++++++++++++++++------------------- 6 files changed, 51 insertions(+), 55 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a2d2f647..069a6cc9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,7 @@ { "parser": "espree", "parserOptions": { - "ecmaVersion": 6 + "ecmaVersion": 2018 }, "env": { "node": true, diff --git a/.gitignore b/.gitignore index 84752ebf..90473111 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ demo/markdownlint-browser.min.js lib-es3 node_modules npm-debug.log +.nyc_output .vscode diff --git a/helpers/helpers.js b/helpers/helpers.js index c72389aa..f6a7e17a 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -24,20 +24,6 @@ module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/; // readFile options for reading with the UTF-8 encoding module.exports.utf8Encoding = { "encoding": "utf8" }; -// Applies key/value pairs from src to dst, returning dst -function assign(dst, src) { - Object.keys(src).forEach(function forKey(key) { - dst[key] = src[key]; - }); - return dst; -} -module.exports.assign = assign; - -// Clones the key/value pairs of obj, returning the clone -module.exports.clone = function clone(obj) { - return assign({}, obj); -}; - // Returns true iff the input is a number module.exports.isNumber = function isNumber(obj) { return typeof obj === "number"; diff --git a/lib/markdownlint.js b/lib/markdownlint.js index ca2ea4c4..339ab129 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -271,7 +271,7 @@ function getEnabledRulesPerLineNumber( if (!noInlineConfig) { let match = helpers.inlineCommentRe.exec(line); if (match) { - enabledRules = helpers.clone(enabledRules); + enabledRules = { ...enabledRules }; while (match) { forMatch(match); match = helpers.inlineCommentRe.exec(line); @@ -613,7 +613,10 @@ function readConfig(file, parsers, callback) { if (errr) { return callback(errr); } - return callback(null, helpers.assign(extendsConfig, config)); + return callback(null, { + ...extendsConfig, + ...config + }); }); } return callback(null, config); @@ -639,9 +642,13 @@ function readConfigSync(file, parsers) { const configExtends = config.extends; if (configExtends) { delete config.extends; - return helpers.assign( - readConfigSync(path.resolve(path.dirname(file), configExtends), parsers), - config); + return { + ...readConfigSync( + path.resolve(path.dirname(file), configExtends), + parsers + ), + ...config + }; } return config; } diff --git a/package.json b/package.json index 4e6d8f38..3d1f2cc8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "bugs": "https://github.com/DavidAnson/markdownlint/issues", "scripts": { "test": "nodeunit test/markdownlint-test.js", - "test-cover": "istanbul cover node_modules/nodeunit/bin/nodeunit test/markdownlint-test.js", + "test-cover": "nyc node_modules/nodeunit/bin/nodeunit test/markdownlint-test.js", "test-extra": "nodeunit test/markdownlint-test-extra.js", "debug": "node debug node_modules/nodeunit/bin/nodeunit", "lint": "eslint lib helpers test schema && eslint --env browser --global markdownit --global markdownlint --rule \"no-unused-vars: 0, no-extend-native: 0, max-statements: 0, no-console: 0, no-var: 0\" demo && eslint --rule \"no-console: 0, no-invalid-this: 0, no-shadow: 0, object-property-newline: 0\" example", @@ -34,7 +34,6 @@ "cpy-cli": "~2.0.0", "eslint": "~5.15.3", "glob": "~7.1.3", - "istanbul": "~0.4.5", "js-yaml": "~3.13.0", "markdown-it-for-inline": "~0.1.1", "markdown-it-katex": "~2.0.3", @@ -42,6 +41,7 @@ "markdown-it-sup": "~1.0.0", "markdownlint-rule-helpers": "~0.1.0", "nodeunit": "~0.11.3", + "nyc": "~14.1.0", "rimraf": "~2.6.3", "toml": "~3.0.0", "tv4": "~1.3.0", diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 86d7a82f..16066f45 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -47,8 +47,10 @@ function createTestForFile(file) { }) .then( function lintWithConfig(config) { - const mergedConfig = - helpers.assign(helpers.clone(defaultConfig), config); + const mergedConfig = { + ...defaultConfig, + ...config + }; return promisify(markdownlint, { "files": [ file ], "config": mergedConfig, @@ -1651,11 +1653,11 @@ module.exports.configMultiple = function configMultiple(test) { markdownlint.readConfig("./test/config/config-grandparent.json", function callback(err, actual) { test.ifError(err); - const expected = helpers.assign( - helpers.assign( - helpers.assign({}, require("./config/config-child.json")), - require("./config/config-parent.json")), - require("./config/config-grandparent.json")); + const expected = { + ...require("./config/config-child.json"), + ...require("./config/config-parent.json"), + ...require("./config/config-grandparent.json") + }; delete expected.extends; test.deepEqual(actual, expected, "Config object not correct."); test.done(); @@ -1729,11 +1731,11 @@ module.exports.configMultipleYaml = function configMultipleYaml(test) { [ require("js-yaml").safeLoad ], function callback(err, actual) { test.ifError(err); - const expected = helpers.assign( - helpers.assign( - helpers.assign({}, require("./config/config-child.json")), - require("./config/config-parent.json")), - require("./config/config-grandparent.json")); + const expected = { + ...require("./config/config-child.json"), + ...require("./config/config-parent.json"), + ...require("./config/config-grandparent.json") + }; delete expected.extends; test.deepEqual(actual, expected, "Config object not correct."); test.done(); @@ -1747,11 +1749,11 @@ module.exports.configMultipleHybrid = function configMultipleHybrid(test) { [ JSON.parse, require("toml").parse, require("js-yaml").safeLoad ], function callback(err, actual) { test.ifError(err); - const expected = helpers.assign( - helpers.assign( - helpers.assign({}, require("./config/config-child.json")), - require("./config/config-parent.json")), - require("./config/config-grandparent.json")); + const expected = { + ...require("./config/config-child.json"), + ...require("./config/config-parent.json"), + ...require("./config/config-grandparent.json") + }; delete expected.extends; test.deepEqual(actual, expected, "Config object not correct."); test.done(); @@ -1796,11 +1798,11 @@ module.exports.configMultipleSync = function configMultipleSync(test) { test.expect(1); const actual = markdownlint.readConfigSync("./test/config/config-grandparent.json"); - const expected = helpers.assign( - helpers.assign( - helpers.assign({}, require("./config/config-child.json")), - require("./config/config-parent.json")), - require("./config/config-grandparent.json")); + const expected = { + ...require("./config/config-child.json"), + ...require("./config/config-parent.json"), + ...require("./config/config-grandparent.json") + }; delete expected.extends; test.deepEqual(actual, expected, "Config object not correct."); test.done(); @@ -1877,11 +1879,11 @@ module.exports.configMultipleYamlSync = function configMultipleYamlSync(test) { test.expect(1); const actual = markdownlint.readConfigSync( "./test/config/config-grandparent.yaml", [ require("js-yaml").safeLoad ]); - const expected = helpers.assign( - helpers.assign( - helpers.assign({}, require("./config/config-child.json")), - require("./config/config-parent.json")), - require("./config/config-grandparent.json")); + const expected = { + ...require("./config/config-child.json"), + ...require("./config/config-parent.json"), + ...require("./config/config-grandparent.json") + }; delete expected.extends; test.deepEqual(actual, expected, "Config object not correct."); test.done(); @@ -1893,11 +1895,11 @@ function configMultipleHybridSync(test) { const actual = markdownlint.readConfigSync( "./test/config/config-grandparent-hybrid.yaml", [ JSON.parse, require("toml").parse, require("js-yaml").safeLoad ]); - const expected = helpers.assign( - helpers.assign( - helpers.assign({}, require("./config/config-child.json")), - require("./config/config-parent.json")), - require("./config/config-grandparent.json")); + const expected = { + ...require("./config/config-child.json"), + ...require("./config/config-parent.json"), + ...require("./config/config-grandparent.json") + }; delete expected.extends; test.deepEqual(actual, expected, "Config object not correct."); test.done(); @@ -2306,7 +2308,7 @@ module.exports.customRulesBadProperty = function customRulesBadProperty(test) { ].forEach(function forProperty(property) { const propertyName = property[0]; property[1].forEach(function forPropertyValue(propertyValue) { - const badRule = helpers.clone(customRules.anyBlockquote); + const badRule = { ...customRules.anyBlockquote }; badRule[propertyName] = propertyValue; const options = { "customRules": [ badRule ]