mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Replace assign/clone helpers with object spread syntax.
This commit is contained in:
parent
684416a902
commit
1b8b15693f
6 changed files with 51 additions and 55 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"parser": "espree",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,4 +5,5 @@ demo/markdownlint-browser.min.js
|
|||
lib-es3
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.nyc_output
|
||||
.vscode
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 ]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue