diff --git a/.eslintrc.json b/.eslintrc.json index 01d827ba..a2d2f647 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,277 +1,54 @@ { - "parser": "espree", - "parserOptions": { - "ecmaVersion": 6 - }, - "env": { - "node": true, - "es6": true - }, - "rules": { - "accessor-pairs": "error", - "array-bracket-newline": "error", - "array-bracket-spacing": ["error", "always"], - "array-callback-return": "error", - "array-element-newline": "off", - "arrow-body-style": "error", - "arrow-parens": "error", - "arrow-spacing": "error", - "block-scoped-var": "error", - "block-spacing": "error", - "brace-style": "error", - "callback-return": "off", - "camelcase": "error", - "capitalized-comments": "off", - "class-methods-use-this": "error", - "comma-dangle": "error", - "comma-spacing": "error", - "comma-style": "error", - "complexity": "error", - "computed-property-spacing": "error", - "consistent-return": "off", - "consistent-this": "error", - "constructor-super": "error", - "curly": "error", - "default-case": "error", - "dot-location": ["error", "property"], - "dot-notation": "error", - "eol-last": "error", - "eqeqeq": "error", - "for-direction": "error", - "func-call-spacing": "error", - "func-name-matching": "off", - "func-names": "error", - "func-style": ["error", "declaration"], - "function-paren-newline": "off", - "generator-star-spacing": "error", - "getter-return": "error", - "global-require": "off", - "guard-for-in": "error", - "handle-callback-err": "error", - "id-blacklist": "error", - "id-length": "off", - "id-match": "error", - "implicit-arrow-linebreak": "error", - "indent": ["error", 2, { "SwitchCase": 1 }], - "indent-legacy": "off", - "init-declarations": "error", - "jsx-quotes": "error", - "key-spacing": "error", - "keyword-spacing": "error", - "line-comment-position": "error", - "linebreak-style": "off", - "lines-around-comment": "off", - "lines-around-directive": "error", - "lines-between-class-members": "error", - "max-classes-per-file": "error", - "max-depth": "error", - "max-len": "error", - "max-lines": "off", - "max-lines-per-function": "off", - "max-nested-callbacks": "error", - "max-params": ["error", 9], - "max-statements": ["error", 33], - "max-statements-per-line": "error", - "multiline-comment-style": ["error", "separate-lines"], - "multiline-ternary": "off", - "new-cap": "error", - "new-parens": "error", - "newline-after-var": "off", - "newline-before-return": "off", - "newline-per-chained-call": "off", - "no-alert": "error", - "no-array-constructor": "error", - "no-async-promise-executor": "error", - "no-await-in-loop": "error", - "no-bitwise": "off", - "no-buffer-constructor": "error", - "no-caller": "error", - "no-case-declarations": "error", - "no-catch-shadow": "error", - "no-class-assign": "error", - "no-compare-neg-zero": "error", - "no-cond-assign": "error", - "no-confusing-arrow": "error", - "no-console": "error", - "no-const-assign": "error", - "no-constant-condition": "error", - "no-continue": "error", - "no-control-regex": "error", - "no-debugger": "error", - "no-delete-var": "error", - "no-div-regex": "error", - "no-dupe-args": "error", - "no-dupe-class-members": "error", - "no-dupe-keys": "error", - "no-duplicate-case": "error", - "no-duplicate-imports": "error", - "no-else-return": "error", - "no-empty": "error", - "no-empty-character-class": "error", - "no-empty-function": "off", - "no-empty-pattern": "error", - "no-eq-null": "error", - "no-eval": "error", - "no-ex-assign": "error", - "no-extend-native": "error", - "no-extra-bind": "error", - "no-extra-boolean-cast": "error", - "no-extra-label": "error", - "no-extra-parens": "off", - "no-extra-semi": "error", - "no-fallthrough": "error", - "no-floating-decimal": "error", - "no-func-assign": "error", - "no-global-assign": "error", - "no-implicit-coercion": "off", - "no-implicit-globals": "error", - "no-implied-eval": "error", - "no-inline-comments": "error", - "no-inner-declarations": "error", - "no-invalid-regexp": "error", - "no-invalid-this": "off", - "no-irregular-whitespace": "error", - "no-iterator": "error", - "no-label-var": "error", - "no-labels": "error", - "no-lone-blocks": "error", - "no-lonely-if": "error", - "no-loop-func": "error", - "no-magic-numbers": "off", - "no-misleading-character-class": "error", - "no-mixed-operators": "error", - "no-mixed-requires": "error", - "no-mixed-spaces-and-tabs": "error", - "no-multi-assign": "off", - "no-multi-spaces": "error", - "no-multi-str": "error", - "no-multiple-empty-lines": "error", - "no-native-reassign": "error", - "no-negated-condition": "error", - "no-negated-in-lhs": "error", - "no-nested-ternary": "off", - "no-new": "error", - "no-new-func": "error", - "no-new-object": "error", - "no-new-require": "error", - "no-new-symbol": "error", - "no-new-wrappers": "error", - "no-obj-calls": "error", - "no-octal": "error", - "no-octal-escape": "error", - "no-param-reassign": "off", - "no-path-concat": "error", - "no-plusplus": "off", - "no-process-env": "error", - "no-process-exit": "error", - "no-proto": "error", - "no-prototype-builtins": "error", - "no-redeclare": "error", - "no-regex-spaces": "error", - "no-restricted-globals": "error", - "no-restricted-imports": "error", - "no-restricted-modules": "error", - "no-restricted-properties": "error", - "no-restricted-syntax": "error", - "no-return-assign": "error", - "no-return-await": "error", - "no-script-url": "error", - "no-self-assign": "error", - "no-self-compare": "error", - "no-sequences": "error", - "no-shadow": "error", - "no-shadow-restricted-names": "error", - "no-spaced-func": "error", - "no-sparse-arrays": "error", - "no-sync": "off", - "no-tabs": "error", - "no-template-curly-in-string": "error", - "no-ternary": "off", - "no-this-before-super": "error", - "no-throw-literal": "error", - "no-trailing-spaces": "error", - "no-undef": "error", - "no-undef-init": "error", - "no-undefined": "off", - "no-underscore-dangle": "error", - "no-unexpected-multiline": "error", - "no-unmodified-loop-condition": "error", - "no-unneeded-ternary": "error", - "no-unreachable": "error", - "no-unsafe-finally": "error", - "no-unsafe-negation": "error", - "no-unused-expressions": "error", - "no-unused-labels": "error", - "no-unused-vars": "error", - "no-use-before-define": "error", - "no-useless-call": "error", - "no-useless-catch": "error", - "no-useless-computed-key": "error", - "no-useless-concat": "error", - "no-useless-constructor": "error", - "no-useless-escape": "error", - "no-useless-rename": "error", - "no-useless-return": "error", - "no-var": "error", - "no-void": "error", - "no-warning-comments": "error", - "no-whitespace-before-property": "error", - "no-with": "error", - "nonblock-statement-body-position": "error", - "object-curly-newline": "off", - "object-curly-spacing": ["error", "always"], - "object-property-newline": "error", - "object-shorthand": "off", - "one-var": "off", - "one-var-declaration-per-line": "error", - "operator-assignment": "error", - "operator-linebreak": ["error", "after"], - "padded-blocks": "off", - "padding-line-between-statements": "off", - "prefer-arrow-callback": "off", - "prefer-const": "error", - "prefer-destructuring": "off", - "prefer-numeric-literals": "error", - "prefer-object-spread": "error", - "prefer-promise-reject-errors": "error", - "prefer-reflect": "off", - "prefer-rest-params": "error", - "prefer-spread": "error", - "prefer-template": "off", - "quote-props": "error", - "quotes": "error", - "radix": "error", - "require-atomic-updates": "error", - "require-await": "error", - "require-jsdoc": "off", - "require-unicode-regexp": "off", - "require-yield": "error", - "rest-spread-spacing": "error", - "semi": "error", - "semi-spacing": "error", - "semi-style": "error", - "sort-imports": "error", - "sort-keys": "off", - "sort-vars": "error", - "space-before-blocks": "error", - "space-before-function-paren": ["error", "never"], - "space-in-parens": "error", - "space-infix-ops": "error", - "space-unary-ops": "error", - "spaced-comment": "error", - "strict": "error", - "switch-colon-spacing": "error", - "symbol-description": "error", - "template-curly-spacing": "error", - "template-tag-spacing": "error", - "unicode-bom": "error", - "use-isnan": "error", - "valid-jsdoc": "error", - "valid-typeof": "error", - "vars-on-top": "off", - "wrap-iife": "error", - "wrap-regex": "off", - "yield-star-spacing": "error", - "yoda": "error" - } + "parser": "espree", + "parserOptions": { + "ecmaVersion": 6 + }, + "env": { + "node": true, + "es6": true + }, + "extends": "eslint:all", + "rules": { + "array-bracket-spacing": ["error", "always"], + "array-element-newline": "off", + "capitalized-comments": "off", + "dot-location": ["error", "property"], + "func-style": ["error", "declaration"], + "function-paren-newline": "off", + "global-require": "off", + "id-length": "off", + "indent": ["error", 2, { "SwitchCase": 1 }], + "linebreak-style": "off", + "max-lines": "off", + "max-lines-per-function": "off", + "max-params": ["error", 9], + "max-statements": ["error", 33], + "multiline-comment-style": ["error", "separate-lines"], + "multiline-ternary": "off", + "newline-per-chained-call": "off", + "no-empty-function": "off", + "no-extra-parens": "off", + "no-implicit-coercion": "off", + "no-magic-numbers": "off", + "no-nested-ternary": "off", + "no-param-reassign": "off", + "no-plusplus": "off", + "no-sync": "off", + "no-ternary": "off", + "no-undefined": "off", + "object-curly-spacing": ["error", "always"], + "object-shorthand": "off", + "one-var": "off", + "operator-linebreak": ["error", "after"], + "padded-blocks": "off", + "prefer-arrow-callback": "off", + "prefer-destructuring": "off", + "prefer-named-capture-group": "off", + "prefer-template": "off", + "require-unicode-regexp": "off", + "sort-keys": "off", + "space-before-function-paren": ["error", "never"], + "vars-on-top": "off", + "wrap-regex": "off" + } } diff --git a/demo/default.js b/demo/default.js index 16b9bd15..2f325b26 100644 --- a/demo/default.js +++ b/demo/default.js @@ -89,7 +89,7 @@ } else { // Update from File object var reader = new FileReader(); - reader.onload = function readerOnload(e) { + reader.onload = function onload(e) { markdown.value = e.target.result; onMarkdownInput(); }; diff --git a/lib/markdownlint.js b/lib/markdownlint.js index 511f8ef9..4bbf26bf 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -74,7 +74,7 @@ function validateRuleList(ruleList) { // Class for results with toString for pretty display function newResults(ruleList) { function Results() {} - Results.prototype.toString = function resultsToString(useAlias) { + Results.prototype.toString = function toString(useAlias) { const that = this; let ruleNameToRule = null; const results = []; @@ -415,7 +415,7 @@ function lintContent( return callback(ex); } shared.makeTokenCache(null); - callback(null, result); + return callback(null, result); } // Lints a single file @@ -433,7 +433,7 @@ function lintFile( if (err) { return callback(err); } - lintContent(ruleList, file, content, md, config, frontMatter, + return lintContent(ruleList, file, content, md, config, frontMatter, noInlineConfig, resultVersion, callback); } // Make a/synchronous call to read file @@ -476,6 +476,7 @@ function lintInput(options, synchronous, callback) { }); const results = newResults(ruleList); // Helper to lint the next string or file + /* eslint-disable consistent-return */ function lintNextItem() { let iterating = true; let item = null; @@ -485,9 +486,7 @@ function lintInput(options, synchronous, callback) { return callback(err); } results[item] = result; - if (!iterating) { - lintNextItem(); - } + return iterating || lintNextItem(); } while (iterating) { if ((item = stringsKeys.shift())) { @@ -518,7 +517,7 @@ function lintInput(options, synchronous, callback) { } } } - lintNextItem(); + return lintNextItem(); } /** @@ -603,15 +602,14 @@ function readConfig(file, parsers, callback) { if (configExtends) { delete config.extends; const extendsFile = path.resolve(path.dirname(file), configExtends); - readConfig(extendsFile, parsers, (errr, extendsConfig) => { + return readConfig(extendsFile, parsers, (errr, extendsConfig) => { if (errr) { return callback(errr); } - callback(null, shared.assign(extendsConfig, config)); + return callback(null, shared.assign(extendsConfig, config)); }); - } else { - callback(null, config); } + return callback(null, config); }); } diff --git a/lib/shared.js b/lib/shared.js index bf7a2179..f95377a2 100644 --- a/lib/shared.js +++ b/lib/shared.js @@ -76,6 +76,7 @@ module.exports.includesSorted = function includesSorted(array, element) { let left = 0; let right = array.length - 1; while (left <= right) { + /* eslint-disable no-bitwise */ const mid = (left + right) >> 1; if (array[mid] < element) { left = mid + 1; @@ -144,10 +145,10 @@ module.exports.headingStyleFor = function headingStyleFor(token) { }; // Calls the provided function for each matching token -function filterTokens(params, type, callback) { +function filterTokens(params, type, handler) { params.tokens.forEach(function forToken(token) { if (token.type === type) { - callback(token); + handler(token); } }); } @@ -234,24 +235,24 @@ module.exports.makeTokenCache = makeTokenCache; module.exports.forEachLine = function forEachLine(callback) { tokenCache.lineMetadata.forEach(function forMetadata(metadata) { // Parameters: line, lineIndex, inCode, onFence, inTable - callback.apply(this, metadata); + callback(...metadata); }); }; // Calls the provided function for each specified inline child token module.exports.forEachInlineChild = -function forEachInlineChild(params, type, callback) { +function forEachInlineChild(params, type, handler) { filterTokens(params, "inline", function forToken(token) { token.children.forEach(function forChild(child) { if (child.type === type) { - callback(child, token); + handler(child, token); } }); }); }; // Calls the provided function for each heading's content -module.exports.forEachHeading = function forEachHeading(params, callback) { +module.exports.forEachHeading = function forEachHeading(params, handler) { let heading = null; params.tokens.forEach(function forToken(token) { if (token.type === "heading_open") { @@ -259,14 +260,14 @@ module.exports.forEachHeading = function forEachHeading(params, callback) { } else if (token.type === "heading_close") { heading = null; } else if ((token.type === "inline") && heading) { - callback(heading, token.content); + handler(heading, token.content); } }); }; // Calls the provided function for each inline code span's content module.exports.forEachInlineCodeSpan = - function forEachInlineCodeSpan(input, callback) { + function forEachInlineCodeSpan(input, handler) { let currentLine = 0; let currentColumn = 0; let index = 0; @@ -290,7 +291,7 @@ module.exports.forEachInlineCodeSpan = (startColumn >= 0) && (tickCount === currentTicks)) { // Found end backticks; invoke callback for code span - callback( + handler( input.substring(startIndex, index - currentTicks), startLine, startColumn, tickCount); startIndex = -1; diff --git a/package.json b/package.json index 0d91c0ee..b18dd03e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test-cover": "istanbul cover 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 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-shadow: 0, object-property-newline: 0\" example", + "lint": "eslint lib 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", "build-config-schema": "node schema/build-config-schema.js", "build-demo": "cpy node_modules/markdown-it/dist/markdown-it.min.js demo && cd demo && rimraf markdownlint-browser.* && cpy file-header.js . --rename=markdownlint-browser.js && tsc --allowJs --resolveJsonModule --outDir ../lib-es3 ../lib/markdownlint.js && browserify ../lib-es3/lib/markdownlint.js --standalone markdownlint >> markdownlint-browser.js && uglifyjs markdownlint-browser.js --compress --mangle --comments --output markdownlint-browser.min.js", "build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2", @@ -29,13 +29,13 @@ "markdown-it": "8.4.2" }, "devDependencies": { - "@types/node": "~10.12.21", + "@types/node": "~11.12.0", "browserify": "~16.2.3", "cpy-cli": "~2.0.0", - "eslint": "~5.12.1", + "eslint": "~5.15.3", "glob": "~7.1.3", "istanbul": "~0.4.5", - "js-yaml": "~3.12.1", + "js-yaml": "~3.13.0", "markdown-it-for-inline": "~0.1.1", "markdown-it-katex": "~2.0.3", "markdown-it-sub": "~1.0.0", @@ -44,8 +44,8 @@ "rimraf": "~2.6.3", "toml": "~3.0.0", "tv4": "~1.3.0", - "typescript": "~3.3.1", - "uglify-js": "~3.4.9" + "typescript": "~3.3.4000", + "uglify-js": "~3.5.2" }, "keywords": [ "markdown", diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 6c930482..742e8cce 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -25,7 +25,7 @@ function promisify(func, ...args) { if (error) { return reject(error); } - resolve(result); + return resolve(result); }); }); } @@ -1112,12 +1112,15 @@ module.exports.readme = function readme(test) { if (!seenRelated) { seenRelated = true; } else if (seenRelated && !seenRules) { - seenRules = inRules = true; + seenRules = true; + inRules = true; } else if (seenRelated && seenRules && !seenTags) { - seenTags = inTags = true; + seenTags = true; + inTags = true; } } else if (token.type === "bullet_list_close") { - inRules = inTags = false; + inRules = false; + inTags = false; } else if (token.type === "inline") { if (inRules) { const rule = rulesLeft.shift(); @@ -1181,7 +1184,8 @@ module.exports.doc = function doc(test) { if (inHeading) { testTagsAliasesParams(rule); rule = rulesLeft.shift(); - ruleHasTags = ruleHasAliases = false; + ruleHasTags = false; + ruleHasAliases = false; test.ok(rule, "Missing rule implementation for " + token.content + "."); test.equal(token.content,