diff --git a/.eslintrc.json b/.eslintrc.json index 4981a747..2f067a53 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -7,7 +7,8 @@ "es6": true }, "plugins": [ - "jsdoc" + "jsdoc", + "node" ], "extends": [ "eslint:all", @@ -65,10 +66,53 @@ "space-before-function-paren": ["error", "never"], "vars-on-top": "off", "wrap-regex": "off", + "jsdoc/check-examples": "error", "jsdoc/check-indentation": "error", "jsdoc/check-syntax": "error", "jsdoc/match-description": "error", - "jsdoc/require-description": "error" + "jsdoc/require-description": "error", + + "node/handle-callback-err": "error", + "node/no-callback-literal": "error", + "node/no-exports-assign": "error", + "node/no-extraneous-import": "error", + "node/no-extraneous-require": "error", + "node/no-missing-import": "error", + "node/no-missing-require": "error", + "node/no-new-require": "error", + "node/no-path-concat": "error", + "node/no-process-exit": "error", + "node/no-unpublished-bin": "error", + "node/no-unpublished-import": "error", + "node/no-unpublished-require": "error", + "node/no-unsupported-features/es-builtins": "error", + "node/no-unsupported-features/es-syntax": "error", + "node/no-unsupported-features/node-builtins": ["error", { + "ignores": [ + "fs.promises" + ] + }], + "node/process-exit-as-throw": "error", + "node/shebang": "error", + "node/no-deprecated-api": "error", + "node/callback-return": "error", + "node/exports-style": "error", + "node/file-extension-in-import": "error", + "node/global-require": "off", + "node/no-mixed-requires": "error", + "node/no-process-env": "error", + "node/no-restricted-import": "error", + "node/no-restricted-require": "error", + "node/no-sync": "off", + "node/prefer-global/buffer": "error", + "node/prefer-global/console": "error", + "node/prefer-global/process": "error", + "node/prefer-global/text-decoder": "error", + "node/prefer-global/text-encoder": "error", + "node/prefer-global/url-search-params": "error", + "node/prefer-global/url": "error", + "node/prefer-promises/dns": "error", + "node/prefer-promises/fs": "off" } } diff --git a/demo/markdown-it-stub.js b/demo/markdown-it-stub.js index ddb4dfe1..88fc2f41 100644 --- a/demo/markdown-it-stub.js +++ b/demo/markdown-it-stub.js @@ -5,9 +5,3 @@ module.exports = window.markdownit; if (!module.exports) { console.error("markdown-it must be loaded before markdownlint."); } - -// Use browser's URL implementation if not available on url module -var url = require("url"); -if (!url.URL) { - url.URL = URL; -} diff --git a/doc/CustomRules.md b/doc/CustomRules.md index 6abfe31b..874bf9d5 100644 --- a/doc/CustomRules.md +++ b/doc/CustomRules.md @@ -15,8 +15,6 @@ That function is called once for each file/string input and is passed the parsed A simple rule implementation looks like: ```js -const { URL } = require("url"); - module.exports = { "names": [ "any-blockquote" ], "description": "Rule that reports an error for any blockquote", diff --git a/example/typescript/type-check.ts b/example/typescript/type-check.ts index 56874f33..f6ffd1c3 100644 --- a/example/typescript/type-check.ts +++ b/example/typescript/type-check.ts @@ -3,7 +3,6 @@ import markdownlint from "../.."; const assert = require("assert"); -const { URL } = require("url"); const markdownlintJsonPath = "../../.markdownlint.json"; function assertConfiguration(config: markdownlint.Configuration) { diff --git a/helpers/helpers.js b/helpers/helpers.js index 4f020375..d86a20d3 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -32,7 +32,7 @@ const emphasisMarkersRe = /[_*]/g; const linkRe = /\[(?:[^[\]]|\[[^\]]*\])*\](?:\(\S*\))?/g; // readFile options for reading with the UTF-8 encoding -module.exports.utf8Encoding = { "encoding": "utf8" }; +module.exports.utf8Encoding = "utf8"; // All punctuation characters (normal and full-width) module.exports.allPunctuation = ".,;:!?。,;:!?"; diff --git a/lib/markdownlint.js b/lib/markdownlint.js index fdca779a..fb792564 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.js @@ -4,7 +4,6 @@ const fs = require("fs"); const path = require("path"); -const { URL } = require("url"); const markdownIt = require("markdown-it"); const rules = require("./rules"); const helpers = require("../helpers"); @@ -681,6 +680,7 @@ function lintFile( } // Make a/synchronous call to read file if (synchronous) { + // @ts-ignore lintContentWrapper(null, fs.readFileSync(file, helpers.utf8Encoding)); } else { fs.readFile(file, helpers.utf8Encoding, lintContentWrapper); @@ -889,6 +889,7 @@ function readConfig(file, parsers, callback) { */ function readConfigSync(file, parsers) { // Read file + // @ts-ignore const content = fs.readFileSync(file, helpers.utf8Encoding); // Try to parse file const { config, message } = parseConfiguration(file, content, parsers); diff --git a/lib/rules.js b/lib/rules.js index 4f145be5..8c0e3421 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -2,7 +2,6 @@ "use strict"; -const { URL } = require("url"); const packageJson = require("../package.json"); const homepage = packageJson.homepage; const version = packageJson.version; diff --git a/package.json b/package.json index 44d537dc..9977a09f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "test-cover": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 node test/markdownlint-test.js", "test-declaration": "cd example/typescript && tsc && node type-check.js", "test-extra": "node test/markdownlint-test-extra.js", - "lint": "eslint --max-warnings 0 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", + "lint": "eslint --max-warnings 0 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, node/no-missing-require: 0, node/no-extraneous-require: 0\" example", "ci": "npm run test-cover && npm run lint && npm run test-declaration", "build-config-schema": "node schema/build-config-schema.js", "build-declaration": "tsc --allowJs --declaration --outDir declaration --resolveJsonModule lib/markdownlint.js && cpy declaration/lib/markdownlint.d.ts lib && rimraf declaration", @@ -42,6 +42,7 @@ "cpy-cli": "~3.1.1", "eslint": "~7.8.1", "eslint-plugin-jsdoc": "~30.3.1", + "eslint-plugin-node": "~11.1.0", "globby": "~11.0.1", "js-yaml": "~3.14.0", "make-dir-cli": "~2.0.0", diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 077e94cf..9e7b8683 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -5,7 +5,6 @@ const fs = require("fs"); const os = require("os"); const path = require("path"); -const { URL } = require("url"); const { promisify } = require("util"); const md = require("markdown-it")(); const pluginInline = require("markdown-it-for-inline"); @@ -3946,6 +3945,16 @@ tape("customRulesLintJavaScript", (test) => { test.ifError(err); const expected = { "test/lint-javascript.md": [ + { + "lineNumber": 8, + "ruleNames": [ "lint-javascript" ], + "ruleDescription": "Rule that lints JavaScript code", + "ruleInformation": null, + "errorDetail": + "Definition for rule 'node/handle-callback-err' was not found.", + "errorContext": "\"use strict\";", + "errorRange": null + }, { "lineNumber": 10, "ruleNames": [ "lint-javascript" ], diff --git a/test/rules/any-blockquote.js b/test/rules/any-blockquote.js index 647fe767..a9e8dd82 100644 --- a/test/rules/any-blockquote.js +++ b/test/rules/any-blockquote.js @@ -2,7 +2,6 @@ "use strict"; -const { URL } = require("url"); const { filterTokens } = require("markdownlint-rule-helpers"); module.exports = { diff --git a/test/rules/letters-E-X.js b/test/rules/letters-E-X.js index 124cd9be..5a39ab29 100644 --- a/test/rules/letters-E-X.js +++ b/test/rules/letters-E-X.js @@ -2,8 +2,6 @@ "use strict"; -const { URL } = require("url"); - module.exports = { "names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ], "description": "Rule that reports an error for lines with the letters 'EX'",